Search in sources :

Example 11 with DevicePrint

use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.

the class DevicePrintServiceTest method shouldCreateNewProfileAndDeleteOlderOnes.

@Test
public void shouldCreateNewProfileAndDeleteOlderOnes() throws NotUniqueUserProfileException {
    //Given
    DevicePrint devicePrint = mock(DevicePrint.class);
    List<UserProfile> userProfiles = spy(new ArrayList<UserProfile>());
    UserProfile userProfileOne = mock(UserProfile.class);
    UserProfile userProfileTwo = mock(UserProfile.class);
    UserProfile userProfileThree = mock(UserProfile.class);
    userProfiles.add(userProfileOne);
    userProfiles.add(userProfileTwo);
    userProfiles.add(userProfileThree);
    given(userProfilesDao.getProfiles()).willReturn(userProfiles);
    given(userProfileOne.getLastSelectedDate()).willReturn(getDate(10));
    given(userProfileTwo.getLastSelectedDate()).willReturn(getDate(31));
    given(userProfileThree.getLastSelectedDate()).willReturn(getDate(30));
    //When
    devicePrintService.createNewProfile(devicePrint);
    //Then
    verify(userProfilesDao).removeProfile(anyString());
    verify(userProfiles).remove(userProfileTwo);
    verify(userProfiles).remove(userProfileThree);
    ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
    verify(userProfilesDao).addProfile(userProfileCaptor.capture());
    UserProfile userProfile = userProfileCaptor.getValue();
    assertEquals(userProfile.getDevicePrint(), devicePrint);
    verify(userProfilesDao).saveProfiles();
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 12 with DevicePrint

use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.

the class DevicePrintAuthenticationServiceTest method shouldAutoSaveProfilePageWhenSubmittedOTPWithCorrectCodeWithAuthSaveProp.

/**
     * 5a) third call, using OPT, 2 - OPT code submitted, with correct code - with Auth Save Profile prop set to "true"
     */
@Test
public void shouldAutoSaveProfilePageWhenSubmittedOTPWithCorrectCodeWithAuthSaveProp() throws AuthLoginException {
    //Given
    Callback[] callbacks = new Callback[2];
    PasswordCallback smsOTPCallback = mock(PasswordCallback.class);
    ConfirmationCallback confirmationCallback = mock(ConfirmationCallback.class);
    int state = 2;
    String otpCode = "OTPCODE";
    callbacks[0] = smsOTPCallback;
    callbacks[1] = confirmationCallback;
    given(smsOTPCallback.getPassword()).willReturn(otpCode.toCharArray());
    given(confirmationCallback.getSelectedIndex()).willReturn(0);
    given(hotpService.isValidHOTP("OTPCODE")).willReturn(true);
    given(devicePrintService.hasRequiredAttributes(Matchers.<DevicePrint>anyObject())).willReturn(true);
    given(devicePrintAuthenticationConfig.getBoolean(DevicePrintAuthenticationConfig.AUTO_STORE_PROFILES)).willReturn(true);
    //When
    int nextState = devicePrintAuthenticationService.process(callbacks, state);
    //Then
    assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
    verify(devicePrintService).createNewProfile(Matchers.<DevicePrint>anyObject());
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 13 with DevicePrint

use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.

the class DevicePrintAuthenticationServiceTest method shouldNotSaveProfileIfRequiredAttributesNotSet.

@Test
public void shouldNotSaveProfileIfRequiredAttributesNotSet() throws AuthLoginException {
    //Given
    Callback[] callbacks = new Callback[2];
    PasswordCallback smsOTPCallback = mock(PasswordCallback.class);
    ConfirmationCallback confirmationCallback = mock(ConfirmationCallback.class);
    int state = 2;
    String otpCode = "OTPCODE";
    callbacks[0] = smsOTPCallback;
    callbacks[1] = confirmationCallback;
    given(smsOTPCallback.getPassword()).willReturn(otpCode.toCharArray());
    given(confirmationCallback.getSelectedIndex()).willReturn(0);
    given(hotpService.isValidHOTP("OTPCODE")).willReturn(true);
    given(devicePrintService.hasRequiredAttributes(Matchers.<DevicePrint>anyObject())).willReturn(false);
    given(devicePrintAuthenticationConfig.getBoolean(DevicePrintAuthenticationConfig.AUTO_STORE_PROFILES)).willReturn(true);
    //When
    int nextState = devicePrintAuthenticationService.process(callbacks, state);
    //Then
    assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
    verify(devicePrintService, never()).createNewProfile(Matchers.<DevicePrint>anyObject());
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 14 with DevicePrint

use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.

the class DevicePrintAuthenticationServiceTest method shouldSendOTPWhenDevicePrintInfoNotSufficient.

/*

    1) first call ISAuthConstants.LOGIN_START - device print attr populated, device print info not sufficient - should return ISAuthConstants.LOGIN_SUCCEED
    2) first call ISAuthConstants.LOGIN_START - device print attr populated, with invalid stored profiles using OTP - should return 2
    3) first call ISAuthConstants.LOGIN_START - device print attr populated, with a valid stored profile - should return ISAuthConstants.LOGIN_SUCCEED

    4) second call, using OPT, 2 - request OPT to be sent - should return 2
    5) third call, using OPT, 2 - OPT code submitted, with correct code - should return 3
    6) third call, using OPT, 2 - OPT code submitted, with incorrect code - should throw exception

    7) fourth call, 3 - don't save profile - should return ISAuthConstants.LOGIN_SUCCEED, with no profile saved
    8) fourth call, 3 - save profile, having no valid previous profiles - should create new profile, return ISAuthConstants.LOGIN_SUCCEED
    9) fourth call, 3 - save profile, having a valid previous profile - should update previous profile, return ISAuthConstants.LOGIN_SUCCEED

     */
/**
     * 1) first call ISAuthConstants.LOGIN_START - device print attr populated, device print info not sufficient - should return 2 (SEND_OPT)
     */
@Test
public void shouldSendOTPWhenDevicePrintInfoNotSufficient() throws AuthLoginException {
    //Given
    Callback[] callbacks = new Callback[1];
    NameCallback devicePrintCallback = mock(NameCallback.class);
    int state = ISAuthConstants.LOGIN_START;
    DevicePrint devicePrint = mock(DevicePrint.class);
    callbacks[0] = devicePrintCallback;
    given(devicePrintCallback.getName()).willReturn("DEVICE_PRINT_INFO");
    given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
    given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(false);
    //When
    int nextState = devicePrintAuthenticationService.process(callbacks, state);
    //Then
    assertEquals(nextState, 2);
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 15 with DevicePrint

use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.

the class DevicePrintServiceTest method shouldCreateNewProfile.

@Test
public void shouldCreateNewProfile() throws NotUniqueUserProfileException {
    //Given
    DevicePrint devicePrint = mock(DevicePrint.class);
    given(userProfilesDao.getProfiles()).willReturn(new ArrayList<UserProfile>());
    //When
    devicePrintService.createNewProfile(devicePrint);
    //Then
    verify(userProfilesDao).removeProfile(anyString());
    ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
    verify(userProfilesDao).addProfile(userProfileCaptor.capture());
    UserProfile userProfile = userProfileCaptor.getValue();
    assertEquals(userProfile.getDevicePrint(), devicePrint);
    verify(userProfilesDao).saveProfiles();
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Aggregations

DevicePrint (org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint)23 Test (org.testng.annotations.Test)20 UserProfile (org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile)10 Callback (javax.security.auth.callback.Callback)8 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)8 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)8 NameCallback (javax.security.auth.callback.NameCallback)8 PasswordCallback (javax.security.auth.callback.PasswordCallback)8 ArrayList (java.util.ArrayList)2 ComparisonResult (org.forgerock.openam.authentication.modules.deviceprint.comparators.ComparisonResult)2 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DevicePrintAuthenticationConfig (org.forgerock.openam.authentication.modules.deviceprint.DevicePrintAuthenticationConfig)1 Extractor (org.forgerock.openam.authentication.modules.deviceprint.extractors.Extractor)1