Search in sources :

Example 16 with DevicePrint

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

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

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

the class DevicePrintAuthenticationConfigTest method shouldCheckForRequiredAttributesWithSomeRequiredAndPresent.

@Test
public void shouldCheckForRequiredAttributesWithSomeRequiredAndPresent() {
    //Given
    addToConfigSet(DevicePrintAuthenticationConfig.FONTS_REQUIRED, "true");
    addToConfigSet(DevicePrintAuthenticationConfig.GEO_LOCATION_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.PLUGINS_REQUIRED, "true");
    addToConfigSet(DevicePrintAuthenticationConfig.SCREEN_PARAMS_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.TIMEZONE_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.USER_AGENT_REQUIRED, "true");
    DevicePrint devicePrint = mock(DevicePrint.class);
    given(devicePrint.getInstalledFonts()).willReturn("INSTALLED_FONTS");
    given(devicePrint.getLatitude()).willReturn(2.0);
    given(devicePrint.getLongitude()).willReturn(3.0);
    given(devicePrint.getInstalledPlugins()).willReturn("INSTALLED+PLUGINS");
    given(devicePrint.getUserAgent()).willReturn("USER_AGENT");
    //When
    boolean value = devicePrintAuthenticationConfig.hasRequiredAttributes(devicePrint);
    //Then
    assertTrue(value);
}
Also used : DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 19 with DevicePrint

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

the class DevicePrintAuthenticationConfigTest method shouldCheckForRequiredAttributesWithSomeRequiredButNotAllPresent.

@Test
public void shouldCheckForRequiredAttributesWithSomeRequiredButNotAllPresent() {
    //Given
    addToConfigSet(DevicePrintAuthenticationConfig.FONTS_REQUIRED, "true");
    addToConfigSet(DevicePrintAuthenticationConfig.GEO_LOCATION_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.PLUGINS_REQUIRED, "true");
    addToConfigSet(DevicePrintAuthenticationConfig.SCREEN_PARAMS_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.TIMEZONE_REQUIRED, "true");
    addToConfigSet(DevicePrintAuthenticationConfig.USER_AGENT_REQUIRED, "true");
    DevicePrint devicePrint = mock(DevicePrint.class);
    given(devicePrint.getInstalledFonts()).willReturn("INSTALLED_FONTS");
    given(devicePrint.getLatitude()).willReturn(2.0);
    given(devicePrint.getLongitude()).willReturn(3.0);
    given(devicePrint.getInstalledPlugins()).willReturn("INSTALLED+PLUGINS");
    given(devicePrint.getScreenColourDepth()).willReturn("SCREEN_COLOUR_DEPTH");
    given(devicePrint.getScreenHeight()).willReturn("SCREEN_HEIGHT");
    given(devicePrint.getScreenWidth()).willReturn("SCREEN_WIDTH");
    given(devicePrint.getUserAgent()).willReturn("USER_AGENT");
    //When
    boolean value = devicePrintAuthenticationConfig.hasRequiredAttributes(devicePrint);
    //Then
    assertFalse(value);
}
Also used : DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 20 with DevicePrint

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

the class DevicePrintAuthenticationServiceTest method shouldCreateUserProfileWhenNoValidPreviousProfiles.

/**
     * 8) fourth call, 3 - save profile, having no valid previous profiles - should create new profile, return ISAuthConstants.LOGIN_SUCCEED
     */
@Test
public void shouldCreateUserProfileWhenNoValidPreviousProfiles() throws AuthLoginException {
    //Given
    NameCallback devicePrintCallback = mock(NameCallback.class);
    Callback[] callbacks = new Callback[] { devicePrintCallback };
    int state = ISAuthConstants.LOGIN_START;
    DevicePrint devicePrint = mock(DevicePrint.class);
    given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
    given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(false);
    devicePrintAuthenticationService.process(callbacks, state);
    callbacks = new Callback[1];
    ChoiceCallback choiceCallback = mock(ChoiceCallback.class);
    state = 3;
    callbacks[0] = choiceCallback;
    given(choiceCallback.getSelectedIndexes()).willReturn(new int[] { 0 });
    //When
    int nextState = devicePrintAuthenticationService.process(callbacks, state);
    //Then
    verify(devicePrintService).createNewProfile(devicePrint);
    assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) 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) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) 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