Search in sources :

Example 1 with DefaultMultifactorAuthenticationContextValidator

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

the class DefaultMultifactorAuthenticationContextValidatorTests method verifyContextPassesValidationWithProvider.

@Test
public void verifyContextPassesValidationWithProvider() {
    val applicationContext = getStaticApplicationContext();
    val v = new DefaultMultifactorAuthenticationContextValidator("authn_method", "trusted_authn", applicationContext);
    val authentication = MultifactorAuthenticationTestUtils.getAuthentication(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), CollectionUtils.wrap("authn_method", List.of("mfa-dummy")));
    val result = v.validate(authentication, "mfa-dummy", Optional.of(MultifactorAuthenticationTestUtils.getRegisteredService()));
    assertTrue(result.isSuccess());
}
Also used : lombok.val(lombok.val) DefaultMultifactorAuthenticationContextValidator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultMultifactorAuthenticationContextValidator

use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator 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 3 with DefaultMultifactorAuthenticationContextValidator

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

the class DefaultMultifactorAuthenticationContextValidatorTests method verifyTrustedAuthnFoundFromContext.

@Test
public void verifyTrustedAuthnFoundFromContext() {
    val applicationContext = getStaticApplicationContext();
    val v = new DefaultMultifactorAuthenticationContextValidator("authn_method", "trusted_authn", applicationContext);
    val authentication = MultifactorAuthenticationTestUtils.getAuthentication(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), CollectionUtils.wrap("authn_method", List.of("mfa-other")));
    var result = v.validate(authentication, "mfa-dummy", Optional.of(MultifactorAuthenticationTestUtils.getRegisteredService()));
    assertFalse(result.isSuccess());
    val otherProvider = new TestMultifactorAuthenticationProvider();
    otherProvider.setId("mfa-other");
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, otherProvider);
    result = v.validate(authentication, "mfa-dummy", Optional.of(MultifactorAuthenticationTestUtils.getRegisteredService()));
    assertTrue(result.isSuccess());
}
Also used : lombok.val(lombok.val) DefaultMultifactorAuthenticationContextValidator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultMultifactorAuthenticationContextValidator

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

the class MultifactorAuthenticationTestUtils method mockRequestAuthnContextValidator.

public static RequestedAuthenticationContextValidator mockRequestAuthnContextValidator(final ServicesManager servicesManager, final Optional<MultifactorAuthenticationProvider> provider, final ConfigurableApplicationContext applicationContext, final String failureMode) {
    val multifactorTrigger = mock(MultifactorAuthenticationTriggerSelectionStrategy.class);
    val service = MultifactorAuthenticationTestUtils.getRegisteredService("https://www.github.com/apereo/cas", failureMode);
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(service);
    when(multifactorTrigger.resolve(any(), any(), any(), any(), any())).thenReturn(provider);
    val multifactorContextValidator = new DefaultMultifactorAuthenticationContextValidator("authn_method", "trusted_authn", applicationContext);
    return new DefaultRequestedAuthenticationContextValidator(servicesManager, multifactorTrigger, multifactorContextValidator);
}
Also used : lombok.val(lombok.val) DefaultMultifactorAuthenticationContextValidator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator) DefaultRequestedAuthenticationContextValidator(org.apereo.cas.authentication.DefaultRequestedAuthenticationContextValidator) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Example 5 with DefaultMultifactorAuthenticationContextValidator

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

the class DefaultMultifactorAuthenticationContextValidatorTests method verifyTrustedAuthnFoundInContext.

@Test
public void verifyTrustedAuthnFoundInContext() {
    val applicationContext = getStaticApplicationContext();
    val v = new DefaultMultifactorAuthenticationContextValidator("authn_method", "trusted_authn", applicationContext);
    val authentication = MultifactorAuthenticationTestUtils.getAuthentication(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), CollectionUtils.wrap("authn_method", List.of("mfa-other"), "trusted_authn", List.of("mfa-dummy")));
    val result = v.validate(authentication, "mfa-dummy", Optional.of(MultifactorAuthenticationTestUtils.getRegisteredService()));
    assertTrue(result.isSuccess());
}
Also used : lombok.val(lombok.val) DefaultMultifactorAuthenticationContextValidator(org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)7 DefaultMultifactorAuthenticationContextValidator (org.apereo.cas.authentication.DefaultMultifactorAuthenticationContextValidator)7 Test (org.junit.jupiter.api.Test)6 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)2 DefaultChainingMultifactorAuthenticationProvider (org.apereo.cas.authentication.DefaultChainingMultifactorAuthenticationProvider)1 DefaultMultifactorAuthenticationFailureModeEvaluator (org.apereo.cas.authentication.DefaultMultifactorAuthenticationFailureModeEvaluator)1 DefaultRequestedAuthenticationContextValidator (org.apereo.cas.authentication.DefaultRequestedAuthenticationContextValidator)1 Service (org.apereo.cas.authentication.principal.Service)1 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 RegisteredService (org.apereo.cas.services.RegisteredService)1