use of com.amazon.dlic.auth.http.jwt.keybyoidc.BadCredentialsException in project security by opensearch-project.
the class AbstractHTTPJwtAuthenticator method extractCredentials0.
private AuthCredentials extractCredentials0(final RestRequest request) throws OpenSearchSecurityException {
String jwtString = getJwtTokenString(request);
if (Strings.isNullOrEmpty(jwtString)) {
return null;
}
JwtToken jwt;
try {
jwt = jwtVerifier.getVerifiedJwtToken(jwtString);
} catch (AuthenticatorUnavailableException e) {
log.info(e.toString());
throw new OpenSearchSecurityException(e.getMessage(), RestStatus.SERVICE_UNAVAILABLE);
} catch (BadCredentialsException e) {
log.info("Extracting JWT token from {} failed", jwtString, e);
return null;
}
JwtClaims claims = jwt.getClaims();
final String subject = extractSubject(claims);
if (subject == null) {
log.error("No subject found in JWT token");
return null;
}
final String[] roles = extractRoles(claims);
final AuthCredentials ac = new AuthCredentials(subject, roles).markComplete();
for (Entry<String, Object> claim : claims.asMap().entrySet()) {
ac.addAttribute("attr.jwt." + claim.getKey(), String.valueOf(claim.getValue()));
}
return ac;
}
Aggregations