Search in sources :

Example 1 with DefaultMultifactorAuthenticationFailureModeEvaluator

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());
}
Also used : lombok.val(lombok.val) DefaultMultifactorAuthenticationContextValidator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultMultifactorAuthenticationFailureModeEvaluator

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());
}
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 3 with DefaultMultifactorAuthenticationFailureModeEvaluator

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));
}
Also used : lombok.val(lombok.val) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) RegisteredService(org.apereo.cas.services.RegisteredService) MockFlowSession(org.springframework.webflow.test.MockFlowSession) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ViewState(org.springframework.webflow.engine.ViewState) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MultifactorAuthenticationProvider(org.apereo.cas.authentication.MultifactorAuthenticationProvider) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) ChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.ChainingMultifactorAuthenticationProvider) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Flow(org.springframework.webflow.engine.Flow) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) DefaultChainingMultifactorAuthenticationBypassProvider(org.apereo.cas.authentication.bypass.DefaultChainingMultifactorAuthenticationBypassProvider) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultMultifactorAuthenticationFailureModeEvaluator

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());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator)

Example 5 with DefaultMultifactorAuthenticationFailureModeEvaluator

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()));
}
Also used : lombok.val(lombok.val) MultifactorAuthenticationProviderBypassProperties(org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) DefaultChainingMultifactorAuthenticationProvider(org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider) HttpRequestMultifactorAuthenticationProviderBypassEvaluator(org.apereo.cas.authentication.bypass.HttpRequestMultifactorAuthenticationProviderBypassEvaluator) DefaultMultifactorAuthenticationFailureModeEvaluator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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