Search in sources :

Example 21 with DevicePrint

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

Example 22 with DevicePrint

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

the class DevicePrintAuthenticationServiceTest method shouldGotoSaveProfilePageWhenSubmittedOTPWithCorrectCode.

/**
     * 5) third call, using OPT, 2 - OPT code submitted, with correct code - should return 3
     */
@Test
public void shouldGotoSaveProfilePageWhenSubmittedOTPWithCorrectCode() throws AuthLoginException {
    //Given
    Callback[] callbacks = new Callback[2];
    PasswordCallback smsOTPCallback = mock(PasswordCallback.class);
    ConfirmationCallback confirmationCallback = mock(ConfirmationCallback.class);
    int state = 2;
    String otpCode = "OTPCODE";
    callbacks[0] = smsOTPCallback;
    callbacks[1] = confirmationCallback;
    given(smsOTPCallback.getPassword()).willReturn(otpCode.toCharArray());
    given(confirmationCallback.getSelectedIndex()).willReturn(0);
    given(hotpService.isValidHOTP("OTPCODE")).willReturn(true);
    given(devicePrintService.hasRequiredAttributes(Matchers.<DevicePrint>anyObject())).willReturn(true);
    //When
    int nextState = devicePrintAuthenticationService.process(callbacks, state);
    //Then
    assertEquals(nextState, 3);
}
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) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 23 with DevicePrint

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

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