protected void authenticateAndResolvePrincipal ( final AuthenticationBuilder builder , final Credential credential , final PrincipalResolver resolver , final AuthenticationHandler handler ) throws GeneralSecurityException , PreventedException { publishEvent ( new CasAuthenticationTransactionStartedEvent ( this , credential ) ) ; val result = handler . authenticate ( credential ) ; val authenticationHandlerName = handler . getName ( ) ; builder . addSuccess ( authenticationHandlerName , result ) ; LOGGER . debug ( "Authentication handler [{}] successfully authenticated [{}]" , authenticationHandlerName , credential ) ; publishEvent ( new CasAuthenticationTransactionSuccessfulEvent ( this , credential ) ) ; var principal = result . getPrincipal ( ) ; val resolverName = resolver != null ? resolver . getName ( ) : "N/A" ; if ( resolver == null ) { LOGGER . debug ( "No principal resolution is configured for [{}]. Falling back to handler principal [{}]" , authenticationHandlerName , principal ) ; } else { principal = resolvePrincipal ( handler , resolver , credential , principal ) ; if ( principal == null ) { if ( this . principalResolutionFailureFatal ) { LOGGER . warn ( "Principal resolution handled by [{}] produced a null principal for: [{}]" + "CAS is configured to treat principal resolution failures as fatal." , resolverName , credential ) ; throw new UnresolvedPrincipalException ( ) ; } LOGGER . warn ( "Principal resolution handled by [{}] produced a null principal. " + "This is likely due to misconfiguration or missing attributes; CAS will attempt to use the principal " + "produced by the authentication handler, if any." , resolver . getClass ( ) . getSimpleName ( ) ) ; } } if ( principal == null ) { LOGGER . warn ( "Principal resolution for authentication by [{}] produced a null principal." , authenticationHandlerName ) ; } else { builder . setPrincipal ( principal ) ; } LOGGER . debug ( "Final principal resolved for this authentication event is [{}]" , principal ) ; publishEvent ( new CasAuthenticationPrincipalResolvedEvent ( this , principal ) ) ; }
Authenticate and resolve principal .