Search in sources :

Example 6 with UnresolvedPrincipalException

use of org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException in project cas by apereo.

the class DefaultAuthenticationManager method authenticate.

@Override
@Audit(action = AuditableActions.AUTHENTICATION, actionResolverName = AuditActionResolvers.AUTHENTICATION_RESOLVER, resourceResolverName = AuditResourceResolvers.AUTHENTICATION_RESOURCE_RESOLVER)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {
    val result = invokeAuthenticationPreProcessors(transaction);
    if (!result) {
        LOGGER.warn("An authentication pre-processor could not successfully process the authentication transaction");
        throw new AuthenticationException("Authentication pre-processor has failed to process transaction");
    }
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(transaction.getCredentials());
    val builder = authenticateInternal(transaction);
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(builder);
    val authentication = builder.build();
    addAuthenticationMethodAttribute(builder, authentication);
    populateAuthenticationMetadataAttributes(builder, transaction);
    invokeAuthenticationPostProcessors(builder, transaction);
    val auth = builder.build();
    val principal = auth.getPrincipal();
    if (principal instanceof NullPrincipal) {
        throw new UnresolvedPrincipalException(auth);
    }
    LOGGER.info("Authenticated principal [{}] with attributes [{}] via credentials [{}].", principal.getId(), principal.getAttributes(), transaction.getCredentials());
    AuthenticationCredentialsThreadLocalBinder.bindCurrent(auth);
    return auth;
}
Also used : lombok.val(lombok.val) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) UnresolvedPrincipalException(org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException) Audit(org.apereo.inspektr.audit.annotation.Audit)

Aggregations

UnresolvedPrincipalException (org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException)6 NullPrincipal (org.apereo.cas.authentication.principal.NullPrincipal)5 Principal (org.apereo.cas.authentication.principal.Principal)4 CasAuthenticationPrincipalResolvedEvent (org.apereo.cas.support.events.authentication.CasAuthenticationPrincipalResolvedEvent)3 CasAuthenticationTransactionStartedEvent (org.apereo.cas.support.events.authentication.CasAuthenticationTransactionStartedEvent)3 CasAuthenticationTransactionSuccessfulEvent (org.apereo.cas.support.events.authentication.CasAuthenticationTransactionSuccessfulEvent)3 Audit (org.apereo.inspektr.audit.annotation.Audit)3 Counted (com.codahale.metrics.annotation.Counted)2 Metered (com.codahale.metrics.annotation.Metered)2 Timed (com.codahale.metrics.annotation.Timed)2 lombok.val (lombok.val)2