diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/util/IdentityCommonUtil.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/util/IdentityCommonUtil.java index dbdf545fa..614032dc0 100644 --- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/util/IdentityCommonUtil.java +++ b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.identity/src/main/java/com/wso2/openbanking/accelerator/identity/util/IdentityCommonUtil.java @@ -213,7 +213,14 @@ public static boolean validateJWTSignatureWithPublicKey(String jwtString, String try { JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey) publicKey); - return SignedJWT.parse(jwtString).verify(verifier); + boolean isValid = SignedJWT.parse(jwtString).verify(verifier); + if (!isValid) { + log.error("Invalid JWT signature"); + throw new OpenBankingException("Invalid JWT signature"); + } else { + log.debug("Returning true since the JWT signature is valid."); + return true; + } } catch (JOSEException | ParseException e) { throw new OpenBankingException("Error occurred while validating JWT signature"); } diff --git a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.consent.endpoint/src/main/java/com/wso2/openbanking/accelerator/consent/endpoint/api/ConsentValidationEndpoint.java b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.consent.endpoint/src/main/java/com/wso2/openbanking/accelerator/consent/endpoint/api/ConsentValidationEndpoint.java index 49698e925..6d536e084 100644 --- a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.consent.endpoint/src/main/java/com/wso2/openbanking/accelerator/consent/endpoint/api/ConsentValidationEndpoint.java +++ b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.consent.endpoint/src/main/java/com/wso2/openbanking/accelerator/consent/endpoint/api/ConsentValidationEndpoint.java @@ -116,11 +116,10 @@ public Response validate(@Context HttpServletRequest request, @Context HttpServl requestData = JWTUtils.decodeRequestJWT(payload, "body"); } catch (OpenBankingException e) { log.error("Error while validating JWT signature", e); - throw new ConsentException(ResponseStatus.INTERNAL_SERVER_ERROR, "Error while validating JWT " + - "signature"); + throw new ConsentException(ResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage()); } catch (ParseException e) { log.error("Error while decoding validation JWT", e); - throw new ConsentException(ResponseStatus.INTERNAL_SERVER_ERROR, "Error while decoding validation JWT"); + throw new ConsentException(ResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage()); } } else { try {