use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldGetCurrentDevicePrint.
@Test
public void shouldGetCurrentDevicePrint() {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
Set<Extractor> extractors = new HashSet<Extractor>();
Extractor extractorOne = mock(Extractor.class);
Extractor extractorTwo = mock(Extractor.class);
given(extractorFactory.getExtractors()).willReturn(extractors);
extractors.add(extractorOne);
extractors.add(extractorTwo);
//When
DevicePrint devicePrint = devicePrintService.getDevicePrint(request);
//Then
verify(extractorOne).extractData(Matchers.<DevicePrint>anyObject(), eq(request));
verify(extractorTwo).extractData(Matchers.<DevicePrint>anyObject(), eq(request));
assertNotNull(devicePrint);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldCheckHasRequiredAttributes.
@Test
public void shouldCheckHasRequiredAttributes() {
//Given
DevicePrint devicePrint = mock(DevicePrint.class);
//When
devicePrintService.hasRequiredAttributes(devicePrint);
//Then
verify(devicePrintAuthenticationConfig).hasRequiredAttributes(devicePrint);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint 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.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintComparatorTest method shouldCompareDevicePrints.
@Test
public void shouldCompareDevicePrints() {
//Given
DevicePrint currentDevicePrint = mock(DevicePrint.class);
DevicePrint storedDevicePrint = mock(DevicePrint.class);
DevicePrintAuthenticationConfig config = mock(DevicePrintAuthenticationConfig.class);
given(currentDevicePrint.getUserAgent()).willReturn("USER_AGENT");
given(storedDevicePrint.getUserAgent()).willReturn("USER_AGENT");
given(config.getLong(DevicePrintAuthenticationConfig.USER_AGENT_PENALTY_POINTS)).willReturn(100L);
given(config.getBoolean(DevicePrintAuthenticationConfig.IGNORE_VERSION_IN_USER_AGENT)).willReturn(false);
given(currentDevicePrint.getInstalledFonts()).willReturn("INSTALLED_FONTS");
given(storedDevicePrint.getInstalledFonts()).willReturn("INSTALLED_FONTS");
given(config.getInt(DevicePrintAuthenticationConfig.MAX_TOLERATED_DIFFS_IN_INSTALLED_FONTS)).willReturn(5);
given(config.getInt(DevicePrintAuthenticationConfig.MAX_TOLERATED_PERCENTAGE_TO_MARK_AS_DIFFERENT_INSTALLED_FONTS)).willReturn(10);
given(config.getLong(DevicePrintAuthenticationConfig.INSTALLED_FONTS_PENALTY_POINTS)).willReturn(100L);
given(currentDevicePrint.getInstalledPlugins()).willReturn("INSTALLED_PLUGINS");
given(storedDevicePrint.getInstalledPlugins()).willReturn("INSTALLED_PLUGINS");
given(config.getInt(DevicePrintAuthenticationConfig.MAX_TOLERATED_DIFFS_IN_INSTALLED_PLUGINS)).willReturn(5);
given(config.getInt(DevicePrintAuthenticationConfig.MAX_TOLERATED_PERCENTAGE_TO_MARK_AS_DIFFERENT_PLUGINS)).willReturn(10);
given(config.getLong(DevicePrintAuthenticationConfig.INSTALLED_PLUGINS_PENALTY_POINTS)).willReturn(100L);
given(currentDevicePrint.getScreenColourDepth()).willReturn("SCREEN_COLOUR_DEPTH");
given(storedDevicePrint.getScreenColourDepth()).willReturn("SCREEN_COLOUR_DEPTH");
given(config.getLong(DevicePrintAuthenticationConfig.SCREEN_COLOUR_DEPTH_PENALTY_POINTS)).willReturn(100L);
given(currentDevicePrint.getTimezone()).willReturn("TIMEZONE");
given(storedDevicePrint.getTimezone()).willReturn("TIMEZONE");
given(config.getLong(DevicePrintAuthenticationConfig.TIMEZONE_PENALTY_POINTS)).willReturn(100L);
given(currentDevicePrint.getScreenWidth()).willReturn("SCREEN_WIDTH");
given(storedDevicePrint.getScreenWidth()).willReturn("SCREEN_WIDTH");
given(currentDevicePrint.getScreenHeight()).willReturn("SCREEN_HEIGHT");
given(storedDevicePrint.getScreenHeight()).willReturn("SCREEN_HEIGHT");
given(config.getLong(DevicePrintAuthenticationConfig.SCREEN_RESOLUTION_PENALTY_POINTS)).willReturn(100L);
given(currentDevicePrint.getLatitude()).willReturn(2.0);
given(storedDevicePrint.getLatitude()).willReturn(2.0);
given(currentDevicePrint.getLongitude()).willReturn(3.0);
given(storedDevicePrint.getLongitude()).willReturn(3.0);
given(config.getLong(DevicePrintAuthenticationConfig.LOCATION_ALLOWED_RANGE)).willReturn(100L);
given(config.getLong(DevicePrintAuthenticationConfig.LOCATION_PENALTY_POINTS)).willReturn(100L);
ComparisonResult cr = new ComparisonResult(10L);
given(multiValueAttributeComparator.compare(anyString(), anyString(), anyInt(), anyInt(), anyLong())).willReturn(cr);
given(colocationComparator.compare(anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong(), anyLong())).willReturn(cr);
//When
ComparisonResult comparisonResult = devicePrintComparator.compare(currentDevicePrint, storedDevicePrint, config);
//Then
verify(multiValueAttributeComparator, times(2)).compare(anyString(), anyString(), anyInt(), anyInt(), anyLong());
verify(colocationComparator).compare(anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong(), anyLong());
assertEquals((long) comparisonResult.getPenaltyPoints(), 30L);
assertFalse(comparisonResult.getAdditionalInfoInCurrentValue());
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class FormExtractor method extractData.
/**
* {@inheritDoc}
*
* Extracts screen params, timezone and plugins from http header to DevicePrint.
*/
public void extractData(DevicePrint devicePrint, HttpServletRequest request) {
String devicePrintInfo = request.getParameter(DEVICE_PRINT_INFO);
if (devicePrintInfo == null) {
DEBUG.warning("HTTP form doesn't have " + DEVICE_PRINT_INFO + " attribute. No data extracted from form.");
}
if (DEBUG.messageEnabled()) {
DEBUG.message("Extracted device print info: " + devicePrintInfo);
}
DevicePrint devicePrintFromJson = new DevicePrint();
try {
devicePrintFromJson = mapper.readValue(devicePrintInfo, DevicePrint.class);
} catch (Exception e) {
DEBUG.error("Error while parsing json", e);
}
devicePrint.merge(devicePrintFromJson);
}
Aggregations