Search in sources :

Example 1 with UserProfile

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

the class UserProfilesDao method saveProfiles.

/**
     * Saves the DAO's internal user profiles cache to LDAP.
     *
     * @throws NotUniqueUserProfileException If two or more user profiles have the same uuid or name.
     */
public void saveProfiles() throws NotUniqueUserProfileException {
    validate();
    Set<String> vals = new HashSet<String>();
    for (UserProfile userProfile : profiles) {
        Writer strWriter = new StringWriter();
        try {
            mapper.writeValue(strWriter, userProfile);
            vals.add(strWriter.toString());
        } catch (Exception e) {
            DEBUG.error("Error while serializing profiles. " + e);
        }
    }
    Map<String, Set> attrMap = new HashMap<String, Set>();
    attrMap.put(LDAP_DEVICE_PRINT_ATTRIBUTE_NAME, vals);
    try {
        amIdentity.setAttributes(attrMap);
        amIdentity.store();
        DEBUG.message("Profiles stored");
    } catch (Exception e) {
        DEBUG.error("Could not store profiles. " + e);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) StringWriter(java.io.StringWriter) Writer(java.io.Writer) NotUniqueUserProfileException(org.forgerock.openam.authentication.modules.deviceprint.exceptions.NotUniqueUserProfileException) HashSet(java.util.HashSet)

Example 2 with UserProfile

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

the class UserProfilesDaoTest method createUserProfile.

private UserProfile createUserProfile(String uuid, String name) {
    UserProfile userProfile = new UserProfile(getDate(), getDate(), 1L);
    DevicePrint devicePrint = new DevicePrint();
    devicePrint.setScreenColourDepth("SCREEN_COLOUR_DEPTH");
    devicePrint.setScreenHeight("SCREEN_HEIGHT");
    devicePrint.setScreenWidth("SCREEN_WIDTH");
    devicePrint.setInstalledPlugins("INSTALLED_PLUGINS");
    devicePrint.setInstalledFonts("INSTALLED_FONTS");
    devicePrint.setTimezone("TIMEZONE");
    devicePrint.setLongitude(2.0);
    devicePrint.setLatitude(3.0);
    devicePrint.setUserAgent("USER_AGENT");
    userProfile.setDevicePrint(devicePrint);
    userProfile.setUuid(uuid);
    return userProfile;
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint)

Example 3 with UserProfile

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

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

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

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