Search in sources :

Example 1 with InvalidAuthenticationException

use of org.apache.nifi.registry.web.security.authentication.exception.InvalidAuthenticationException in project nifi-registry by apache.

the class JwtIdentityProvider method authenticate.

@Override
public AuthenticationResponse authenticate(AuthenticationRequest authenticationRequest) throws InvalidCredentialsException, IdentityAccessException {
    if (authenticationRequest == null) {
        logger.info("Cannot authenticate null authenticationRequest, returning null.");
        return null;
    }
    final Object credentials = authenticationRequest.getCredentials();
    String jwtAuthToken = credentials != null && credentials instanceof String ? (String) credentials : null;
    if (credentials == null) {
        logger.info("JWT not found in authenticationRequest credentials, returning null.");
        return null;
    }
    try {
        final String jwtPrincipal = jwtService.getAuthenticationFromToken(jwtAuthToken);
        return new AuthenticationResponse(jwtPrincipal, jwtPrincipal, expiration, issuer);
    } catch (JwtException e) {
        throw new InvalidAuthenticationException(e.getMessage(), e);
    }
}
Also used : JwtException(io.jsonwebtoken.JwtException) AuthenticationResponse(org.apache.nifi.registry.security.authentication.AuthenticationResponse) InvalidAuthenticationException(org.apache.nifi.registry.web.security.authentication.exception.InvalidAuthenticationException)

Aggregations

JwtException (io.jsonwebtoken.JwtException)1 AuthenticationResponse (org.apache.nifi.registry.security.authentication.AuthenticationResponse)1 InvalidAuthenticationException (org.apache.nifi.registry.web.security.authentication.exception.InvalidAuthenticationException)1