Search in sources :

Example 1 with DuoSecurityMultifactorAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties in project cas by apereo.

the class DuoSecurityPingEndpointTests method verifyOperation.

@Test
public void verifyOperation() {
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val duoService = mock(DuoSecurityAuthenticationService.class);
    when(duoService.ping()).thenReturn(true);
    val props = new DuoSecurityMultifactorAuthenticationProperties().setDuoApiHost("https://api.duosecurity.com");
    when(duoService.getProperties()).thenReturn(props);
    val bean = mock(DuoSecurityMultifactorAuthenticationProvider.class);
    when(bean.getId()).thenReturn(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
    when(bean.getDuoAuthenticationService()).thenReturn(duoService);
    when(bean.matches(eq(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER))).thenReturn(true);
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, bean, "duoProvider");
    val indicator = new DuoSecurityPingEndpoint(casProperties, this.applicationContext);
    val result = indicator.pingDuo(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
    assertNotNull(result);
    assertTrue(result.containsKey(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER));
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with DuoSecurityMultifactorAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties in project cas by apereo.

the class BasicDuoSecurityAuthenticationServiceTests method verifyPing.

@Test
public void verifyPing() throws Exception {
    var entity = MAPPER.writeValueAsString(Map.of("stat", "OK", "response", "pong"));
    try (val webServer = new MockWebServer(9310, new ByteArrayResource(entity.getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        val props = new DuoSecurityMultifactorAuthenticationProperties().setDuoApiHost("http://localhost:9310");
        val service = new BasicDuoSecurityAuthenticationService(props, httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
        assertTrue(service.ping());
    }
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with DuoSecurityMultifactorAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties in project cas by apereo.

the class BasicDuoSecurityAuthenticationServiceTests method verifyAccountStatusDisabled.

@Test
public void verifyAccountStatusDisabled() throws Exception {
    val props = new DuoSecurityMultifactorAuthenticationProperties();
    BeanUtils.copyProperties(props, casProperties.getAuthn().getMfa().getDuo().get(0));
    props.setAccountStatusEnabled(false);
    val service = new BasicDuoSecurityAuthenticationService(props, httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
    assertEquals(DuoSecurityUserAccountStatus.AUTH, service.getUserAccount("casuser").getStatus());
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with DuoSecurityMultifactorAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties in project cas by apereo.

the class DuoSecurityMultifactorWebflowConfigurer method doInitialize.

@Override
protected void doInitialize() {
    val duoConfig = casProperties.getAuthn().getMfa().getDuo();
    var flowRegistryBeans = duoConfig.stream().map(duo -> {
        val duoFlowRegistry = buildDuoFlowRegistry(duo);
        val duoFlowRegistryInstance = ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, duoFlowRegistry, duo.getId());
        return Pair.of(duo.getId(), duoFlowRegistryInstance);
    }).collect(Collectors.toList());
    val flowRegistries = flowRegistryBeans.stream().map(Pair::getValue).collect(Collectors.toList());
    getMultifactorAuthenticationFlowDefinitionRegistries().addAll(flowRegistries);
    flowRegistryBeans.forEach(duo -> registerMultifactorProviderAuthenticationWebflow(getLoginFlow(), duo.getKey(), duo.getKey()));
    duoConfig.stream().filter(DuoSecurityMultifactorAuthenticationProperties::isTrustedDeviceEnabled).forEach(duo -> {
        val id = duo.getId();
        LOGGER.debug("Activating multifactor trusted authentication for webflow [{}]", id);
        val registry = applicationContext.getBean(id, FlowDefinitionRegistry.class);
        registerMultifactorTrustedAuthentication(registry);
    });
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) DuoSecurityCredential(org.apereo.cas.adaptors.duo.authn.DuoSecurityCredential) TransitionModel(org.springframework.webflow.engine.model.TransitionModel) AbstractStateModel(org.springframework.webflow.engine.model.AbstractStateModel) FlowBuilderServices(org.springframework.webflow.engine.builder.support.FlowBuilderServices) BinderModel(org.springframework.webflow.engine.model.BinderModel) StringUtils(org.apache.commons.lang3.StringUtils) ActionStateModel(org.springframework.webflow.engine.model.ActionStateModel) ArrayList(java.util.ArrayList) FlowModelFlowBuilder(org.springframework.webflow.engine.builder.model.FlowModelFlowBuilder) AbstractActionModel(org.springframework.webflow.engine.model.AbstractActionModel) Pair(org.apache.commons.lang3.tuple.Pair) CasWebflowConstants(org.apereo.cas.web.flow.CasWebflowConstants) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BindingModel(org.springframework.webflow.engine.model.BindingModel) EvaluateModel(org.springframework.webflow.engine.model.EvaluateModel) LinkedList(java.util.LinkedList) AbstractMultifactorTrustedDeviceWebflowConfigurer(org.apereo.cas.trusted.web.flow.AbstractMultifactorTrustedDeviceWebflowConfigurer) ApplicationContextProvider(org.apereo.cas.util.spring.ApplicationContextProvider) DynamicFlowModelBuilder(org.apereo.cas.web.flow.configurer.DynamicFlowModelBuilder) DefaultFlowModelHolder(org.springframework.webflow.engine.model.builder.DefaultFlowModelHolder) FlowDefinitionRegistry(org.springframework.webflow.definition.registry.FlowDefinitionRegistry) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) lombok.val(lombok.val) Flow(org.springframework.webflow.engine.Flow) EndStateModel(org.springframework.webflow.engine.model.EndStateModel) Collectors(java.util.stream.Collectors) ViewStateModel(org.springframework.webflow.engine.model.ViewStateModel) FlowDefinitionRegistryBuilder(org.springframework.webflow.config.FlowDefinitionRegistryBuilder) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) CasMultifactorWebflowCustomizer(org.apereo.cas.web.flow.configurer.CasMultifactorWebflowCustomizer) Optional(java.util.Optional) VarModel(org.springframework.webflow.engine.model.VarModel)

Example 5 with DuoSecurityMultifactorAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties in project cas by apereo.

the class DefaultDuoSecurityAdminApiServiceTests method setup.

@BeforeEach
public void setup() {
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    properties = new DuoSecurityMultifactorAuthenticationProperties().setDuoApiHost("localhost:8443").setDuoAdminIntegrationKey(UUID.randomUUID().toString()).setDuoAdminSecretKey(UUID.randomUUID().toString());
    val duoService = new BasicDuoSecurityAuthenticationService(properties, httpClient, List.of(), Caffeine.newBuilder().build());
    val bean = mock(DuoSecurityMultifactorAuthenticationProvider.class);
    when(bean.getId()).thenReturn(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
    when(bean.getDuoAuthenticationService()).thenReturn(duoService);
    when(bean.matches(eq(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER))).thenReturn(true);
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, bean, "duoProvider");
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

lombok.val (lombok.val)12 DuoSecurityMultifactorAuthenticationProperties (org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties)12 Test (org.junit.jupiter.api.Test)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 HttpClient (org.apereo.cas.util.http.HttpClient)3 MockWebServer (org.apereo.cas.util.MockWebServer)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Http (com.duosecurity.client.Http)1 AccessDevice (com.duosecurity.model.AccessDevice)1 Application (com.duosecurity.model.Application)1 AuthContext (com.duosecurity.model.AuthContext)1 AuthDevice (com.duosecurity.model.AuthDevice)1 AuthResult (com.duosecurity.model.AuthResult)1 HealthCheckResponse (com.duosecurity.model.HealthCheckResponse)1 Location (com.duosecurity.model.Location)1 Token (com.duosecurity.model.Token)1 User (com.duosecurity.model.User)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1