Search in sources :

Example 6 with DefaultChainingMultifactorAuthenticationProvider

use of org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider in project cas by apereo.

the class DefaultRequestedAuthenticationContextValidatorTests method verifyRequestedAuthenticationContextChained.

@Test
public void verifyRequestedAuthenticationContextChained() {
    val applicationContext = buildApplicationContext();
    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");
    val provider2 = new TestMultifactorAuthenticationProvider("mfa-second");
    chainProvider.addMultifactorAuthenticationProvider(provider1);
    chainProvider.addMultifactorAuthenticationProvider(provider2);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider1);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider2);
    val servicesManager = mock(ServicesManager.class);
    val validator = MultifactorAuthenticationTestUtils.mockRequestAuthnContextValidator(servicesManager, Optional.of(chainProvider), applicationContext, BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.UNDEFINED.toString());
    val assertion = mock(Assertion.class);
    val principal = MultifactorAuthenticationTestUtils.getPrincipal(CASUSER, CollectionUtils.wrap(CASUSER, AUTH_ATTRIBUTES));
    val auth = MultifactorAuthenticationTestUtils.getAuthentication(principal, AUTH_ATTRIBUTES);
    auth.getAttributes().put("authn_method", List.of(provider2.getId()));
    when(assertion.getPrimaryAuthentication()).thenReturn(auth);
    val result = validator.validateAuthenticationContext(assertion, new MockHttpServletRequest(), new MockHttpServletResponse());
    assertTrue(result.isSuccess());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) Test(org.junit.jupiter.api.Test)

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