Search in sources :

Example 6 with DevicePrint

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

the class DevicePrintAuthenticationConfigTest method shouldCheckForRequiredAttributesWithNoneRequiredOrPresent.

@Test
public void shouldCheckForRequiredAttributesWithNoneRequiredOrPresent() {
    //Given
    addToConfigSet(DevicePrintAuthenticationConfig.FONTS_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.GEO_LOCATION_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.PLUGINS_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.SCREEN_PARAMS_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.TIMEZONE_REQUIRED, "false");
    addToConfigSet(DevicePrintAuthenticationConfig.USER_AGENT_REQUIRED, "false");
    DevicePrint devicePrint = mock(DevicePrint.class);
    //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 7 with DevicePrint

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

the class DevicePrintAuthenticationConfigTest method shouldCheckForRequiredAttributesWithAllRequiredAndPresent.

@Test
public void shouldCheckForRequiredAttributesWithAllRequiredAndPresent() {
    //Given
    addToConfigSet(DevicePrintAuthenticationConfig.FONTS_REQUIRED, "true");
    addToConfigSet(DevicePrintAuthenticationConfig.GEO_LOCATION_REQUIRED, "true");
    addToConfigSet(DevicePrintAuthenticationConfig.PLUGINS_REQUIRED, "true");
    addToConfigSet(DevicePrintAuthenticationConfig.SCREEN_PARAMS_REQUIRED, "true");
    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.getTimezone()).willReturn("TIMEZONE");
    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 8 with DevicePrint

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

the class DevicePrintAuthenticationServiceTest method shouldLoginSuccessfullyWhenValidMatchingStoredDevicePrintProfilesFound.

/**
     * 3) first call ISAuthConstants.LOGIN_START - device print attr populated, with a valid stored profile - should return ISAuthConstants.LOGIN_SUCCEED
     */
@Test
public void shouldLoginSuccessfullyWhenValidMatchingStoredDevicePrintProfilesFound() throws AuthLoginException {
    //Given
    Callback[] callbacks = new Callback[1];
    NameCallback devicePrintCallback = mock(NameCallback.class);
    int state = ISAuthConstants.LOGIN_START;
    DevicePrint devicePrint = mock(DevicePrint.class);
    UserProfile validStoredMatchingProfile = mock(UserProfile.class);
    UserProfile selectedUserProfile = validStoredMatchingProfile;
    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, ISAuthConstants.LOGIN_SUCCEED);
}
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)

Example 9 with DevicePrint

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

the class DevicePrintServiceTest method shouldGetBestMatchingUserProfile.

@Test
public void shouldGetBestMatchingUserProfile() {
    //Given
    DevicePrint devicePrint = mock(DevicePrint.class);
    List<UserProfile> userProfiles = new ArrayList<UserProfile>();
    UserProfile userProfileOne = mock(UserProfile.class);
    UserProfile userProfileTwo = mock(UserProfile.class);
    UserProfile userProfileThree = mock(UserProfile.class);
    DevicePrint userProfileOneDevicePrint = mock(DevicePrint.class);
    DevicePrint userProfileTwoDevicePrint = mock(DevicePrint.class);
    DevicePrint userProfileThreeDevicePrint = mock(DevicePrint.class);
    ComparisonResult userProfileOneResult = new ComparisonResult(30L);
    ComparisonResult userProfileThreeResult = new ComparisonResult(20L);
    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(29));
    given(userProfileOne.getDevicePrint()).willReturn(userProfileOneDevicePrint);
    given(userProfileTwo.getDevicePrint()).willReturn(userProfileTwoDevicePrint);
    given(userProfileThree.getDevicePrint()).willReturn(userProfileThreeDevicePrint);
    given(devicePrintComparator.compare(devicePrint, userProfileOneDevicePrint, devicePrintAuthenticationConfig)).willReturn(userProfileOneResult);
    given(devicePrintComparator.compare(devicePrint, userProfileThreeDevicePrint, devicePrintAuthenticationConfig)).willReturn(userProfileThreeResult);
    given(devicePrintAuthenticationConfig.getLong(DevicePrintAuthenticationConfig.MAX_TOLERATED_PENALTY_POINTS)).willReturn(50L);
    //When
    UserProfile selectedUserProfile = devicePrintService.getBestMatchingUserProfile(devicePrint);
    //Then
    assertEquals(selectedUserProfile, userProfileThree);
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) ArrayList(java.util.ArrayList) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) ComparisonResult(org.forgerock.openam.authentication.modules.deviceprint.comparators.ComparisonResult) Test(org.testng.annotations.Test)

Example 10 with DevicePrint

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

the class DevicePrintServiceTest method shouldGetBestMatchingUserProfileWithNoStoredProfiles.

@Test
public void shouldGetBestMatchingUserProfileWithNoStoredProfiles() {
    //Given
    DevicePrint devicePrint = mock(DevicePrint.class);
    List<UserProfile> userProfiles = new ArrayList<UserProfile>();
    given(userProfilesDao.getProfiles()).willReturn(userProfiles);
    //When
    UserProfile selectedUserProfile = devicePrintService.getBestMatchingUserProfile(devicePrint);
    //Then
    assertNull(selectedUserProfile);
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) ArrayList(java.util.ArrayList) 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