Skip to content

Commit ca95380

Browse files
committed
Refactor the jwtvendor expiry and set up upper limit
Signed-off-by: Ryan Liang <jiallian@amazon.com>
1 parent 884f7a1 commit ca95380

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class JwtVendor {
4242
private final JoseJwtProducer jwtProducer;
4343
private final LongSupplier timeProvider;
4444
private final EncryptionDecryptionUtil encryptionDecryptionUtil;
45+
private final Integer defaultExpirySeconds = 300;
46+
private final Integer maxExpirySeconds = 600;
4547

4648
public JwtVendor(final Settings settings, final Optional<LongSupplier> timeProvider) {
4749
JoseJwtProducer jwtProducer = new JoseJwtProducer();
@@ -126,7 +128,11 @@ public String createJwt(
126128

127129
jwtClaims.setNotBefore(nowAsMillis);
128130

129-
expirySeconds = (expirySeconds == null) ? 300 : expirySeconds;
131+
if (expirySeconds > maxExpirySeconds) {
132+
throw new Exception("The provided expiration time exceeds the maximum allowed duration of " + maxExpirySeconds + " seconds");
133+
}
134+
135+
expirySeconds = (expirySeconds == null) ? defaultExpirySeconds : Math.min(expirySeconds, maxExpirySeconds);
130136
if (expirySeconds <= 0) {
131137
throw new Exception("The expiration time should be a positive integer");
132138
}

0 commit comments

Comments
 (0)