Search in sources :

Example 11 with UserProfile

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

the class DevicePrintService method createNewProfile.

/**
     * Creates a new User Profile with the given Device Print information in LDAP.
     *
     * @param devicePrint The Device Print to store.
     * @throws NotUniqueUserProfileException If the Device print information's id is not unique.
     */
public void createNewProfile(DevicePrint devicePrint) throws NotUniqueUserProfileException {
    UserProfile profile = new UserProfile(new Date(), new Date(), 1L);
    profile.setDevicePrint(devicePrint);
    profile.setUuid(new RandomHashGenerator().getRandomHash());
    saveProfile(profile);
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) Date(java.util.Date)

Example 12 with UserProfile

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

the class DevicePrintService method removeOldestProfile.

/**
     * Finds the oldest User's profile and removes it from LDAP.
     */
private void removeOldestProfile() {
    UserProfile oldestProfile = null;
    Date oldestDate = new Date();
    for (UserProfile userProfile : userProfilesDao.getProfiles()) {
        if (userProfile.getLastSelectedDate().before(oldestDate)) {
            oldestDate = userProfile.getLastSelectedDate();
            oldestProfile = userProfile;
        }
    }
    if (oldestProfile != null) {
        userProfilesDao.getProfiles().remove(oldestProfile);
    }
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) Date(java.util.Date)

Example 13 with UserProfile

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

the class DevicePrintService method getBestMatchingUserProfile.

/**
     * Uses the given Device Print information to find the best matching stored Device Print information from stored
     * User Profiles. It uses the penalty points set in the authentication module settings to determine whether a stored
     * Device print matches the given one.
     *
     * If no match is found null is returned.
     *
     * @param devicePrint The Device Print to find a match for.
     * @return The matching User Profile or null.
     */
public UserProfile getBestMatchingUserProfile(DevicePrint devicePrint) {
    SortedMap<ComparisonResult, UserProfile> comparisonResultMap = new TreeMap<ComparisonResult, UserProfile>();
    for (UserProfile userProfile : getNotExpiredProfiles()) {
        DevicePrint storedDevicePrint = userProfile.getDevicePrint();
        comparisonResultMap.put(devicePrintComparator.compare(devicePrint, storedDevicePrint, devicePrintAuthenticationConfig), userProfile);
    }
    if (comparisonResultMap.isEmpty()) {
        return null;
    }
    ComparisonResult selectedComparisonResult = comparisonResultMap.firstKey();
    UserProfile selectedProfile = null;
    if (selectedComparisonResult.getPenaltyPoints() <= devicePrintAuthenticationConfig.getLong(DevicePrintAuthenticationConfig.MAX_TOLERATED_PENALTY_POINTS)) {
        selectedProfile = comparisonResultMap.get(selectedComparisonResult);
    }
    return selectedProfile;
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) TreeMap(java.util.TreeMap) ComparisonResult(org.forgerock.openam.authentication.modules.deviceprint.comparators.ComparisonResult)

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