Search in sources :

Example 21 with AuthenticationException

use of org.apereo.cas.authentication.AuthenticationException in project cas by apereo.

the class AbstractAuthenticationAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final String agent = WebUtils.getHttpServletRequestUserAgent();
    final GeoLocationRequest geoLocation = WebUtils.getHttpServletRequestGeoLocation();
    if (!adaptiveAuthenticationPolicy.apply(agent, geoLocation)) {
        final String msg = "Adaptive authentication policy does not allow this request for " + agent + " and " + geoLocation;
        final Map<String, Class<? extends Exception>> map = Collections.singletonMap(UnauthorizedAuthenticationException.class.getSimpleName(), UnauthorizedAuthenticationException.class);
        final AuthenticationException error = new AuthenticationException(msg, map, Collections.emptyMap());
        return new Event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, new LocalAttributeMap(CasWebflowConstants.TRANSITION_ID_ERROR, error));
    }
    final Event serviceTicketEvent = this.serviceTicketRequestWebflowEventResolver.resolveSingle(requestContext);
    if (serviceTicketEvent != null) {
        fireEventHooks(serviceTicketEvent, requestContext);
        return serviceTicketEvent;
    }
    final Event finalEvent = this.initialAuthenticationAttemptWebflowEventResolver.resolveSingle(requestContext);
    fireEventHooks(finalEvent, requestContext);
    return finalEvent;
}
Also used : LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) UnauthorizedAuthenticationException(org.apereo.cas.authentication.adaptive.UnauthorizedAuthenticationException) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) UnauthorizedAuthenticationException(org.apereo.cas.authentication.adaptive.UnauthorizedAuthenticationException) Event(org.springframework.webflow.execution.Event) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) UnauthorizedAuthenticationException(org.apereo.cas.authentication.adaptive.UnauthorizedAuthenticationException)

Aggregations

AuthenticationException (org.apereo.cas.authentication.AuthenticationException)21 Event (org.springframework.webflow.execution.Event)10 Authentication (org.apereo.cas.authentication.Authentication)9 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)7 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)7 RegisteredService (org.apereo.cas.services.RegisteredService)6 HashMap (java.util.HashMap)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)5 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 Credential (org.apereo.cas.authentication.Credential)5 Map (java.util.Map)4 AbstractTicketException (org.apereo.cas.ticket.AbstractTicketException)4 GeneralSecurityException (java.security.GeneralSecurityException)3 Optional (java.util.Optional)3 AccountLockedException (javax.security.auth.login.AccountLockedException)3 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 PreventedException (org.apereo.cas.authentication.PreventedException)3 Service (org.apereo.cas.authentication.principal.Service)3 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)3