Search in sources :

Example 6 with AuthenticationResponse

use of org.apache.nifi.registry.security.authentication.AuthenticationResponse in project nifi-registry by apache.

the class AccessResource method createAccessToken.

private String createAccessToken(IdentityProvider identityProvider, AuthenticationRequest authenticationRequest) throws InvalidCredentialsException, AdministrationException {
    final AuthenticationResponse authenticationResponse;
    try {
        authenticationResponse = identityProvider.authenticate(authenticationRequest);
        final String token = jwtService.generateSignedToken(authenticationResponse);
        return token;
    } catch (final IdentityAccessException | JwtException e) {
        throw new AdministrationException(e.getMessage());
    }
}
Also used : JwtException(io.jsonwebtoken.JwtException) IdentityAccessException(org.apache.nifi.registry.security.authentication.exception.IdentityAccessException) AdministrationException(org.apache.nifi.registry.exception.AdministrationException) AuthenticationResponse(org.apache.nifi.registry.security.authentication.AuthenticationResponse)

Example 7 with AuthenticationResponse

use of org.apache.nifi.registry.security.authentication.AuthenticationResponse in project nifi-registry by apache.

the class IdentityAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    // Determine if this AuthenticationProvider's identityProvider should be able to support this AuthenticationRequest
    boolean tokenOriginatedFromThisIdentityProvider = checkTokenOriginatedFromThisIdentityProvider(authentication);
    if (!tokenOriginatedFromThisIdentityProvider) {
        // cannot authenticate this token and another provider should be tried.
        return null;
    }
    AuthenticationRequestToken authenticationRequestToken = ((AuthenticationRequestToken) authentication);
    AuthenticationRequest authenticationRequest = authenticationRequestToken.getAuthenticationRequest();
    try {
        AuthenticationResponse authenticationResponse = identityProvider.authenticate(authenticationRequest);
        if (authenticationResponse == null) {
            return null;
        }
        return buildAuthenticatedToken(authenticationRequestToken, authenticationResponse);
    } catch (InvalidCredentialsException e) {
        throw new BadCredentialsException("Identity Provider authentication failed.", e);
    }
}
Also used : InvalidCredentialsException(org.apache.nifi.registry.security.authentication.exception.InvalidCredentialsException) AuthenticationRequest(org.apache.nifi.registry.security.authentication.AuthenticationRequest) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) AuthenticationResponse(org.apache.nifi.registry.security.authentication.AuthenticationResponse)

Aggregations

AuthenticationResponse (org.apache.nifi.registry.security.authentication.AuthenticationResponse)7 InvalidCredentialsException (org.apache.nifi.registry.security.authentication.exception.InvalidCredentialsException)5 IdentityAccessException (org.apache.nifi.registry.security.authentication.exception.IdentityAccessException)4 Authentication (org.springframework.security.core.Authentication)3 JwtException (io.jsonwebtoken.JwtException)2 SecurityProviderCreationException (org.apache.nifi.registry.security.exception.SecurityProviderCreationException)2 SecurityProviderDestructionException (org.apache.nifi.registry.security.exception.SecurityProviderDestructionException)2 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 IOException (java.io.IOException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 CertificateExpiredException (java.security.cert.CertificateExpiredException)1 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)1 X509Certificate (java.security.cert.X509Certificate)1 AdministrationException (org.apache.nifi.registry.exception.AdministrationException)1