use of org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException in project cas by apereo.
the class AbstractAuthenticationManager method authenticate.
@Override
@Audit(action = "AUTHENTICATION", actionResolverName = "AUTHENTICATION_RESOLVER", resourceResolverName = "AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name = "AUTHENTICATE_TIMER")
@Metered(name = "AUTHENTICATE_METER")
@Counted(name = "AUTHENTICATE_COUNT", monotonic = true)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {
AuthenticationCredentialsLocalBinder.bindCurrent(transaction.getCredentials());
final AuthenticationBuilder builder = authenticateInternal(transaction);
authenticationEventExecutionPlan.getAuthenticationPostProcessors().forEach(p -> {
LOGGER.info("Invoking authentication post processor [{}]", p);
p.process(transaction, builder);
});
final Authentication authentication = builder.build();
final Principal principal = authentication.getPrincipal();
if (principal instanceof NullPrincipal) {
throw new UnresolvedPrincipalException(authentication);
}
addAuthenticationMethodAttribute(builder, authentication);
LOGGER.info("Authenticated principal [{}] with attributes [{}] via credentials [{}].", principal.getId(), principal.getAttributes(), transaction.getCredentials());
populateAuthenticationMetadataAttributes(builder, transaction.getCredentials());
final Authentication a = builder.build();
AuthenticationCredentialsLocalBinder.bindCurrent(a);
return a;
}
use of org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException 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));
}
use of org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException in project cas by apereo.
the class DefaultAuthenticationManager 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 {
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();
if (resolver != null) {
principal = resolvePrincipal(handler, resolver, credential, principal);
}
if (principal == null) {
val resolverName = resolver == null ? authenticationHandlerName : resolver.getName();
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.", resolverName);
} else {
builder.setPrincipal(principal);
}
LOGGER.debug("Final principal resolved for this authentication event is [{}]", principal);
publishEvent(new CasAuthenticationPrincipalResolvedEvent(this, principal));
}
use of org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException in project cas by apereo.
the class PolicyBasedAuthenticationManager method authenticate.
@Override
@Audit(action = "AUTHENTICATION", actionResolverName = "AUTHENTICATION_RESOLVER", resourceResolverName = "AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name = "AUTHENTICATE_TIMER")
@Metered(name = "AUTHENTICATE_METER")
@Counted(name = "AUTHENTICATE_COUNT", monotonic = true)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {
AuthenticationCredentialsThreadLocalBinder.bindCurrent(transaction.getCredentials());
final AuthenticationBuilder builder = authenticateInternal(transaction);
AuthenticationCredentialsThreadLocalBinder.bindCurrent(builder);
final Authentication authentication = builder.build();
addAuthenticationMethodAttribute(builder, authentication);
populateAuthenticationMetadataAttributes(builder, transaction);
invokeAuthenticationPostProcessors(builder, transaction);
final Authentication auth = builder.build();
final Principal 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;
}
use of org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException in project cas by apereo.
the class PolicyBasedAuthenticationManager 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 {
publishEvent(new CasAuthenticationTransactionStartedEvent(this, credential));
final AuthenticationHandlerExecutionResult result = handler.authenticate(credential);
builder.addSuccess(handler.getName(), result);
LOGGER.debug("Authentication handler [{}] successfully authenticated [{}]", handler.getName(), credential);
publishEvent(new CasAuthenticationTransactionSuccessfulEvent(this, credential));
Principal principal = result.getPrincipal();
final String resolverName = resolver != null ? resolver.getClass().getSimpleName() : "N/A";
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.", 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.", handler.getName());
} else {
builder.setPrincipal(principal);
}
LOGGER.debug("Final principal resolved for this authentication event is [{}]", principal);
publishEvent(new CasAuthenticationPrincipalResolvedEvent(this, principal));
}
Aggregations