use of org.springframework.webflow.test.MockRequestContext 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());
}
use of org.springframework.webflow.test.MockRequestContext 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());
}
use of org.springframework.webflow.test.MockRequestContext 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());
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class RankedMultifactorAuthenticationProviderWebflowEventResolverTests method verifyWithNoTicketOrService.
@Test
public void verifyWithNoTicketOrService() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolve(context).iterator().next().getId());
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
val service = RegisteredServiceTestUtils.getRegisteredService(Map.of());
servicesManager.save(service);
WebUtils.putRegisteredService(context, service);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolve(context).iterator().next().getId());
val tgt = new MockTicketGrantingTicket("casuser");
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolve(context).iterator().next().getId());
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class RankedMultifactorAuthenticationProviderWebflowEventResolverTests method verifyAuthnResolvesEvent.
@Test
public void verifyAuthnResolvesEvent() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
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);
WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon"));
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolve(context).iterator().next().getId());
}
Aggregations