use of fish.payara.microprofile.jwtauth.jwt.JwtTokenParser in project Payara by payara.
the class SignedJWTIdentityStore method validate.
public CredentialValidationResult validate(SignedJWTCredential signedJWTCredential) {
final JwtTokenParser jwtTokenParser = new JwtTokenParser(enabledNamespace, customNamespace, disableTypeVerification);
try {
JsonWebTokenImpl jsonWebToken = jwtTokenParser.parse(signedJWTCredential.getSignedJWT(), isEncryptionRequired, publicKeyStore, acceptedIssuer, privateKeyStore);
// verifyAndParseEncryptedJWT audience
final Set<String> recipientsOfThisJWT = jsonWebToken.getAudience();
// find if any recipient is in the allowed audience
Boolean recipientInAudience = allowedAudience.map(recipient -> recipient.stream().anyMatch(a -> recipientsOfThisJWT != null && recipientsOfThisJWT.contains(a))).orElse(true);
if (!recipientInAudience) {
throw new Exception("The intended audience " + recipientsOfThisJWT + " is not a part of allowed audience.");
}
Set<String> groups = new HashSet<>();
Collection<String> groupClaims = jsonWebToken.getClaim("groups");
if (groupClaims != null) {
groups.addAll(groupClaims);
}
return new CredentialValidationResult(jsonWebToken, groups);
} catch (Exception e) {
LOGGER.log(INFO, "Exception trying to parse JWT token.", e);
}
return INVALID_RESULT;
}
Aggregations