Search in sources :

Example 56 with Event

use of org.springframework.webflow.execution.Event 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

Event (org.springframework.webflow.execution.Event)56 Test (org.junit.Test)26 MockRequestContext (org.springframework.webflow.test.MockRequestContext)20 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)15 Authentication (org.apereo.cas.authentication.Authentication)13 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)13 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)13 RegisteredService (org.apereo.cas.services.RegisteredService)12 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)11 MockServletContext (org.springframework.mock.web.MockServletContext)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)8 LogoutProperties (org.apereo.cas.configuration.model.core.logout.LogoutProperties)8 WebUtils (org.apereo.cas.web.support.WebUtils)8 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)8 RequestContext (org.springframework.webflow.execution.RequestContext)8 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Map (java.util.Map)6