Skip to content

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-turner committed Oct 18, 2024
2 parents be5e475 + 10e04d2 commit a3fd1ed
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private byte[] createPassword(AuthenticationTokenIdentifier identifier,
DelegationTokenConfig cfg) {
long now = System.currentTimeMillis();
identifier.setIssueDate(now);
identifier.setExpirationDate(calculateExpirationDate());
identifier.setExpirationDate(calculateExpirationDate(now));
// Limit the lifetime if the user requests it
if (cfg != null) {
long requestedLifetime = cfg.getTokenLifetime(TimeUnit.MILLISECONDS);
Expand All @@ -104,8 +104,7 @@ private byte[] createPassword(AuthenticationTokenIdentifier identifier,
return createPassword(identifier);
}

private long calculateExpirationDate() {
long now = System.currentTimeMillis();
private long calculateExpirationDate(long now) {
long expiration = now + tokenMaxLifetime;
// Catch overflow
if (expiration < now) {
Expand All @@ -123,11 +122,12 @@ protected byte[] createPassword(AuthenticationTokenIdentifier identifier) {
identifier.setKeyId(secretKey.getKeyId());
identifier.setInstanceId(instanceID);

long now = System.currentTimeMillis();
if (!identifier.isSetIssueDate()) {
identifier.setIssueDate(System.currentTimeMillis());
identifier.setIssueDate(now);
}
if (!identifier.isSetExpirationDate()) {
identifier.setExpirationDate(calculateExpirationDate());
identifier.setExpirationDate(calculateExpirationDate(now));
}
return createPassword(identifier.getBytes(), secretKey.getKey());
}
Expand Down

0 comments on commit a3fd1ed

Please sign in to comment.