use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class DefaultMultifactorAuthenticationTriggerSelectionStrategyTests method getMultifactorAuthenticationTrigger.
private static MultifactorAuthenticationTrigger getMultifactorAuthenticationTrigger() {
val trigger = mock(MultifactorAuthenticationTrigger.class);
when(trigger.supports(any(), any(), any(), any())).thenReturn(true);
when(trigger.isActivated(any(), any(), any(), any(), any())).thenReturn(Optional.of(new TestMultifactorAuthenticationProvider()));
return trigger;
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class RestMultifactorAuthenticationProviderBypassEvaluatorTests method verifyOperationShouldProceed.
@Test
public void verifyOperationShouldProceed() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
try (val webServer = new MockWebServer(9316, new ByteArrayResource("Y".getBytes(StandardCharsets.UTF_8), "REST Output"), HttpStatus.ACCEPTED)) {
webServer.start();
val props = new MultifactorAuthenticationProviderBypassProperties();
props.getRest().setUrl("http://localhost:9316");
val provider = new TestMultifactorAuthenticationProvider();
val r = new RestMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
val res = r.shouldMultifactorAuthenticationProviderExecute(MultifactorAuthenticationTestUtils.getAuthentication("casuser"), MultifactorAuthenticationTestUtils.getRegisteredService(), provider, new MockHttpServletRequest());
assertTrue(res);
}
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class DefaultMultifactorAuthenticationFailureModeEvaluatorTests method executeEvaluation.
protected void executeEvaluation(final BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes providerMode, final BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes serviceMode, final BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes expected) {
val eval = new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties);
val provider = new TestMultifactorAuthenticationProvider();
provider.setFailureMode(providerMode);
val service = CoreAuthenticationTestUtils.getRegisteredService();
val policy = new DefaultRegisteredServiceMultifactorPolicy();
policy.setFailureMode(serviceMode);
when(service.getMultifactorPolicy()).thenReturn(policy);
val result = eval.evaluate(service, provider);
assertEquals(expected, result);
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderResolverTests method assertProviderResolutionFromManyProviders.
private static void assertProviderResolutionFromManyProviders(final MultifactorAuthenticationTrigger trigger, final ConfigurableApplicationContext applicationContext, final boolean assertPresence) {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val provider1 = new TestMultifactorAuthenticationProvider();
provider1.setOrder(10);
registerProviderInApplicationContext(applicationContext, context, provider1);
val provider2 = new TestMultifactorAuthenticationProvider("mfa-other");
provider2.setOrder(1);
registerProviderInApplicationContext(applicationContext, context, provider2);
val principal = CoreAuthenticationTestUtils.getPrincipal("casuser", CollectionUtils.wrap("mfa-principal", List.of(provider2.getId())));
val result = trigger.isActivated(CoreAuthenticationTestUtils.getAuthentication(principal, CollectionUtils.wrap("mfa-authn", List.of(provider2.getId()))), CoreAuthenticationTestUtils.getRegisteredService(), request, new MockHttpServletResponse(), CoreAuthenticationTestUtils.getService());
if (assertPresence) {
assertTrue(result.isPresent());
assertEquals(provider2.getId(), result.get().getId());
} else {
assertTrue(result.isEmpty());
}
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class RegisteredServicePrincipalAttributeMultifactorAuthenticationTriggerTests method verifyOperationByMultipleProviders.
@Test
public void verifyOperationByMultipleProviders() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val provider1 = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(appCtx);
val provider2 = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(appCtx, new TestMultifactorAuthenticationProvider("mfa-example"));
val policy = mock(RegisteredServiceMultifactorPolicy.class);
when(policy.getPrincipalAttributeNameTrigger()).thenReturn("email");
when(policy.getPrincipalAttributeValueToMatch()).thenReturn(".+@example.*");
when(policy.getMultifactorAuthenticationProviders()).thenReturn(Set.of(provider1.getId(), provider2.getId()));
when(registeredService.getMultifactorPolicy()).thenReturn(policy);
val props = new CasConfigurationProperties();
val selector = mock(MultifactorAuthenticationProviderSelector.class);
when(selector.resolve(any(Collection.class), any(), any())).thenReturn(provider2);
val trigger = new RegisteredServicePrincipalAttributeMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), appCtx, selector);
val result = trigger.isActivated(authentication, registeredService, httpRequest, this.httpResponse, mock(Service.class));
assertTrue(result.isPresent());
assertEquals(provider2.getId(), result.get().getId());
}
Aggregations