Search in sources :

Example 41 with EventFactorySupport

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

the class AllSpnegoKnownClientSystemsFilterActionTests method ensureHostnameAndIpShouldDoSpnego.

@Test
public void ensureHostnameAndIpShouldDoSpnego() {
    final HostNameSpnegoKnownClientSystemsFilterAction action = new HostNameSpnegoKnownClientSystemsFilterAction("74\\..+", "", 0, "\\w+\\.\\w+\\.\\w+");
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr(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)

Example 42 with EventFactorySupport

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

the class AllSpnegoKnownClientSystemsFilterActionTests method ensureHostnameShouldDoSpnego.

@Test
public void ensureHostnameShouldDoSpnego() {
    final HostNameSpnegoKnownClientSystemsFilterAction action = new HostNameSpnegoKnownClientSystemsFilterAction("", "", 0, "\\w+\\.\\w+\\.\\w+");
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr(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)

Example 43 with EventFactorySupport

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

the class PasswordChangeAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    try {
        final UsernamePasswordCredential c = (UsernamePasswordCredential) WebUtils.getCredential(requestContext);
        final PasswordChangeBean bean = requestContext.getFlowScope().get(PasswordManagementWebflowConfigurer.FLOW_VAR_ID_PASSWORD, PasswordChangeBean.class);
        if (passwordManagementService.change(c, bean)) {
            return new EventFactorySupport().event(this, PASSWORD_UPDATE_SUCCESS);
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    requestContext.getMessageContext().addMessage(new MessageBuilder().error().code("pm.updateFailure").defaultText("Could not update the account password").build());
    return error();
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) PasswordChangeBean(org.apereo.cas.pm.PasswordChangeBean) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 44 with EventFactorySupport

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

the class VerifyPasswordResetRequestAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final PasswordManagementProperties pm = casProperties.getAuthn().getPm();
    final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
    final String token = request.getParameter(PARAMETER_NAME_TOKEN);
    if (StringUtils.isBlank(token)) {
        LOGGER.error("Password reset token is missing");
        return error();
    }
    final String username = passwordManagementService.parseToken(token);
    if (StringUtils.isBlank(username)) {
        LOGGER.error("Password reset token could not be verified");
        return error();
    }
    if (pm.getReset().isSecurityQuestionsEnabled()) {
        final Map<String, String> questions = passwordManagementService.getSecurityQuestions(username);
        if (questions.isEmpty()) {
            LOGGER.warn("No security questions could be found for [{}]", username);
            return error();
        }
        requestContext.getFlowScope().put("questions", new HashSet<>(questions.keySet()));
    } else {
        LOGGER.debug("Security questions are not enabled");
    }
    requestContext.getFlowScope().put("token", token);
    requestContext.getFlowScope().put("username", username);
    requestContext.getFlowScope().put("questionsEnabled", pm.getReset().isSecurityQuestionsEnabled());
    if (pm.getReset().isSecurityQuestionsEnabled()) {
        return success();
    }
    return new EventFactorySupport().event(this, "questionsDisabled");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 45 with EventFactorySupport

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

the class CheckWebAuthenticationRequestAction method doExecute.

@Override
protected Event doExecute(final RequestContext context) throws Exception {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    LOGGER.debug("Checking request content type [{}] against [{}]", request.getContentType(), this.contentType);
    if (this.contentType.equalsIgnoreCase(request.getContentType())) {
        LOGGER.debug("Authentication request via type [{}] is not web-based", this.contentType);
        return new EventFactorySupport().no(this);
    }
    LOGGER.debug("Authenticated request is identified as web-based via type [{}]", request.getContentType());
    return new EventFactorySupport().yes(this);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

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