Search in sources :

Example 1 with DevicePrint

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Extractor(org.forgerock.openam.authentication.modules.deviceprint.extractors.Extractor) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with 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);
}
Also used : DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 3 with 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;
}
Also used : UserProfile(org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint)

Example 4 with DevicePrint

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());
}
Also used : DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) DevicePrintAuthenticationConfig(org.forgerock.openam.authentication.modules.deviceprint.DevicePrintAuthenticationConfig) Test(org.testng.annotations.Test)

Example 5 with DevicePrint

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);
}
Also used : DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint)

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