Search in sources :

Example 11 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class SelectiveMultifactorAuthenticationProviderWebflowEventResolverTests method verifyOperation.

@Test
public void verifyOperation() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val service = RegisteredServiceTestUtils.getRegisteredService();
    servicesManager.save(service);
    WebUtils.putRegisteredService(context, service);
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val resolvedEvents = CollectionUtils.wrapHashSet(new EventFactorySupport().event(this, provider.getId()));
    WebUtils.putResolvedEventsAsAttribute(context, resolvedEvents);
    val result = selectiveAuthenticationProviderWebflowEventResolver.resolve(context);
    assertNotNull(result);
    assertNotNull(WebUtils.getResolvedMultifactorAuthenticationProviders(context));
    assertEquals(provider.getId(), result.iterator().next().getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test)

Example 12 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class SelectiveMultifactorAuthenticationProviderWebflowEventResolverTests method verifyEmptyOperation.

@Test
public void verifyEmptyOperation() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val service = RegisteredServiceTestUtils.getRegisteredService();
    servicesManager.save(service);
    WebUtils.putRegisteredService(context, service);
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    val resolvedEvents = CollectionUtils.wrapHashSet(new EventFactorySupport().event(this, "mfa-something"));
    WebUtils.putResolvedEventsAsAttribute(context, resolvedEvents);
    val result = selectiveAuthenticationProviderWebflowEventResolver.resolve(context);
    assertNotNull(result);
    assertTrue(WebUtils.getResolvedMultifactorAuthenticationProviders(context).isEmpty());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test)

Example 13 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class SelectiveMultifactorAuthenticationProviderWebflowEventResolverTests method verifyNoProvider.

@Test
public void verifyNoProvider() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val service = RegisteredServiceTestUtils.getRegisteredService();
    servicesManager.save(service);
    WebUtils.putRegisteredService(context, service);
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    val resolvedEvents = CollectionUtils.wrapHashSet(new EventFactorySupport().event(this, "mfa-something"));
    WebUtils.putResolvedEventsAsAttribute(context, resolvedEvents);
    val result = selectiveAuthenticationProviderWebflowEventResolver.resolve(context);
    assertNotNull(result);
    assertFalse(result.isEmpty());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test)

Example 14 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class RequestParameterMultifactorAuthenticationPolicyEventResolverTests method verifyOperation.

@Test
public void verifyOperation() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val service = RegisteredServiceTestUtils.getRegisteredService();
    servicesManager.save(service);
    WebUtils.putRegisteredService(context, service);
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    var results = requestParameterAuthenticationPolicyWebflowEventResolver.resolve(context);
    assertNull(results);
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    request.addParameter(casProperties.getAuthn().getMfa().getTriggers().getHttp().getRequestParameter(), TestMultifactorAuthenticationProvider.ID);
    results = requestParameterAuthenticationPolicyWebflowEventResolver.resolve(context);
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(TestMultifactorAuthenticationProvider.ID, results.iterator().next().getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 15 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class GrouperMultifactorAuthenticationPolicyEventResolverTests method verifyOperation.

@Test
public void verifyOperation() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    val event = resolver.resolve(context);
    assertEquals(1, event.size());
    assertEquals(TestMultifactorAuthenticationProvider.ID, event.iterator().next().getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Transition (org.springframework.webflow.engine.Transition)38 lombok.val (lombok.val)29 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)29 DefaultTransitionCriteria (org.springframework.webflow.engine.support.DefaultTransitionCriteria)24 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)23 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)22 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)22 MockServletContext (org.springframework.mock.web.MockServletContext)22 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)22 MockRequestContext (org.springframework.webflow.test.MockRequestContext)22 Test (org.junit.jupiter.api.Test)17 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)5 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Flow (org.springframework.webflow.engine.Flow)4 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)3 ActionState (org.springframework.webflow.engine.ActionState)3 Authentication (org.apereo.cas.authentication.Authentication)2 DefaultRegisteredServiceMultifactorPolicy (org.apereo.cas.services.DefaultRegisteredServiceMultifactorPolicy)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2