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