/** * Handle cas authentication policy failure event. * * @param event the event */ @EventListener public void handleCasAuthenticationTransactionFailureEvent(final CasAuthenticationTransactionFailureEvent event) { if (this.casEventRepository != null) { val dto = prepareCasEvent(event); dto.setPrincipalId(event.getCredential().getId()); dto.putEventId(CasAuthenticationPolicyFailureEvent.class.getSimpleName()); this.casEventRepository.save(dto); } }
/** * 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 failures = evaluateAuthenticationPolicies(authentication, transaction, authenticationHandlers); 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()); } }