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));
}
Aggregations