Search in sources :

Example 6 with Transition

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

the class MultifactorAuthenticationUtilsTests method verifyResolveByAttribute.

@Test
public void verifyResolveByAttribute() {
    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.resolveEventViaMultivaluedAttribute(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), List.of("mfa-value"), MultifactorAuthenticationTestUtils.getRegisteredService(), Optional.of(context), provider, (s, mfaProvider) -> RegexUtils.find("mfa-.+", s));
    assertNotNull(result);
    assertFalse(result.isEmpty());
}
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)

Example 7 with Transition

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

the class DefaultMultifactorAuthenticationProviderResolverTests method registerProviderInApplicationContext.

private static TestMultifactorAuthenticationProvider registerProviderInApplicationContext(final ConfigurableApplicationContext applicationContext, final MockRequestContext context, final TestMultifactorAuthenticationProvider candidateProvider) {
    val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, candidateProvider);
    val targetResolver = new DefaultTargetStateResolver(provider.getId());
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(provider.getId())), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    return (TestMultifactorAuthenticationProvider) provider;
}
Also used : lombok.val(lombok.val) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) 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)

Example 8 with Transition

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

the class RankedMultifactorAuthenticationProviderWebflowEventResolverTests method verifyAuthnResolvesMfaEvent.

@Test
public void verifyAuthnResolvesMfaEvent() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addParameter(casProperties.getAuthn().getMfa().getTriggers().getHttp().getRequestParameter(), TestMultifactorAuthenticationProvider.ID);
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    val service = RegisteredServiceTestUtils.getRegisteredService(Map.of());
    servicesManager.save(service);
    WebUtils.putRegisteredService(context, service);
    val tgt = new MockTicketGrantingTicket("casuser");
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    cas.addTicket(tgt);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon"));
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    assertEquals(TestMultifactorAuthenticationProvider.ID, resolver.resolveSingle(context).getId());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) 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 9 with Transition

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

the class RankedMultifactorAuthenticationProviderWebflowEventResolverTests method verifyAuthnResolvesMfaContextValidated.

@Test
public void verifyAuthnResolvesMfaContextValidated() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addParameter(casProperties.getAuthn().getMfa().getTriggers().getHttp().getRequestParameter(), TestMultifactorAuthenticationProvider.ID);
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val tgt = new MockTicketGrantingTicket("casuser", Map.of(), Map.of(casProperties.getAuthn().getMfa().getCore().getAuthenticationContextAttribute(), List.of(TestMultifactorAuthenticationProvider.ID)));
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    cas.addTicket(tgt);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon"));
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolve(context).iterator().next().getId());
    val registeredService = RegisteredServiceTestUtils.getRegisteredService(Map.of());
    val multifactorPolicy = new DefaultRegisteredServiceMultifactorPolicy();
    multifactorPolicy.setForceExecution(true);
    registeredService.setMultifactorPolicy(multifactorPolicy);
    WebUtils.putRegisteredService(context, registeredService);
    assertEquals(TestMultifactorAuthenticationProvider.ID, resolver.resolveSingle(context).getId());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) DefaultRegisteredServiceMultifactorPolicy(org.apereo.cas.services.DefaultRegisteredServiceMultifactorPolicy) 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 10 with Transition

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

the class RankedMultifactorAuthenticationProviderWebflowEventResolverTests method verifyAuthnResolvesMfaContextValidatedNoForceExecution.

@Test
public void verifyAuthnResolvesMfaContextValidatedNoForceExecution() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addParameter(casProperties.getAuthn().getMfa().getTriggers().getHttp().getRequestParameter(), TestMultifactorAuthenticationProvider.ID);
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val tgt = new MockTicketGrantingTicket("casuser", Map.of(), Map.of(casProperties.getAuthn().getMfa().getCore().getAuthenticationContextAttribute(), List.of(TestMultifactorAuthenticationProvider.ID)));
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    cas.addTicket(tgt);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon"));
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolve(context).iterator().next().getId());
    val registeredService = RegisteredServiceTestUtils.getRegisteredService(Map.of());
    WebUtils.putRegisteredService(context, registeredService);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolveSingle(context).getId());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) 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)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