From cfb2695b2761efc3f15ae0ff114455e1a4f8caf8 Mon Sep 17 00:00:00 2001 From: Mathew Jose Mammoottil Date: Mon, 26 Aug 2024 12:24:11 +0530 Subject: [PATCH] resolved comment --- .../src/main/java/com/crapi/config/JwtProvider.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/services/identity/src/main/java/com/crapi/config/JwtProvider.java b/services/identity/src/main/java/com/crapi/config/JwtProvider.java index 5567d7df..17193255 100644 --- a/services/identity/src/main/java/com/crapi/config/JwtProvider.java +++ b/services/identity/src/main/java/com/crapi/config/JwtProvider.java @@ -24,7 +24,6 @@ import com.nimbusds.jose.jwk.JWK; import com.nimbusds.jose.jwk.JWKSet; import com.nimbusds.jose.jwk.RSAKey; -import com.nimbusds.jwt.JWT; import com.nimbusds.jwt.JWTParser; import com.nimbusds.jwt.PlainJWT; import com.nimbusds.jwt.SignedJWT; @@ -169,10 +168,8 @@ private String getJwtSecret(JWSHeader header) throws JOSEException { * @return validate token expire and true boolean */ public boolean validateJwtToken(String authToken) { - JWT jwt = null; try { - jwt = JWTParser.parse(authToken); - SignedJWT signedJWT = (SignedJWT) jwt; + SignedJWT signedJWT = SignedJWT.parse(authToken); JWSHeader header = signedJWT.getHeader(); Algorithm alg = header.getAlgorithm(); boolean valid = false; @@ -198,8 +195,12 @@ public boolean validateJwtToken(String authToken) { } } catch (ParseException e) { - if (jwt instanceof PlainJWT) return true; - logger.error("Could not parse JWT Token -> Message: %d", e); + try { + PlainJWT jwt = PlainJWT.parse(authToken); + return true; + } catch (ParseException parseException) { + log.error("Could not parse JWT Token -> Message: %d", parseException); + } } catch (JOSEException e) { log.error("RSA JWK Extraction failed -> Message: %d", e); }