Search in sources :

Example 1 with DefaultMultifactorAuthenticationProviderResolver

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());
}
Also used : lombok.val(lombok.val) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) 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 2 with DefaultMultifactorAuthenticationProviderResolver

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());
}
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 3 with DefaultMultifactorAuthenticationProviderResolver

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

Example 4 with DefaultMultifactorAuthenticationProviderResolver

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

Example 5 with DefaultMultifactorAuthenticationProviderResolver

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

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