use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderResolverTests method verifyResolutionByPrincipalAttribute.
@Test
public void verifyResolutionByPrincipalAttribute() {
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));
val provider = registerProviderInApplicationContext(applicationContext, context, new TestMultifactorAuthenticationProvider());
val resolver = new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical());
val principal = CoreAuthenticationTestUtils.getPrincipal("casuser", CollectionUtils.wrap("authlevel", List.of(provider.getId())));
var results = resolver.resolveEventViaPrincipalAttribute(principal, List.of("authlevel"), CoreAuthenticationTestUtils.getRegisteredService(), Optional.of(context), List.of(provider), (input, mfaProvider) -> input.equalsIgnoreCase(provider.getId()));
assertNotNull(results);
assertEquals(provider.getId(), results.iterator().next().getId());
results = resolver.resolveEventViaPrincipalAttribute(principal, List.of("authlevel"), CoreAuthenticationTestUtils.getRegisteredService(), Optional.of(context), List.of(), (input, mfaProvider) -> input.equalsIgnoreCase(provider.getId()));
assertNull(results);
results = resolver.resolveEventViaPrincipalAttribute(principal, List.of(), CoreAuthenticationTestUtils.getRegisteredService(), Optional.of(context), List.of(), (input, mfaProvider) -> input.equalsIgnoreCase(provider.getId()));
assertNull(results);
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderResolverTests method verifyMultipleProvidersWithPrincipalAttributes.
@Test
public void verifyMultipleProvidersWithPrincipalAttributes() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val casProperties = new CasConfigurationProperties();
casProperties.getAuthn().getMfa().getTriggers().getPrincipal().setGlobalPrincipalAttributeNameTriggers("mfa-principal");
val resolver = new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical());
val trigger = new PrincipalAttributeMultifactorAuthenticationTrigger(casProperties, resolver, applicationContext);
assertProviderResolutionFromManyProviders(trigger, applicationContext, true);
assertThrows(UnsatisfiedAuthenticationContextTicketValidationException.class, () -> {
throw new UnsatisfiedAuthenticationContextTicketValidationException(MultifactorAuthenticationTestUtils.getService("id"));
});
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderResolverTests method verifyNoMatch.
@Test
public void verifyNoMatch() {
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));
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val resolver = new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical());
val principal = CoreAuthenticationTestUtils.getPrincipal("casuser");
val results = resolver.resolveEventViaAttribute(principal, Map.of("authlevel", List.of("strong")), List.of(), CoreAuthenticationTestUtils.getRegisteredService(), Optional.of(context), List.of(provider), (s, mfaProvider) -> false);
assertNull(results);
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderResolverTests method verifyResolutionByAuthenticationAttribute.
@Test
public void verifyResolutionByAuthenticationAttribute() {
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));
val provider = registerProviderInApplicationContext(applicationContext, context, new TestMultifactorAuthenticationProvider());
val resolver = new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical());
val authentication = CoreAuthenticationTestUtils.getAuthentication("casuser", CollectionUtils.wrap("authlevel", List.of(provider.getId())));
val results = resolver.resolveEventViaAuthenticationAttribute(authentication, List.of("authlevel"), CoreAuthenticationTestUtils.getRegisteredService(), Optional.of(context), List.of(provider), (input, mfaProvider) -> input.equalsIgnoreCase(provider.getId()));
assertNotNull(results);
assertEquals(provider.getId(), results.iterator().next().getId());
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class CredentialMultifactorAuthenticationProviderBypassEvaluatorTests method verifyOperation.
@Test
public void verifyOperation() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val eval = new DefaultChainingMultifactorAuthenticationBypassProvider();
val bypassProps = new MultifactorAuthenticationProviderBypassProperties();
bypassProps.setCredentialClassType(UsernamePasswordCredential.class.getName());
eval.addMultifactorAuthenticationProviderBypassEvaluator(new CredentialMultifactorAuthenticationProviderBypassEvaluator(bypassProps, TestMultifactorAuthenticationProvider.ID));
val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("cn", List.of("example")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
val policy = new DefaultRegisteredServiceMultifactorPolicy();
when(registeredService.getMultifactorPolicy()).thenReturn(policy);
assertFalse(eval.shouldMultifactorAuthenticationProviderExecute(authentication, registeredService, provider, new MockHttpServletRequest()));
bypassProps.setCredentialClassType(BasicIdentifiableCredential.class.getName());
assertTrue(eval.shouldMultifactorAuthenticationProviderExecute(authentication, registeredService, provider, new MockHttpServletRequest()));
}
Aggregations