Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a log to indicate errors related to JWKS request in enforcer #3483

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.wso2.choreo.connect.enforcer.security.jwt.validator;

import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.RemoteKeySourceException;
import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.RSAKey;
import com.nimbusds.jwt.JWTClaimsSet;
Expand Down Expand Up @@ -114,10 +115,10 @@ private JWTValidationInfo validateToken(SignedJWTInfo signedJWTInfo, ExtendedTok

protected boolean validateSignature(SignedJWT signedJWT, ExtendedTokenIssuerDto tokenIssuer)
throws EnforcerException {
String certificateAlias = tokenIssuer.getCertificateAlias();
String keyID = signedJWT.getHeader().getKeyID();
String jwksUrl = tokenIssuer.getJwksConfigurationDTO().getUrl();
try {
String certificateAlias = tokenIssuer.getCertificateAlias();
String keyID = signedJWT.getHeader().getKeyID();
String jwksUrl = tokenIssuer.getJwksConfigurationDTO().getUrl();
if (StringUtils.isNotEmpty(keyID)) {
if (tokenIssuer.getJwksConfigurationDTO().isEnabled() && StringUtils
.isNotEmpty(jwksUrl)) {
Expand Down Expand Up @@ -156,6 +157,9 @@ protected boolean validateSignature(SignedJWT signedJWT, ExtendedTokenIssuerDto
}
}
return JWTUtils.verifyTokenSignature(signedJWT, certificateAlias);
} catch (RemoteKeySourceException e) {
logger.error("Error while retrieving the JWKSet from the remote endpoint : " + jwksUrl, e);
throw new EnforcerException("JWT Signature verification failed", e);
} catch (JOSEException | IOException e) {
throw new EnforcerException("JWT Signature verification failed", e);
}
Expand Down
Loading