Search in sources :

Example 21 with EventFactorySupport

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

the class VerifyPasswordlessAccountAuthenticationAction method doExecute.

@Override
public Event doExecute(final RequestContext requestContext) {
    val username = requestContext.getRequestParameters().getRequired("username");
    val account = passwordlessUserAccountStore.findUser(username);
    if (account.isEmpty()) {
        WebUtils.addErrorMessageToContext(requestContext, "passwordless.error.unknown.user");
        return error();
    }
    val user = account.get();
    if (StringUtils.isBlank(user.getPhone()) && StringUtils.isBlank(user.getEmail())) {
        WebUtils.addErrorMessageToContext(requestContext, "passwordless.error.invalid.user");
        return error();
    }
    WebUtils.putPasswordlessAuthenticationAccount(requestContext, user);
    if (user.isRequestPassword()) {
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_PROMPT);
    }
    return success();
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 22 with EventFactorySupport

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

the class SpnegoKnownClientSystemsFilterActionTests method ensureAltRemoteIpHeaderShouldBeChecked.

@Test
public void ensureAltRemoteIpHeaderShouldBeChecked() throws Exception {
    val action = new BaseSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("^74\\.125\\..+"), "alternateRemoteIp", 120);
    val ctx = new MockRequestContext();
    val req = new MockHttpServletRequest();
    req.setRemoteAddr("555.555.555.555");
    req.addHeader("alternateRemoteIp", ALTERNATE_REMOTE_IP);
    val extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    val ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) 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.jupiter.api.Test)

Example 23 with EventFactorySupport

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

the class SpnegoKnownClientSystemsFilterActionTests method ensureHostnameAndIpShouldDoSpnego.

@Test
public void ensureHostnameAndIpShouldDoSpnego() throws Exception {
    val action = new HostNameSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("74\\..+"), StringUtils.EMPTY, 0, "\\w+\\.\\w+\\.\\w+");
    val ctx = new MockRequestContext();
    val req = new MockHttpServletRequest();
    req.setRemoteAddr(ALTERNATE_REMOTE_IP);
    val extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    val ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) 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.jupiter.api.Test)

Example 24 with EventFactorySupport

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

the class BaseLdapSpnegoKnownClientSystemsFilterActionTests method ensureLdapAttributeShouldDoSpnego.

@Test
public void ensureLdapAttributeShouldDoSpnego() throws Exception {
    val ctx = new MockRequestContext();
    val req = new MockHttpServletRequest();
    req.setRemoteAddr("localhost");
    val extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    val ev = ldapSpnegoClientAction.execute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) 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.jupiter.api.Test)

Example 25 with EventFactorySupport

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

the class SpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldBeChecked.

@Test
public void ensureRemoteIpShouldBeChecked() throws Exception {
    val action = new BaseSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("^192\\.158\\..+"), StringUtils.EMPTY, 0);
    val ctx = new MockRequestContext();
    val req = new MockHttpServletRequest();
    req.setRemoteAddr("192.158.5.781");
    val extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    val ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) 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.jupiter.api.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