Search in sources :

Example 1 with User

use of com.duosecurity.model.User 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)

Aggregations

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 Location (com.duosecurity.model.Location)1 Token (com.duosecurity.model.Token)1 User (com.duosecurity.model.User)1 lombok.val (lombok.val)1 DuoSecurityMultifactorAuthenticationProperties (org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties)1 HttpClient (org.apereo.cas.util.http.HttpClient)1 Test (org.junit.jupiter.api.Test)1