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());
}
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());
}
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());
}
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());
}
Aggregations