Search in sources :

Example 1 with DefaultChainingMultifactorAuthenticationProvider

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);
}
Also used : lombok.val(lombok.val) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider)

Example 2 with DefaultChainingMultifactorAuthenticationProvider

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());
}
Also used : lombok.val(lombok.val) DefaultMultifactorAuthenticationContextValidator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultChainingMultifactorAuthenticationProvider

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);
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) Test(org.junit.jupiter.api.Test)

Example 4 with 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));
}
Also used : lombok.val(lombok.val) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) RegisteredService(org.apereo.cas.services.RegisteredService) MockFlowSession(org.springframework.webflow.test.MockFlowSession) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ViewState(org.springframework.webflow.engine.ViewState) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MultifactorAuthenticationProvider(org.apereo.cas.authentication.MultifactorAuthenticationProvider) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) ChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.ChainingMultifactorAuthenticationProvider) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Flow(org.springframework.webflow.engine.Flow) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) DefaultChainingMultifactorAuthenticationBypassProvider(org.apereo.cas.authentication.bypass.DefaultChainingMultifactorAuthenticationBypassProvider) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultChainingMultifactorAuthenticationProvider

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()));
}
Also used : lombok.val(lombok.val) MultifactorAuthenticationProviderBypassProperties(org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) HttpRequestMultifactorAuthenticationProviderBypassEvaluator(org.apereo.cas.authentication.bypass.HttpRequestMultifactorAuthenticationProviderBypassEvaluator) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)6 DefaultChainingMultifactorAuthenticationProvider (org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider)6 Test (org.junit.jupiter.api.Test)5 DefaultMultifactorAuthenticationFailureModeEvaluator (org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator)4 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)3 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 ChainingMultifactorAuthenticationProvider (org.apereo.cas.authentication.ChainingMultifactorAuthenticationProvider)1 DefaultMultifactorAuthenticationContextValidator (org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator)1 MultifactorAuthenticationProvider (org.apereo.cas.authentication.MultifactorAuthenticationProvider)1 DefaultChainingMultifactorAuthenticationBypassProvider (org.apereo.cas.authentication.bypass.DefaultChainingMultifactorAuthenticationBypassProvider)1 HttpRequestMultifactorAuthenticationProviderBypassEvaluator (org.apereo.cas.authentication.bypass.HttpRequestMultifactorAuthenticationProviderBypassEvaluator)1 TestMultifactorAuthenticationProvider (org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider)1 MultifactorAuthenticationProviderBypassProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1