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