use of org.apereo.cas.authentication.bypass.AuthenticationMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class MultifactorAuthenticationProviderBypassTests method verifyMultifactorAuthenticationBypassByAuthenticationHandler.
@Test
public void verifyMultifactorAuthenticationBypassByAuthenticationHandler() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val request = new MockHttpServletRequest();
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setAuthenticationHandlerName("SimpleAuthenticationHandler");
val principal = MultifactorAuthenticationTestUtils.getPrincipal("casuser", CollectionUtils.wrap("givenName", "CAS"));
val authentication = MultifactorAuthenticationTestUtils.getAuthentication(principal, CollectionUtils.wrap(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS, "SimpleAuthenticationHandler"));
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val bypass = new AuthenticationMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertFalse(bypass.shouldMultifactorAuthenticationProviderExecute(authentication, service, provider, request));
}
use of org.apereo.cas.authentication.bypass.AuthenticationMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class DefaultRequestedAuthenticationContextValidatorTests method verifyRequestedAuthenticationContextBypassed.
@Test
public void verifyRequestedAuthenticationContextBypassed() {
val applicationContext = buildApplicationContext();
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val props = MultifactorAuthenticationTestUtils.getAuthenticationBypassProperties();
val bypass = new AuthenticationMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
provider.setBypassEvaluator(bypass);
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, CollectionUtils.wrap(CASUSER, AUTH_ATTRIBUTES));
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.bypass.AuthenticationMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class DefaultRequestedAuthenticationContextValidatorTests method verifyRequestedAuthenticationIsAlreadyBypass.
@Test
public void verifyRequestedAuthenticationIsAlreadyBypass() {
val applicationContext = buildApplicationContext();
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setAuthenticationAttributeName("givenName");
props.setAuthenticationAttributeValue("Not Bypassed");
val bypass = new AuthenticationMultifactorAuthenticationProviderBypassEvaluator(props, TestMultifactorAuthenticationProvider.ID);
provider.setBypassEvaluator(bypass);
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 attrs = new HashMap<String, List<Object>>();
attrs.put(MultifactorAuthenticationProviderBypassEvaluator.AUTHENTICATION_ATTRIBUTE_BYPASS_MFA, List.of(true));
attrs.put(MultifactorAuthenticationProviderBypassEvaluator.AUTHENTICATION_ATTRIBUTE_BYPASS_MFA_PROVIDER, List.of(TestMultifactorAuthenticationProvider.ID));
val auth = MultifactorAuthenticationTestUtils.getAuthentication(principal, attrs);
when(assertion.getPrimaryAuthentication()).thenReturn(auth);
val result = validator.validateAuthenticationContext(assertion, new MockHttpServletRequest(), new MockHttpServletResponse());
assertTrue(result.isSuccess());
}
use of org.apereo.cas.authentication.bypass.AuthenticationMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class DefaultRequestedAuthenticationContextValidatorTests method verifyExecutionIgnoredPerService.
@Test
public void verifyExecutionIgnoredPerService() {
val applicationContext = buildApplicationContext();
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val props = MultifactorAuthenticationTestUtils.getAuthenticationBypassProperties();
val bypass = new AuthenticationMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
provider.setBypassEvaluator(bypass);
val servicesManager = mock(ServicesManager.class);
val validator = MultifactorAuthenticationTestUtils.mockRequestAuthnContextValidator(servicesManager, Optional.of(provider), applicationContext, BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.UNDEFINED.toString());
val mfaPolicy = mock(RegisteredServiceMultifactorPolicy.class);
when(mfaPolicy.isBypassEnabled()).thenReturn(true);
val service = MultifactorAuthenticationTestUtils.getService(UUID.randomUUID().toString());
val registeredService = MultifactorAuthenticationTestUtils.getRegisteredService(service.getId(), BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes.UNDEFINED.toString());
when(registeredService.getMultifactorPolicy()).thenReturn(mfaPolicy);
when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
val assertion = mock(Assertion.class);
when(assertion.getService()).thenReturn(service);
val principal = MultifactorAuthenticationTestUtils.getPrincipal(CASUSER, CollectionUtils.wrap(CASUSER, AUTH_ATTRIBUTES));
val auth = MultifactorAuthenticationTestUtils.getAuthentication(principal, AUTH_ATTRIBUTES);
when(assertion.getPrimaryAuthentication()).thenReturn(auth);
val result = validator.validateAuthenticationContext(assertion, new MockHttpServletRequest(), new MockHttpServletResponse());
assertTrue(result.isSuccess());
assertTrue(result.getContextId().isEmpty());
}
use of org.apereo.cas.authentication.bypass.AuthenticationMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class DefaultRequestedAuthenticationContextValidatorTests method verifyRequestedAuthenticationContextNotBypassed.
@Test
public void verifyRequestedAuthenticationContextNotBypassed() {
val applicationContext = buildApplicationContext();
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setAuthenticationAttributeName("givenName");
props.setAuthenticationAttributeValue("Not Bypassed");
val bypass = new AuthenticationMultifactorAuthenticationProviderBypassEvaluator(props, TestMultifactorAuthenticationProvider.ID);
provider.setBypassEvaluator(bypass);
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());
assertFalse(result.isSuccess());
}
Aggregations