Search in sources :

Example 6 with DefaultMultifactorAuthenticationFailureModeEvaluator

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

the class DefaultRequestedAuthenticationContextValidatorTests method verifyGlobalFailureModeFailsOpen.

@Test
public void verifyGlobalFailureModeFailsOpen() {
    val applicationContext = buildApplicationContext();
    val provider = TestUnavailableMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val casProperties = new CasConfigurationProperties();
    casProperties.getAuthn().getMfa().getCore().setGlobalFailureMode(BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.OPEN);
    val failureEvaluator = new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties);
    provider.setFailureModeEvaluator(failureEvaluator);
    val servicesManager = mock(ServicesManager.class);
    val validator = MultifactorAuthenticationTestUtils.mockRequestAuthnContextValidator(servicesManager, Optional.of(provider), applicationContext, BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.UNDEFINED.toString());
    val assertion = mock(Assertion.class);
    val principal = MultifactorAuthenticationTestUtils.getPrincipal(CASUSER);
    val auth = MultifactorAuthenticationTestUtils.getAuthentication(principal, AUTH_ATTRIBUTES);
    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) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultMultifactorAuthenticationFailureModeEvaluator

use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator 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)

Example 8 with DefaultMultifactorAuthenticationFailureModeEvaluator

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

the class DefaultRequestedAuthenticationContextValidatorTests method verifyGlobalFailureModeFailsClosed.

@Test
public void verifyGlobalFailureModeFailsClosed() {
    val applicationContext = buildApplicationContext();
    TestUnavailableMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val provider = MultifactorAuthenticationUtils.getMultifactorAuthenticationProviderById(TestUnavailableMultifactorAuthenticationProvider.ID, applicationContext);
    val casProperties = new CasConfigurationProperties();
    casProperties.getAuthn().getMfa().getCore().setGlobalFailureMode(BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.CLOSED);
    val failureEvaluator = new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties);
    ((TestUnavailableMultifactorAuthenticationProvider) provider.get()).setFailureModeEvaluator(failureEvaluator);
    val servicesManager = mock(ServicesManager.class);
    val validator = MultifactorAuthenticationTestUtils.mockRequestAuthnContextValidator(servicesManager, Optional.of(new TestMultifactorAuthenticationProvider()), applicationContext, BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.UNDEFINED.toString());
    val assertion = mock(Assertion.class);
    val principal = MultifactorAuthenticationTestUtils.getPrincipal(CASUSER);
    val auth = MultifactorAuthenticationTestUtils.getAuthentication(principal, AUTH_ATTRIBUTES);
    when(assertion.getPrimaryAuthentication()).thenReturn(auth);
    val result = validator.validateAuthenticationContext(assertion, new MockHttpServletRequest(), new MockHttpServletResponse());
    assertFalse(result.isSuccess());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultMultifactorAuthenticationFailureModeEvaluator

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

the class DefaultRequestedAuthenticationContextValidatorTests method verifyServiceFailureModeFailsOpen.

@Test
public void verifyServiceFailureModeFailsOpen() {
    val applicationContext = buildApplicationContext();
    val provider = TestUnavailableMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val casProperties = new CasConfigurationProperties();
    casProperties.getAuthn().getMfa().getCore().setGlobalFailureMode(BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.CLOSED);
    val failureEvaluator = new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties);
    provider.setFailureModeEvaluator(failureEvaluator);
    val servicesManager = mock(ServicesManager.class);
    val validator = MultifactorAuthenticationTestUtils.mockRequestAuthnContextValidator(servicesManager, Optional.of(provider), applicationContext, BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.OPEN.toString());
    val assertion = mock(Assertion.class);
    val service = MultifactorAuthenticationTestUtils.getService("service");
    when(assertion.getService()).thenReturn(service);
    val principal = MultifactorAuthenticationTestUtils.getPrincipal(CASUSER);
    val auth = MultifactorAuthenticationTestUtils.getAuthentication(principal, AUTH_ATTRIBUTES);
    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) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)9 DefaultMultifactorAuthenticationFailureModeEvaluator (org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator)9 Test (org.junit.jupiter.api.Test)8 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 DefaultChainingMultifactorAuthenticationProvider (org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider)4 MockServletContext (org.springframework.mock.web.MockServletContext)2 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)2 MockRequestContext (org.springframework.webflow.test.MockRequestContext)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 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1