diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/jwt/JWTAuthenticator.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/jwt/JWTAuthenticator.java index 33ec5dbabd..669fffaf49 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/jwt/JWTAuthenticator.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/jwt/JWTAuthenticator.java @@ -46,6 +46,7 @@ import org.wso2.apk.enforcer.security.jwt.validator.JWTConstants; import org.wso2.apk.enforcer.security.jwt.validator.JWTValidator; import org.wso2.apk.enforcer.security.jwt.validator.RevokedJWTDataHolder; +import org.wso2.apk.enforcer.subscription.SubscriptionDataHolder; import org.wso2.apk.enforcer.tracing.TracingConstants; import org.wso2.apk.enforcer.tracing.TracingSpan; import org.wso2.apk.enforcer.tracing.TracingTracer; @@ -157,21 +158,15 @@ public AuthenticationContext authenticate(RequestContext requestContext) throws } // Get consumer key from the JWT token claim set - try { - String consumerKey = claims.getStringClaim(APIConstants.JwtTokenConstants.CLIENT_ID); - - // Subscription validation using consumer key - if (consumerKey != null) { - validateSubscriptionUsingConsumerKey(apiKeyValidationInfoDTO, name, version, context, - consumerKey, envType, APIConstants.API_SECURITY_OAUTH2, organization, - splitToken); - } else { - log.error("Error while extracting consumer key from JWT token claim set"); - } - } catch (ParseException e) { - log.error("Error while retrieving clientId from JWT token. {}", e.getMessage()); - throw new APISecurityException(APIConstants.StatusCodes.UNAUTHORIZED.getCode(), - APISecurityConstants.API_AUTH_FORBIDDEN, APISecurityConstants.API_AUTH_FORBIDDEN_MESSAGE); + String consumerKey = claims.get(APIConstants.JwtTokenConstants.CLIENT_ID).toString(); + + // Subscription validation using consumer key + if (consumerKey != null) { + validateSubscriptionUsingConsumerKey(apiKeyValidationInfoDTO, name, version, context, + consumerKey, envType, APIConstants.API_SECURITY_OAUTH2, organization, + splitToken); + } else { + log.error("Error while extracting consumer key from JWT token claim set"); } } else { // In this case, the application related properties are populated so that analytics @@ -451,8 +446,8 @@ private JWTValidationInfo getJwtValidationInfo(String jwtToken, String organizat try { // Get issuer String issuer = jwtClaimsSet.getIssuer(); - JWTValidator jwtValidator = SubscriptionDataStoreImpl.getInstance().getJWTValidatorByIssuer(issuer, - organization, environment); + JWTValidator jwtValidator = SubscriptionDataHolder.getInstance().getSubscriptionDataStore() + .getJWTValidatorByIssuer(issuer, organization, environment); // If no validator found for the issuer, we are not caching the token. if (jwtValidator == null) { throw new APISecurityException(APIConstants.StatusCodes.UNAUTHENTICATED.getCode(),