From 387027bbca257064f9f0417b05182de93ebb0588 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Tue, 22 Aug 2023 00:18:31 -0700 Subject: [PATCH] Refactor the logic in JwtVendor Signed-off-by: Ryan Liang --- .../opensearch/security/authtoken/jwt/JwtVendor.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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);