use of org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent in project cas by apereo.
the class PolicyBasedAuthenticationManager method evaluateFinalAuthentication.
/**
* Evaluate produced authentication context.
* We apply an implicit security policy of at least one successful authentication.
* Then, we apply the configured security policy.
*
* @param builder the builder
* @param transaction the transaction
* @throws AuthenticationException the authentication exception
*/
protected void evaluateFinalAuthentication(final AuthenticationBuilder builder, final AuthenticationTransaction transaction) throws AuthenticationException {
if (builder.getSuccesses().isEmpty()) {
publishEvent(new CasAuthenticationTransactionFailureEvent(this, builder.getFailures(), transaction.getCredentials()));
throw new AuthenticationException(builder.getFailures(), builder.getSuccesses());
}
final Authentication authentication = builder.build();
final Pair<Boolean, Set<Throwable>> failures = evaluateAuthenticationPolicies(authentication, transaction);
if (!failures.getKey()) {
publishEvent(new CasAuthenticationPolicyFailureEvent(this, builder.getFailures(), transaction, authentication));
failures.getValue().forEach(e -> handleAuthenticationException(e, e.getClass().getSimpleName(), builder));
throw new AuthenticationException(builder.getFailures(), builder.getSuccesses());
}
}
use of org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent in project cas by apereo.
the class CasAuthenticationEventListenerTests method verifyCasAuthenticationPolicyFailureEvent.
@Test
public void verifyCasAuthenticationPolicyFailureEvent() {
val event = new CasAuthenticationPolicyFailureEvent(this, CollectionUtils.wrap("error", new FailedLoginException()), new DefaultAuthenticationTransaction(CoreAuthenticationTestUtils.getService(), CollectionUtils.wrap(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword())), CoreAuthenticationTestUtils.getAuthentication());
applicationContext.publishEvent(event);
assertFalse(casEventRepository.load().findAny().isEmpty());
}
use of org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent in project cas by apereo.
the class DefaultAuthenticationManager method evaluateFinalAuthentication.
/**
* Evaluate produced authentication context.
* We apply an implicit security policy of at least one successful authentication.
* Then, we apply the configured security policy.
*
* @param builder the builder
* @param transaction the transaction
* @param authenticationHandlers the authentication handlers
* @throws AuthenticationException the authentication exception
*/
protected void evaluateFinalAuthentication(final AuthenticationBuilder builder, final AuthenticationTransaction transaction, final Set<AuthenticationHandler> authenticationHandlers) throws AuthenticationException {
if (builder.getSuccesses().isEmpty()) {
publishEvent(new CasAuthenticationTransactionFailureEvent(this, builder.getFailures(), transaction.getCredentials()));
throw new AuthenticationException(builder.getFailures(), builder.getSuccesses());
}
val authentication = builder.build();
val executionResult = evaluateAuthenticationPolicies(authentication, transaction, authenticationHandlers);
if (!executionResult.isSuccess()) {
publishEvent(new CasAuthenticationPolicyFailureEvent(this, builder.getFailures(), transaction, authentication));
executionResult.getFailures().forEach(e -> handleAuthenticationException(e, e.getClass().getSimpleName(), builder));
throw new AuthenticationException(builder.getFailures(), builder.getSuccesses());
}
}
use of org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent in project cas by apereo.
the class PolicyBasedAuthenticationManager method evaluateProducedAuthenticationContext.
/**
* Evaluate produced authentication context.
* We apply an implicit security policy of at least one successful authentication.
* Then, we apply the configured security policy.
*
* @param builder the builder
* @param transaction the transaction
* @throws AuthenticationException the authentication exception
*/
protected void evaluateProducedAuthenticationContext(final AuthenticationBuilder builder, final AuthenticationTransaction transaction) throws AuthenticationException {
if (builder.getSuccesses().isEmpty()) {
publishEvent(new CasAuthenticationTransactionFailureEvent(this, builder.getFailures(), transaction.getCredentials()));
throw new AuthenticationException(builder.getFailures(), builder.getSuccesses());
}
LOGGER.debug("Executing authentication policy [{}]", this.authenticationPolicy);
final Authentication authentication = builder.build();
if (!this.authenticationPolicy.isSatisfiedBy(authentication)) {
publishEvent(new CasAuthenticationPolicyFailureEvent(this, builder.getFailures(), transaction, authentication));
throw new AuthenticationException(builder.getFailures(), builder.getSuccesses());
}
}
use of org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent in project cas by apereo.
the class DefaultCasEventListener method handleCasAuthenticationPolicyFailureEvent.
/**
* Handle cas authentication policy failure event.
*
* @param event the event
*/
@EventListener
public void handleCasAuthenticationPolicyFailureEvent(final CasAuthenticationPolicyFailureEvent event) {
if (this.casEventRepository != null) {
final CasEvent dto = prepareCasEvent(event);
dto.setPrincipalId(event.getAuthentication().getPrincipal().getId());
dto.putId(CasAuthenticationPolicyFailureEvent.class.getSimpleName());
this.casEventRepository.save(dto);
}
}
Aggregations