use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class AuthenticationAttributeMultifactorAuthenticationTriggerTests method verifyMultipleProvider.
@Test
@Order(2)
public void verifyMultipleProvider() {
val otherProvider = new TestMultifactorAuthenticationProvider();
otherProvider.setId("mfa-other");
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, otherProvider);
val props = new CasConfigurationProperties();
val mfa = props.getAuthn().getMfa().getTriggers().getAuthentication();
mfa.setGlobalAuthenticationAttributeNameTriggers("mfa-mode");
mfa.setGlobalAuthenticationAttributeValueRegex(otherProvider.getId());
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 RestEndpointMultifactorAuthenticationTriggerTests method verifyNoProvider.
@Test
@Order(3)
public void verifyNoProvider() {
val props = new CasConfigurationProperties();
val trigger = new RestEndpointMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext);
var result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
assertTrue(result.isEmpty());
props.getAuthn().getMfa().getTriggers().getRest().setUrl("http://localhost:9313");
result = trigger.isActivated(null, null, 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 verifyOperationByProvider.
@Test
@Order(1)
public void verifyOperationByProvider() {
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.isPresent());
}
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class RestEndpointMultifactorAuthenticationTriggerTests method verifyFailProvider.
@Test
@Order(2)
public void verifyFailProvider() {
val response = TestMultifactorAuthenticationProvider.ID.getBytes(StandardCharsets.UTF_8);
try (val webServer = new MockWebServer(9313, new ByteArrayResource(response, "Output"), HttpStatus.UNAUTHORIZED)) {
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());
}
}
use of org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver in project cas by apereo.
the class RegisteredServicePrincipalAttributeMultifactorAuthenticationTriggerTests method verifyPolicyNoAttributes.
@Test
public void verifyPolicyNoAttributes() {
val policy = mock(RegisteredServiceMultifactorPolicy.class);
when(policy.getPrincipalAttributeNameTrigger()).thenReturn("email");
when(policy.getPrincipalAttributeValueToMatch()).thenReturn(StringUtils.EMPTY);
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.isEmpty());
}
Aggregations