Search in sources :

Example 6 with UserProfile

use of org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile 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 7 with UserProfile

use of org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile 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)

Example 8 with UserProfile

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

the class DevicePrintAuthenticationServiceTest method shouldUpdateUserProfileWhenHasValidPreviousProfile.

/**
     * 9) fourth call, 3 - save profile, having a valid previous profile - should update previous profile, return ISAuthConstants.LOGIN_SUCCEED
     */
@Test
public void shouldUpdateUserProfileWhenHasValidPreviousProfile() throws AuthLoginException {
    //Given
    NameCallback devicePrintCallback = mock(NameCallback.class);
    Callback[] callbacks = new Callback[] { devicePrintCallback };
    int state = ISAuthConstants.LOGIN_START;
    DevicePrint devicePrint = mock(DevicePrint.class);
    UserProfile validStoredMatchingProfile = mock(UserProfile.class);
    UserProfile selectedUserProfile = validStoredMatchingProfile;
    given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
    given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(true);
    given(devicePrintService.getBestMatchingUserProfile(devicePrint)).willReturn(selectedUserProfile);
    //When
    int nextState = devicePrintAuthenticationService.process(callbacks, state);
    //Then
    verify(devicePrintService).updateProfile(selectedUserProfile, devicePrint);
    assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) 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) UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 9 with UserProfile

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

the class DevicePrintServiceTest method shouldUpdateProfile.

@Test
public void shouldUpdateProfile() throws NotUniqueUserProfileException {
    //Given
    UserProfile userProfile = mock(UserProfile.class);
    DevicePrint devicePrint = mock(DevicePrint.class);
    given(userProfile.getUuid()).willReturn("USER_PROFILE_UUID");
    given(userProfilesDao.getProfiles()).willReturn(new ArrayList<UserProfile>());
    //When
    devicePrintService.updateProfile(userProfile, devicePrint);
    //Then
    verify(userProfile).setSelectionCounter(anyLong());
    verify(userProfile).setLastSelectedDate(Matchers.<Date>anyObject());
    verify(userProfile).setDevicePrint(devicePrint);
    verify(userProfilesDao).removeProfile(anyString());
    verify(userProfilesDao).addProfile(userProfile);
    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 10 with UserProfile

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

the class DevicePrintAuthenticationServiceTest method shouldGotoOTPStateWhenNoValidMatchingStoredDevicePrintProfilesFound.

/**
     * 2) first call ISAuthConstants.LOGIN_START - device print attr populated, with invalid stored profiles using SMS_OTP - should return 2
     */
@Test
public void shouldGotoOTPStateWhenNoValidMatchingStoredDevicePrintProfilesFound() throws AuthLoginException {
    //Given
    Callback[] callbacks = new Callback[1];
    NameCallback devicePrintCallback = mock(NameCallback.class);
    int state = ISAuthConstants.LOGIN_START;
    DevicePrint devicePrint = mock(DevicePrint.class);
    UserProfile selectedUserProfile = null;
    callbacks[0] = devicePrintCallback;
    given(devicePrintCallback.getName()).willReturn("DEVICE_PRINT_INFO");
    given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
    given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(true);
    given(devicePrintService.getBestMatchingUserProfile(devicePrint)).willReturn(selectedUserProfile);
    //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) UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Aggregations

UserProfile (org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile)13 DevicePrint (org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint)10 Test (org.testng.annotations.Test)8 Callback (javax.security.auth.callback.Callback)3 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)3 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)3 NameCallback (javax.security.auth.callback.NameCallback)3 PasswordCallback (javax.security.auth.callback.PasswordCallback)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ComparisonResult (org.forgerock.openam.authentication.modules.deviceprint.comparators.ComparisonResult)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 NotUniqueUserProfileException (org.forgerock.openam.authentication.modules.deviceprint.exceptions.NotUniqueUserProfileException)1