use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class MultifactorAuthenticationProviderBypassTests method verifyMultifactorAuthenticationBypassByPrincipalAttributes.
@Test
public void verifyMultifactorAuthenticationBypassByPrincipalAttributes() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val request = new MockHttpServletRequest();
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setPrincipalAttributeName("givenName");
props.setPrincipalAttributeValue("CAS");
val principal = MultifactorAuthenticationTestUtils.getPrincipal("casuser", CollectionUtils.wrap("givenName", "CAS"));
val authentication = MultifactorAuthenticationTestUtils.getAuthentication(principal, CollectionUtils.wrap("authnFlag", "bypass"));
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val bypass = new PrincipalMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertFalse(bypass.shouldMultifactorAuthenticationProviderExecute(authentication, service, provider, request));
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class MultifactorAuthenticationProviderBypassTests method verifyMultifactorAuthenticationBypassByAuthenticationCredentialClass.
@Test
public void verifyMultifactorAuthenticationBypassByAuthenticationCredentialClass() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val request = new MockHttpServletRequest();
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setCredentialClassType(Credential.class.getName());
val principal = MultifactorAuthenticationTestUtils.getPrincipal("casuser");
val authentication = MultifactorAuthenticationTestUtils.getAuthentication(principal);
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val bypass = new CredentialMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertFalse(bypass.shouldMultifactorAuthenticationProviderExecute(authentication, service, provider, request));
}
use of org.springframework.context.support.StaticApplicationContext 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());
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class MultifactorAuthenticationUtilsTests method verifyProviderByService.
@Test
public void verifyProviderByService() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
assertTrue(MultifactorAuthenticationUtils.getMultifactorAuthenticationProviderFromApplicationContext(provider.getId()).isPresent());
val registeredService = MultifactorAuthenticationTestUtils.getRegisteredService();
when(registeredService.getMultifactorPolicy().getMultifactorAuthenticationProviders()).thenReturn(Set.of("mfa-other"));
var result = MultifactorAuthenticationUtils.getMultifactorAuthenticationProviderForService(registeredService, applicationContext);
assertNotNull(result);
assertTrue(result.isEmpty());
when(registeredService.getMultifactorPolicy().getMultifactorAuthenticationProviders()).thenReturn(Set.of(provider.getId()));
result = MultifactorAuthenticationUtils.getMultifactorAuthenticationProviderForService(registeredService, applicationContext);
assertNotNull(result);
assertFalse(result.isEmpty());
when(registeredService.getMultifactorPolicy()).thenReturn(null);
assertNull(MultifactorAuthenticationUtils.getMultifactorAuthenticationProviderForService(registeredService, applicationContext));
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class MultifactorAuthenticationUtilsTests method verifyMultivaluedAttrs.
@Test
public void verifyMultivaluedAttrs() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
var result = MultifactorAuthenticationUtils.resolveEventViaMultivaluedAttribute(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), List.of("some-value"), MultifactorAuthenticationTestUtils.getRegisteredService(), Optional.of(context), provider, (s, mfaProvider) -> {
throw new RuntimeException("Bad Predicate");
});
assertNotNull(result);
assertTrue(result.isEmpty());
result = MultifactorAuthenticationUtils.resolveEventViaMultivaluedAttribute(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), "some-value", MultifactorAuthenticationTestUtils.getRegisteredService(), Optional.of(context), provider, (s, mfaProvider) -> {
throw new RuntimeException("Bad Predicate");
});
assertNull(result);
}
Aggregations