use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator 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());
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator in project cas by apereo.
the class DefaultRequestedAuthenticationContextValidatorTests method verifyServiceFailureModeFailsClosed.
@Test
public void verifyServiceFailureModeFailsClosed() {
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.CLOSED.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());
assertFalse(result.isSuccess());
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator 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));
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator in project cas by apereo.
the class MultifactorAuthenticationFailureActionTests method executeAction.
protected void executeAction(final BaseMultifactorAuthenticationProviderProperties.MultifactorAuthenticationProviderFailureModes mode, final String transitionId) throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
provider.setFailureMode(mode);
provider.setFailureModeEvaluator(new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties));
val service = RegisteredServiceTestUtils.getRegisteredService();
servicesManager.save(service);
WebUtils.putRegisteredService(context, service);
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, provider);
val event = mfaFailureAction.execute(context);
assertEquals(transitionId, event.getId());
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator 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()));
}
Aggregations