use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class PrincipalAttributeMultifactorAuthenticationTriggerTests method verifyDenyWhenUnmatched.
@Test
public void verifyDenyWhenUnmatched() {
val props = new CasConfigurationProperties();
val principal = props.getAuthn().getMfa().getTriggers().getPrincipal();
principal.setGlobalPrincipalAttributeNameTriggers("email");
principal.setGlobalPrincipalAttributeValueRegex("-nothing-");
principal.setDenyIfUnmatched(true);
val resolver = new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical());
val trigger = new PrincipalAttributeMultifactorAuthenticationTrigger(props, resolver, applicationContext);
val e = assertThrows(AuthenticationException.class, () -> trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class)));
assertNotNull(e.getCode());
assertTrue(e.getHandlerErrors().containsKey(MultifactorAuthenticationRequiredException.class.getSimpleName()));
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class PrincipalAttributeMultifactorAuthenticationTriggerTests method verifyOperationByProvider.
@Test
public void verifyOperationByProvider() {
val props = new CasConfigurationProperties();
val principal = props.getAuthn().getMfa().getTriggers().getPrincipal();
principal.setGlobalPrincipalAttributeNameTriggers("email");
principal.setGlobalPrincipalAttributeValueRegex(".+@example.*");
val resolver = new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical());
val trigger = new PrincipalAttributeMultifactorAuthenticationTrigger(props, resolver, applicationContext);
val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
assertTrue(result.isPresent());
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class RegisteredServicePrincipalAttributeMultifactorAuthenticationTriggerTests method verifyMismatchAttributesMustDeny.
@Test
public void verifyMismatchAttributesMustDeny() {
val policy = mock(RegisteredServiceMultifactorPolicy.class);
when(policy.getPrincipalAttributeNameTrigger()).thenReturn("bad-attribute");
when(policy.getPrincipalAttributeValueToMatch()).thenReturn(".+@example.*");
when(policy.getMultifactorAuthenticationProviders()).thenReturn(Set.of(TestMultifactorAuthenticationProvider.ID));
when(this.registeredService.getMultifactorPolicy()).thenReturn(policy);
val props = new CasConfigurationProperties();
props.getAuthn().getMfa().getTriggers().getPrincipal().setDenyIfUnmatched(true);
val trigger = new RegisteredServicePrincipalAttributeMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext, mock(MultifactorAuthenticationProviderSelector.class));
assertThrows(AuthenticationException.class, () -> trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class)));
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class RegisteredServicePrincipalAttributeMultifactorAuthenticationTriggerTests method verifyOperationByMultipleProviders.
@Test
public void verifyOperationByMultipleProviders() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val provider1 = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(appCtx);
val provider2 = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(appCtx, new TestMultifactorAuthenticationProvider("mfa-example"));
val policy = mock(RegisteredServiceMultifactorPolicy.class);
when(policy.getPrincipalAttributeNameTrigger()).thenReturn("email");
when(policy.getPrincipalAttributeValueToMatch()).thenReturn(".+@example.*");
when(policy.getMultifactorAuthenticationProviders()).thenReturn(Set.of(provider1.getId(), provider2.getId()));
when(registeredService.getMultifactorPolicy()).thenReturn(policy);
val props = new CasConfigurationProperties();
val selector = mock(MultifactorAuthenticationProviderSelector.class);
when(selector.resolve(any(Collection.class), any(), any())).thenReturn(provider2);
val trigger = new RegisteredServicePrincipalAttributeMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), appCtx, selector);
val result = trigger.isActivated(authentication, registeredService, httpRequest, this.httpResponse, mock(Service.class));
assertTrue(result.isPresent());
assertEquals(provider2.getId(), result.get().getId());
}
Aggregations