Search in sources :

Example 6 with DuoSecurityMultifactorAuthenticationProperties

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

the class DuoSecurityHealthIndicatorTests method verifyOperation.

@Test
public void verifyOperation() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val props = new DuoSecurityMultifactorAuthenticationProperties().setDuoApiHost("https://api.duosecurity.com");
    val duoService = mock(DuoSecurityAuthenticationService.class);
    when(duoService.ping()).thenReturn(true);
    when(duoService.getProperties()).thenReturn(props);
    val bean = mock(DuoSecurityMultifactorAuthenticationProvider.class);
    when(bean.getId()).thenReturn(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
    when(bean.getDuoAuthenticationService()).thenReturn(duoService);
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, bean, "duoProvider");
    val indicator = new DuoSecurityHealthIndicator(applicationContext);
    val health = indicator.health();
    assertNotNull(health);
    assertEquals(health.getStatus(), Status.UP);
    assertTrue(health.getDetails().containsKey("duoApiHost"));
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

Example 7 with DuoSecurityMultifactorAuthenticationProperties

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

the class UniversalPromptDuoSecurityAuthenticationServiceTests method verifyPing.

@Test
public void verifyPing() throws Exception {
    val duoClient = mock(Client.class);
    when(duoClient.healthCheck()).thenReturn(new HealthCheckResponse());
    val duoProperties = new DuoSecurityMultifactorAuthenticationProperties();
    val service = new UniversalPromptDuoSecurityAuthenticationService(duoProperties, mock(HttpClient.class), duoClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
    assertTrue(service.getDuoClient().isPresent());
    assertTrue(service.ping());
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) HealthCheckResponse(com.duosecurity.model.HealthCheckResponse) HttpClient(org.apereo.cas.util.http.HttpClient) Test(org.junit.jupiter.api.Test)

Example 8 with DuoSecurityMultifactorAuthenticationProperties

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

the class UniversalPromptDuoSecurityAuthenticationServiceTests method verifyPingFails.

@Test
public void verifyPingFails() throws Exception {
    val duoClient = mock(Client.class);
    when(duoClient.healthCheck()).thenThrow(new RuntimeException());
    val duoProperties = new DuoSecurityMultifactorAuthenticationProperties();
    val service = new UniversalPromptDuoSecurityAuthenticationService(duoProperties, mock(HttpClient.class), duoClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
    assertTrue(service.getDuoClient().isPresent());
    assertFalse(service.ping());
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) HttpClient(org.apereo.cas.util.http.HttpClient) Test(org.junit.jupiter.api.Test)

Example 9 with DuoSecurityMultifactorAuthenticationProperties

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

the class UniversalPromptDuoSecurityAuthenticationServiceTests method verifyAuth.

@Test
public void verifyAuth() throws Exception {
    val state = UUID.randomUUID().toString();
    val credential = new DuoSecurityUniversalPromptCredential(state, RegisteredServiceTestUtils.getAuthentication("casuser"));
    val duoClient = mock(Client.class);
    val token = new Token();
    token.setAud("aud");
    token.setIat(123456D);
    token.setExp(123456);
    token.setAuth_time(123456789);
    token.setIss("issuer");
    token.setSub("casuser");
    token.setPreferred_username("CAS");
    val authContext = new AuthContext();
    val accessDevice = new AccessDevice();
    accessDevice.setLocation(new Location());
    accessDevice.setHostname("hostname");
    authContext.setAccess_device(accessDevice);
    val authDevice = new AuthDevice();
    authDevice.setLocation(new Location());
    authContext.setAuth_device(authDevice);
    authContext.setUser(new User());
    authContext.setApplication(new Application());
    token.setAuth_context(authContext);
    token.setAuth_result(new AuthResult());
    when(duoClient.exchangeAuthorizationCodeFor2FAResult(anyString(), anyString())).thenReturn(token);
    val duoProperties = new DuoSecurityMultifactorAuthenticationProperties();
    val service = new UniversalPromptDuoSecurityAuthenticationService(duoProperties, mock(HttpClient.class), duoClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
    val result = service.authenticate(credential);
    assertNotNull(result);
    assertTrue(result.isSuccess());
    assertEquals("CAS", result.getUsername());
    assertNotNull(result.getAttributes());
}
Also used : lombok.val(lombok.val) User(com.duosecurity.model.User) AuthContext(com.duosecurity.model.AuthContext) Token(com.duosecurity.model.Token) AuthResult(com.duosecurity.model.AuthResult) AccessDevice(com.duosecurity.model.AccessDevice) AuthDevice(com.duosecurity.model.AuthDevice) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) HttpClient(org.apereo.cas.util.http.HttpClient) Application(com.duosecurity.model.Application) Location(com.duosecurity.model.Location) Test(org.junit.jupiter.api.Test)

Example 10 with DuoSecurityMultifactorAuthenticationProperties

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

the class BasicDuoSecurityAuthenticationServiceTests method verifyPasscode.

@Test
public void verifyPasscode() throws Exception {
    val props = new DuoSecurityMultifactorAuthenticationProperties();
    BeanUtils.copyProperties(props, casProperties.getAuthn().getMfa().getDuo().get(0));
    props.setDuoApiHost("localhost:6342");
    val service = new BasicDuoSecurityAuthenticationService(props, httpClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build()) {

        private static final long serialVersionUID = 1756840642345094968L;

        @Override
        protected JSONObject executeDuoApiRequest(final Http request) {
            return new JSONObject(Map.of("stat", "OK", "result", "allow"));
        }
    };
    try (val webServer = new MockWebServer(6342)) {
        webServer.start();
        val creds = new DuoSecurityPasscodeCredential("casuser", "123456", "mfa-duo");
        assertTrue(service.authenticate(creds).isSuccess());
    }
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) JSONObject(org.json.JSONObject) MockWebServer(org.apereo.cas.util.MockWebServer) Http(com.duosecurity.client.Http) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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