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);
}
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);
}
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;
}
Aggregations