Search in sources :

Example 21 with DefaultTransitionCriteria

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

the class RadiusConfigurationTests method verifyAccessChallengedWebflowEventResolver.

@Test
public void verifyAccessChallengedWebflowEventResolver() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    var result = radiusAccessChallengedAuthenticationWebflowEventResolver.getObject().resolve(context);
    assertNull(result);
    val principal = CoreAuthenticationTestUtils.getPrincipal("casuser", CollectionUtils.wrap(Attr_ReplyMessage.NAME, "Reply-Back", Attr_State.NAME, "State".getBytes(StandardCharsets.UTF_8)));
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(principal), context);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    result = radiusAccessChallengedAuthenticationWebflowEventResolver.getObject().resolve(context);
    assertEquals(1, result.size());
    assertEquals(TestMultifactorAuthenticationProvider.ID, 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) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with DefaultTransitionCriteria

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

the class AuthenticationAttributeMultifactorAuthenticationPolicyEventResolverTests 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 registeredService = RegisteredServiceTestUtils.getRegisteredService();
    servicesManager.save(registeredService);
    WebUtils.putRegisteredService(context, registeredService);
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    var results = authenticationAttributeMultifactorAuthenticationPolicyEventResolver.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);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val authn = RegisteredServiceTestUtils.getAuthentication();
    authn.getAttributes().put("authn-method-dummy", List.of("mfa-dummy"));
    WebUtils.putAuthentication(authn, context);
    results = authenticationAttributeMultifactorAuthenticationPolicyEventResolver.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 23 with DefaultTransitionCriteria

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

the class RequestHeaderMultifactorAuthenticationPolicyEventResolverTests 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 = requestHeaderAuthenticationPolicyWebflowEventResolver.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);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    request.addHeader(casProperties.getAuthn().getMfa().getTriggers().getHttp().getRequestHeader(), TestMultifactorAuthenticationProvider.ID);
    results = requestHeaderAuthenticationPolicyWebflowEventResolver.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 24 with DefaultTransitionCriteria

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

the class MultifactorAuthenticationUtilsTests method verifyResolveBySingleAttribute.

@Test
public void verifyResolveBySingleAttribute() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    assertTrue(MultifactorAuthenticationUtils.getMultifactorAuthenticationProviderFromApplicationContext(provider.getId()).isPresent());
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    val result = MultifactorAuthenticationUtils.resolveEventViaSingleAttribute(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), List.of("mfa-value1"), MultifactorAuthenticationTestUtils.getRegisteredService(), Optional.of(context), provider, (s, mfaProvider) -> RegexUtils.find("mismatch-.+", s));
    assertNull(result);
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) 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)

Aggregations

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