Search in sources :

Example 1 with BadCredentialsException

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;
}
Also used : JwtToken(org.apache.cxf.rs.security.jose.jwt.JwtToken) OpenSearchSecurityException(org.opensearch.OpenSearchSecurityException) AuthCredentials(org.opensearch.security.user.AuthCredentials) JwtClaims(org.apache.cxf.rs.security.jose.jwt.JwtClaims) AuthenticatorUnavailableException(com.amazon.dlic.auth.http.jwt.keybyoidc.AuthenticatorUnavailableException) BadCredentialsException(com.amazon.dlic.auth.http.jwt.keybyoidc.BadCredentialsException)

Aggregations

AuthenticatorUnavailableException (com.amazon.dlic.auth.http.jwt.keybyoidc.AuthenticatorUnavailableException)1 BadCredentialsException (com.amazon.dlic.auth.http.jwt.keybyoidc.BadCredentialsException)1 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)1 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)1 OpenSearchSecurityException (org.opensearch.OpenSearchSecurityException)1 AuthCredentials (org.opensearch.security.user.AuthCredentials)1