Search in sources :

Example 36 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class ValidatePasswordResetTokenAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    try {
        val transientTicket = requestContext.getRequestParameters().get(PasswordManagementWebflowUtils.REQUEST_PARAMETER_NAME_PASSWORD_RESET_TOKEN);
        if (StringUtils.isNotBlank(transientTicket)) {
            val tst = centralAuthenticationService.getTicket(transientTicket, TransientSessionTicket.class);
            val token = tst.getProperties().get(PasswordManagementWebflowUtils.FLOWSCOPE_PARAMETER_NAME_TOKEN).toString();
            val username = passwordManagementService.parseToken(token);
            if (StringUtils.isBlank(username)) {
                throw new IllegalArgumentException("Password reset token could not be verified to determine username");
            }
        }
        return null;
    } catch (final Exception e) {
        LoggingUtils.warn(LOGGER, e);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_INVALID_PASSWORD_RESET_TOKEN);
    }
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 37 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class LoadSurrogatesListAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    try {
        if (WebUtils.hasSurrogateAuthenticationRequest(requestContext)) {
            WebUtils.removeSurrogateAuthenticationRequest(requestContext);
            LOGGER.trace("Attempting to load surrogates...");
            if (loadSurrogates(requestContext)) {
                return new Event(this, CasWebflowConstants.TRANSITION_ID_SURROGATE_VIEW);
            }
            return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_SKIP_SURROGATE);
        }
        val currentCredential = WebUtils.getCredential(requestContext);
        if (currentCredential instanceof SurrogateUsernamePasswordCredential) {
            val authenticationResultBuilder = WebUtils.getAuthenticationResultBuilder(requestContext);
            val credential = (SurrogateUsernamePasswordCredential) currentCredential;
            val registeredService = WebUtils.getRegisteredService(requestContext);
            val result = surrogatePrincipalBuilder.buildSurrogateAuthenticationResult(authenticationResultBuilder, currentCredential, credential.getSurrogateUsername(), registeredService);
            result.ifPresent(builder -> WebUtils.putAuthenticationResultBuilder(builder, requestContext));
        }
        return success();
    } catch (final Exception e) {
        requestContext.getMessageContext().addMessage(new MessageBuilder().error().source("surrogate").code("screen.surrogates.account.selection.error").defaultText("Unable to accept or authorize selection").build());
        LoggingUtils.error(LOGGER, e);
        return error(e);
    }
}
Also used : lombok.val(lombok.val) MessageBuilder(org.springframework.binding.message.MessageBuilder) Event(org.springframework.webflow.execution.Event) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) SurrogateUsernamePasswordCredential(org.apereo.cas.authentication.SurrogateUsernamePasswordCredential)

Example 38 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class WebAuthnValidateSessionCredentialTokenAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
    val token = request.getParameter("token");
    if (StringUtils.isBlank(token)) {
        LOGGER.warn("Missing web authn token from the request");
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE);
    }
    LOGGER.debug("Received web authn token [{}]", token);
    val credential = new WebAuthnCredential(token);
    WebUtils.putCredential(requestContext, credential);
    val session = sessionManager.getSession(WebAuthnCredential.from(credential));
    if (session.isEmpty()) {
        LOGGER.warn("Unable to locate existing session from the current token [{}]", token);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE);
    }
    val result = webAuthnCredentialRepository.getUsernameForUserHandle(session.get());
    if (result.isEmpty()) {
        LOGGER.warn("Unable to locate user based on the given user handle");
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE);
    }
    val username = result.get();
    val authentication = DefaultAuthenticationBuilder.newInstance().addCredential(credential).setPrincipal(principalFactory.createPrincipal(username)).build();
    LOGGER.warn("Finalized authentication attempt based on [{}]", authentication);
    WebUtils.putAuthentication(authentication, requestContext);
    return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_FINALIZE);
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) WebAuthnCredential(org.apereo.cas.webauthn.WebAuthnCredential)

Example 39 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class WebAuthnAccountCheckRegistrationAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    val authentication = WebUtils.getAuthentication(requestContext);
    val principal = resolvePrincipal(authentication.getPrincipal());
    LOGGER.trace("Checking registration record for [{}]", principal.getId());
    val registrations = webAuthnCredentialRepository.getRegistrationsByUsername(principal.getId());
    if (!registrations.isEmpty()) {
        return success();
    }
    return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_REGISTER);
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 40 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class AllSpnegoKnownClientSystemsFilterActionTests method ensureAltRemoteIpHeaderShouldBeChecked.

@Test
public void ensureAltRemoteIpHeaderShouldBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction("^74\\.125\\..+", "alternateRemoteIp", 120);
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("555.555.555.555");
    req.addHeader("alternateRemoteIp", ALTERNATE_REMOTE_IP);
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Aggregations

EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)78 lombok.val (lombok.val)61 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)26 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)26 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)26 MockServletContext (org.springframework.mock.web.MockServletContext)25 MockRequestContext (org.springframework.webflow.test.MockRequestContext)23 Test (org.junit.jupiter.api.Test)21 Event (org.springframework.webflow.execution.Event)12 Test (org.junit.Test)7 LocalAttributeMap (org.springframework.webflow.core.collection.LocalAttributeMap)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HashMap (java.util.HashMap)4 Authentication (org.apereo.cas.authentication.Authentication)4 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 WebUtils (org.apereo.cas.web.support.WebUtils)3 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)3 MessageContext (org.springframework.binding.message.MessageContext)3 Transition (org.springframework.webflow.engine.Transition)3