use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class RegisteredServicePrincipalAttributeMultifactorAuthenticationTriggerTests method verifyMismatchAttributes.
@Test
public void verifyMismatchAttributes() {
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();
val trigger = new RegisteredServicePrincipalAttributeMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext, mock(MultifactorAuthenticationProviderSelector.class));
val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
assertFalse(result.isPresent());
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class RegisteredServicePrincipalAttributeMultifactorAuthenticationTriggerTests method verifyOperationByProvider.
@Test
public void verifyOperationByProvider() {
val policy = mock(RegisteredServiceMultifactorPolicy.class);
when(policy.getPrincipalAttributeNameTrigger()).thenReturn("email");
when(policy.getPrincipalAttributeValueToMatch()).thenReturn(".+@example.*");
when(policy.getMultifactorAuthenticationProviders()).thenReturn(Set.of(TestMultifactorAuthenticationProvider.ID));
when(this.registeredService.getMultifactorPolicy()).thenReturn(policy);
val props = new CasConfigurationProperties();
val trigger = new RegisteredServicePrincipalAttributeMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext, mock(MultifactorAuthenticationProviderSelector.class));
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 AuthenticationAttributeMultifactorAuthenticationTriggerTests method verifyOperationByProvider.
@Test
@Order(1)
public void verifyOperationByProvider() {
val props = new CasConfigurationProperties();
val mfa = props.getAuthn().getMfa().getTriggers().getAuthentication();
mfa.setGlobalAuthenticationAttributeNameTriggers("category");
mfa.setGlobalAuthenticationAttributeValueRegex(".+object.*");
val trigger = new AuthenticationAttributeMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), 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 AuthenticationAttributeMultifactorAuthenticationTriggerTests method verifyNoMatch.
@Test
@Order(3)
public void verifyNoMatch() {
val props = new CasConfigurationProperties();
val mfa = props.getAuthn().getMfa().getTriggers().getAuthentication();
mfa.setGlobalAuthenticationAttributeNameTriggers("whatever");
mfa.setGlobalAuthenticationAttributeValueRegex("whatever");
val trigger = new AuthenticationAttributeMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext);
val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
assertTrue(result.isEmpty());
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class RestEndpointMultifactorAuthenticationTriggerTests method verifyNoProviders.
@Test
@Order(0)
@Tag("DisableProviderRegistration")
public void verifyNoProviders() {
val response = TestMultifactorAuthenticationProvider.ID.getBytes(StandardCharsets.UTF_8);
try (val webServer = new MockWebServer(9313, new ByteArrayResource(response, "Output"), HttpStatus.OK)) {
webServer.start();
val props = new CasConfigurationProperties();
props.getAuthn().getMfa().getTriggers().getRest().setUrl("http://localhost:9313");
val trigger = new RestEndpointMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext);
val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
assertTrue(result.isEmpty());
}
}
Aggregations