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