use of org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider in project cas by apereo.
the class ChainingMultifactorAuthenticationProviderSelector method selectMultifactorAuthenticationProvider.
@Override
protected MultifactorAuthenticationProvider selectMultifactorAuthenticationProvider(final RegisteredService service, final List<MultifactorAuthenticationProvider> providers) {
if (providers.size() > 1) {
val provider = new DefaultChainingMultifactorAuthenticationProvider(failureModeEvaluator);
provider.addMultifactorAuthenticationProviders(providers);
return provider;
}
return super.selectMultifactorAuthenticationProvider(service, providers);
}
use of org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider in project cas by apereo.
the class DefaultMultifactorAuthenticationContextValidatorTests method verifyContextPassesValidationWithChainProvider.
@Test
public void verifyContextPassesValidationWithChainProvider() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val casProperties = new CasConfigurationProperties();
casProperties.getAuthn().getMfa().getCore().setGlobalFailureMode(BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.OPEN);
val failureEvaluator = new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties);
val chainProvider = new DefaultChainingMultifactorAuthenticationProvider(failureEvaluator);
val provider1 = new TestMultifactorAuthenticationProvider("mfa-first");
provider1.setOrder(10);
val provider2 = new TestMultifactorAuthenticationProvider("mfa-second");
provider2.setOrder(20);
chainProvider.addMultifactorAuthenticationProvider(provider1);
chainProvider.addMultifactorAuthenticationProvider(provider2);
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, chainProvider);
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider1);
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider2);
val v = new DefaultMultifactorAuthenticationContextValidator("authn_method", "trusted_authn", applicationContext);
val authentication = MultifactorAuthenticationTestUtils.getAuthentication(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), CollectionUtils.wrap("authn_method", List.of(provider2.getId())));
val result = v.validate(authentication, provider2.getId(), Optional.of(MultifactorAuthenticationTestUtils.getRegisteredService()));
assertTrue(result.isSuccess());
}
use of org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider in project cas by apereo.
the class ChainingMultifactorAuthenticationProviderSelectorTests method verifyMultipleProviders.
@Test
public void verifyMultipleProviders() {
val evaluator = mock(MultifactorAuthenticationFailureModeEvaluator.class);
val selector = new ChainingMultifactorAuthenticationProviderSelector(evaluator);
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val provider1 = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val provider2 = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val result = selector.resolve(List.of(provider1, provider2), RegisteredServiceTestUtils.getRegisteredService(), RegisteredServiceTestUtils.getPrincipal());
assertTrue(result instanceof DefaultChainingMultifactorAuthenticationProvider);
}
use of org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider in project cas by apereo.
the class PrepareMultifactorProviderSelectionActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val flowSession = new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN));
flowSession.setState(new ViewState(flowSession.getDefinitionInternal(), "viewState", mock(ViewFactory.class)));
val exec = new MockFlowExecutionContext(flowSession);
val context = new MockRequestContext(exec);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val chain = new DefaultChainingMultifactorAuthenticationProvider(new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties));
val provider = new TestMultifactorAuthenticationProvider();
provider.setBypassEvaluator(new DefaultChainingMultifactorAuthenticationBypassProvider());
chain.addMultifactorAuthenticationProvider(provider);
val attributes = new LocalAttributeMap(RegisteredService.class.getName(), RegisteredServiceTestUtils.getRegisteredService());
attributes.put(MultifactorAuthenticationProvider.class.getName(), chain);
val event = new EventFactorySupport().event(this, ChainingMultifactorAuthenticationProvider.DEFAULT_IDENTIFIER, attributes);
context.setCurrentEvent(event);
assertNull(action.execute(context));
assertNotNull(WebUtils.getSelectableMultifactorAuthenticationProviders(context));
}
use of org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider in project cas by apereo.
the class DefaultChainingMultifactorAuthenticationProviderTests method verifyOperation.
@Test
public void verifyOperation() {
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setHttpRequestHeaders("headerbypass");
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
provider.setBypassEvaluator(new HttpRequestMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId()));
val casProperties = new CasConfigurationProperties();
casProperties.getAuthn().getMfa().getCore().setGlobalFailureMode(BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.OPEN);
val failureEvaluator = new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties);
val p = new DefaultChainingMultifactorAuthenticationProvider(failureEvaluator);
p.addMultifactorAuthenticationProviders(provider);
assertNotNull(p.getBypassEvaluator());
assertNotNull(p.getId());
assertNotNull(p.getFriendlyName());
assertEquals(BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.NONE, p.getFailureMode());
assertFalse(p.getMultifactorAuthenticationProviders().isEmpty());
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertTrue(p.isAvailable(service));
assertTrue(p.matches(provider.getId()));
}
Aggregations