use of org.springframework.binding.expression.support.LiteralExpression 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.binding.expression.support.LiteralExpression 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());
}
use of org.springframework.binding.expression.support.LiteralExpression 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());
}
use of org.springframework.binding.expression.support.LiteralExpression 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());
}
use of org.springframework.binding.expression.support.LiteralExpression 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);
}
Aggregations