Search in sources :

Example 1 with AccepttoMultifactorTokenCredential

use of org.apereo.cas.mfa.accepto.AccepttoMultifactorTokenCredential in project cas by apereo.

the class AccepttoMultifactorValidateChannelAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    val eventAttributes = new LocalAttributeMap<>();
    try {
        val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
        val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
        val webContext = new JEEContext(request, response);
        val channel = AccepttoWebflowUtils.getChannel(webContext, sessionStore);
        if (channel.isEmpty()) {
            LOGGER.debug("Unable to determine channel from session store; not a validation attempt");
            return null;
        }
        val authentication = AccepttoWebflowUtils.getAuthentication(webContext, sessionStore);
        if (authentication == null) {
            LOGGER.debug("Unable to determine the original authentication attempt the session store");
            throw new AuthenticationException("Unable to determine authentication from session store");
        }
        WebUtils.putAuthentication(authentication, requestContext);
        val credential = new AccepttoMultifactorTokenCredential(channel.toString());
        val service = WebUtils.getService(requestContext);
        LOGGER.debug("Cleaning up session store to remove [{}]", credential);
        AccepttoWebflowUtils.resetChannelAndAuthentication(webContext, sessionStore);
        AccepttoWebflowUtils.setChannel(requestContext, null);
        LOGGER.debug("Attempting to authenticate channel [{}] with authentication [{}] and service [{}]", credential, authentication, service);
        var resultBuilder = authenticationSystemSupport.establishAuthenticationContextFromInitial(authentication);
        resultBuilder = authenticationSystemSupport.handleAuthenticationTransaction(service, resultBuilder, credential);
        WebUtils.putAuthenticationResultBuilder(resultBuilder, requestContext);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_FINALIZE);
    } catch (final Exception e) {
        eventAttributes.put("error", e);
        LoggingUtils.error(LOGGER, e);
    }
    return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, eventAttributes);
}
Also used : lombok.val(lombok.val) LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) JEEContext(org.pac4j.core.context.JEEContext) AccepttoMultifactorTokenCredential(org.apereo.cas.mfa.accepto.AccepttoMultifactorTokenCredential) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) AuthenticationException(org.apereo.cas.authentication.AuthenticationException)

Aggregations

lombok.val (lombok.val)1 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)1 AccepttoMultifactorTokenCredential (org.apereo.cas.mfa.accepto.AccepttoMultifactorTokenCredential)1 JEEContext (org.pac4j.core.context.JEEContext)1 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)1 LocalAttributeMap (org.springframework.webflow.core.collection.LocalAttributeMap)1