Search in sources :

Example 1 with CasAuthenticationTransactionStartedEvent

use of org.apereo.cas.support.events.authentication.CasAuthenticationTransactionStartedEvent in project cas by apereo.

the class AbstractAuthenticationManager method authenticateAndResolvePrincipal.

/**
     * Authenticate and resolve principal.
     *
     * @param builder    the builder
     * @param credential the credential
     * @param resolver   the resolver
     * @param handler    the handler
     * @throws GeneralSecurityException the general security exception
     * @throws PreventedException       the prevented exception
     */
protected void authenticateAndResolvePrincipal(final AuthenticationBuilder builder, final Credential credential, final PrincipalResolver resolver, final AuthenticationHandler handler) throws GeneralSecurityException, PreventedException {
    Principal principal;
    publishEvent(new CasAuthenticationTransactionStartedEvent(this, credential));
    final HandlerResult result = handler.authenticate(credential);
    builder.addSuccess(handler.getName(), result);
    LOGGER.debug("Authentication handler [{}] successfully authenticated [{}]", handler.getName(), credential);
    publishEvent(new CasAuthenticationTransactionSuccessfulEvent(this, credential));
    principal = result.getPrincipal();
    if (resolver == null) {
        LOGGER.debug("No principal resolution is configured for [{}]. Falling back to handler principal [{}]", handler.getName(), 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.", resolver.getClass().getSimpleName(), 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) {
        builder.setPrincipal(principal);
    }
    LOGGER.debug("Final principal resolved for this authentication event is [{}]", principal);
    publishEvent(new CasAuthenticationPrincipalResolvedEvent(this, principal));
}
Also used : CasAuthenticationPrincipalResolvedEvent(org.apereo.cas.support.events.authentication.CasAuthenticationPrincipalResolvedEvent) CasAuthenticationTransactionStartedEvent(org.apereo.cas.support.events.authentication.CasAuthenticationTransactionStartedEvent) UnresolvedPrincipalException(org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException) CasAuthenticationTransactionSuccessfulEvent(org.apereo.cas.support.events.authentication.CasAuthenticationTransactionSuccessfulEvent) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) Principal(org.apereo.cas.authentication.principal.Principal)

Aggregations

UnresolvedPrincipalException (org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException)1 NullPrincipal (org.apereo.cas.authentication.principal.NullPrincipal)1 Principal (org.apereo.cas.authentication.principal.Principal)1 CasAuthenticationPrincipalResolvedEvent (org.apereo.cas.support.events.authentication.CasAuthenticationPrincipalResolvedEvent)1 CasAuthenticationTransactionStartedEvent (org.apereo.cas.support.events.authentication.CasAuthenticationTransactionStartedEvent)1 CasAuthenticationTransactionSuccessfulEvent (org.apereo.cas.support.events.authentication.CasAuthenticationTransactionSuccessfulEvent)1