diff --git a/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java b/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java index 714293598a..457540c361 100644 --- a/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java +++ b/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java @@ -130,15 +130,12 @@ public String createJwt( jwtClaims.setNotBefore(timeMillis); - if (expirySeconds == null) { - long expiryTime = timeProvider.getAsLong() + 300; - jwtClaims.setExpiryTime(expiryTime); - } else if (expirySeconds > 0) { - long expiryTime = timeProvider.getAsLong() + expirySeconds; - jwtClaims.setExpiryTime(expiryTime); - } else { + expirySeconds = (expirySeconds == null) ? 300 : expirySeconds; + if (expirySeconds <= 0) { throw new Exception("The expiration time should be a positive integer"); } + long expiryTime = timeProvider.getAsLong() + expirySeconds; + jwtClaims.setExpiryTime(expiryTime); if (roles != null) { String listOfRoles = String.join(",", roles);