Search in sources :

Example 6 with DefaultMultifactorAuthenticationProviderResolver

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());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MultifactorAuthenticationProviderSelector(org.apereo.cas.authentication.MultifactorAuthenticationProviderSelector) Service(org.apereo.cas.authentication.principal.Service) DefaultMultifactorAuthenticationProviderResolver(org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultMultifactorAuthenticationProviderResolver

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());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MultifactorAuthenticationProviderSelector(org.apereo.cas.authentication.MultifactorAuthenticationProviderSelector) Service(org.apereo.cas.authentication.principal.Service) DefaultMultifactorAuthenticationProviderResolver(org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver) Test(org.junit.jupiter.api.Test)

Example 8 with DefaultMultifactorAuthenticationProviderResolver

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());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Service(org.apereo.cas.authentication.principal.Service) DefaultMultifactorAuthenticationProviderResolver(org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultMultifactorAuthenticationProviderResolver

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());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Service(org.apereo.cas.authentication.principal.Service) DefaultMultifactorAuthenticationProviderResolver(org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 10 with DefaultMultifactorAuthenticationProviderResolver

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());
    }
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MockWebServer(org.apereo.cas.util.MockWebServer) Service(org.apereo.cas.authentication.principal.Service) DefaultMultifactorAuthenticationProviderResolver(org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver) ByteArrayResource(org.springframework.core.io.ByteArrayResource) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

lombok.val (lombok.val)14 DefaultMultifactorAuthenticationProviderResolver (org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver)14 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)14 Test (org.junit.jupiter.api.Test)14 Service (org.apereo.cas.authentication.principal.Service)12 Order (org.junit.jupiter.api.Order)7 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)7 MultifactorAuthenticationProviderSelector (org.apereo.cas.authentication.MultifactorAuthenticationProviderSelector)4 MockWebServer (org.apereo.cas.util.MockWebServer)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 TestMultifactorAuthenticationProvider (org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider)2 Collection (java.util.Collection)1 Tag (org.junit.jupiter.api.Tag)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1