server-side.js revision 67d4b8e0d7b2401ae02cde1c197df565239df882
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2009 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
*/
/*
* Portions Copyrighted 2013 Syntegrity.
* Portions Copyrighted 2013-2014 ForgeRock AS.
*/
var ScalarComparator = {}, ScreenComparator = {}, MultiValueComparator = {}, UserAgentComparator = {}, GeolocationComparator = {};
var config = {
maxPenaltyPoints: 200,
attributes: {
screen: {
required: true,
args: {
penaltyPoints: 50
}
},
plugins: {
required: false,
args: {
maxDifferences: 5,
penaltyPoints: 100
}
}
},
fonts: {
required: false,
args: {
penaltyPoints: 100
}
}
},
timezone: {
timezone: {
required: false,
args: {
penaltyPoints: 100
}
}
},
userAgent: {
required: true,
args: {
ignoreVersion: true,
penaltyPoints: 100
}
},
geolocation: {
required: false,
args: {
penaltyPoints: 100
}
}
}
};
//---------------------------------------------------------------------------//
// Comparator functions //
//---------------------------------------------------------------------------//
// ComparisonResult
/**
* Constructs an instance of a ComparisonResult with the given penalty points.
*
* @param penaltyPoints (Number) The penalty points for the comparison (defaults to 0).
* @param additionalInfoInCurrentValue (boolean) Whether the current value contains more information
* than the stored value (defaults to false).
*/
function ComparisonResult() {
var penaltyPoints = 0,
additionalInfoInCurrentValue = false;
}
} else {
}
}
this.penaltyPoints = penaltyPoints;
}
/**
* Static method for functional programming.
*
* @return boolean true if comparisonResult.isSuccessful().
*/
return comparisonResult.isSuccessful();
};
/**
* Static method for functional programming.
*
* @return boolean true if comparisonResult.additionalInfoInCurrentValue.
*/
};
/**
* Comparison function that can be provided as an argument to array.sort
*/
return 0;
} else if (first === null) {
return -1;
} else if (second === null) {
return 1;
} else {
} else {
return (first.additionalInfoInCurrentValue ? 1 : 0) - (second.additionalInfoInCurrentValue ? 1 : 0);
}
}
};
/**
* Amalgamates the given ComparisonResult into this ComparisonResult.
*
* @param comparisonResult The ComparisonResult to include.
*/
}
};
/**
* Returns true if no penalty points have been assigned for the comparison.
*
* @return boolean true if the comparison was successful.
*/
};
/**
* Compares two simple objects (String|Number) and if they are equal then returns a ComparisonResult with zero
* penalty points assigned, otherwise returns a ComparisonResult with the given number of penalty points assigned.
*
* @param currentValue (String|Number) The current value.
* @param storedValue (String|Number) The stored value.
* @param config: {
* "penaltyPoints": (Number) The number of penalty points.
* }
* @return ComparisonResult.
*/
if (logger.messageEnabled()) {
}
return ComparisonResult.ZERO_PENALTY_POINTS;
}
if (storedValue !== null) {
}
} else if (currentValue !== null) {
return new ComparisonResult(true);
}
return ComparisonResult.ZERO_PENALTY_POINTS;
};
/**
* Compares two screens and if they are equal then returns a ComparisonResult with zero penalty points assigned,
* otherwise returns a ComparisonResult with the given number of penalty points assigned.
*
* @param currentValue: {
* "screenWidth": (Number) The current client screen width.
* "screenHeight": (Number) The current client screen height.
* "screenColourDepth": (Number) The current client screen colour depth.
* }
* @param storedValue: {
* "screenWidth": (Number) The stored client screen width.
* "screenHeight": (Number) The stored client screen height.
* "screenColourDepth": (Number) The stored client screen colour depth.
* }
* @param config: {
* "penaltyPoints": (Number) The number of penalty points.
* }
* @return ComparisonResult
*/
if (logger.messageEnabled()) {
}
// if comparing against old profile
if (storedValue === undefined) {
}
var comparisonResults = [
} else {
}
};
/**
* Splits both values using delimiter, trims every value and compares collections of values.
* Returns zero-result for same multi-value attributes.
*
* If collections are not same checks if number of differences is less or equal maxDifferences or
* percentage of difference is less or equal maxPercentageDifference.
*
* If yes then returns zero-result with additional info, else returns penaltyPoints-result.
*
* @param currentValue: (String) The current value.
* @param storedValue: (String) The stored value.
* @param config: {
* "maxPercentageDifference": (Number) The max difference percentage in the values,
* before the penalty is assigned.
* "maxDifferences": (Number) The max number of differences in the values,
* before the penalty points are assigned.
* "penaltyPoints": (Number) The number of penalty points.
* }
* @return ComparisonResult
*/
if (logger.messageEnabled()) {
}
var delimiter = ";",
return new ComparisonResult(true);
}
if (logger.messageEnabled()) {
}
if (maxNumberOfElements === 0) {
return ComparisonResult.ZERO_PENALTY_POINTS;
}
if (numberOfTheSameElements === maxNumberOfElements) {
return ComparisonResult.ZERO_PENALTY_POINTS;
}
if (logger.messageEnabled()) {
}
}
if (logger.messageEnabled()) {
}
}
if (logger.messageEnabled()) {
+ config.maxDifferences);
}
return new ComparisonResult(true);
};
/**
* Compares two User Agent Strings and if they are equal then returns a ComparisonResult with zero penalty
* points assigned, otherwise returns a ComparisonResult with the given number of penalty points assigned.
*
* @param currentValue (String) The current value.
* @param storedValue (String) The stored value.
* @param config: {
* "ignoreVersion": (boolean) If the version numbers in the User Agent Strings should be ignore
* in the comparison.
* "penaltyPoints": (Number) The number of penalty points.
* }
* @return A ComparisonResult.
*/
if (logger.messageEnabled()) {
}
if (config.ignoreVersion) {
// remove version number
}
};
/**
* Compares two locations, taking into account a degree of difference.
*
* @param currentValue: {
* "latitude": (Number) The current latitude.
* "longitude": (Number) The current longitude.
* }
* @param storedValue: {
* "latitude": (Number) The stored latitude.
* "longitude": (Number) The stored longitude.
* }
* @param config: {
* "allowedRange": (Number) The max difference allowed in the two locations, before the penalty is assigned.
* "penaltyPoints": (Number) The number of penalty points.
* }
* @return ComparisonResult
*/
if (logger.messageEnabled()) {
}
// if comparing against old profile
if (storedValue === undefined) {
}
// both null
return ComparisonResult.ZERO_PENALTY_POINTS;
}
// current null, stored not null
}
// current not null, stored null
}
// both have values, therefore perform comparison
if (logger.messageEnabled()) {
logger.message("Distance between (" + currentValue.latitude + "," + currentValue.longitude + ") and (" +
}
return ComparisonResult.ZERO_PENALTY_POINTS;
}
if (logger.messageEnabled()) {
}
return new ComparisonResult(true);
} else {
if (logger.messageEnabled()) {
}
}
};
//---------------------------------------------------------------------------//
// Device Print Logic - DO NOT MODIFY //
//---------------------------------------------------------------------------//
// Utility functions
/**
* Returns true if evaluating function f on each element of the Array a returns true.
*
* @param a: (Array) The array of elements to evaluate
* @param f: (Function) A single argument function for mapping elements of the array to boolean.
* @return boolean.
*/
all = function(a, f) {
var i;
for (i = 0; i < a.length; i++) {
if (f(a[i]) === false) {
return false;
}
}
return true;
};
/**
* Returns true if evaluating function f on any element of the Array a returns true.
*
* @param a: (Array) The array of elements to evaluate
* @param f: (Function) A single argument function for mapping elements of the array to boolean.
* @return boolean.
*/
any = function(a, f) {
var i;
for (i = 0; i < a.length; i++) {
if (f(a[i]) === true) {
return true;
}
}
return false;
};
/**
* Calculates the distances between the two locations.
*
* @param first: {
* "latitude": (Number) The first latitude.
* "longitude": (Number) The first longitude.
* }
* @param second: {
* "latitude": (Number) The second latitude.
* "longitude": (Number) The second longitude.
* }
* @return Number The distance between the two locations.
*/
dist;
function degreesToRadians(degrees) {
}
function radiansToDegrees(radians) {
}
return dist;
};
/**
* Converts a String holding a delimited sequence of values into an array.
*
* @param text (String) The String representation of a delimited sequence of values.
* @param delimiter (String) The character delimiting values within the text String.
* @return (Array) The comma separated values.
*/
var results = [],
i,
if (text === null) {
return results;
}
if (value !== "") {
}
}
return results;
};
/**
* Converts value to a percentage of range.
*
* @param value (Number) The actual number to be converted to a percentage.
* @param range (Number) The total number of values (i.e. represents 100%).
* @return (Number) The percentage.
*/
if (range === 0) {
return 0;
}
};
/**
* Creates a new array containing only those elements found in both arrays received as arguments.
*
* @param first (Array) The first array.
* @param second (Array) The second array.
* @return (Array) The elements that found in first and second.
*/
});
};
i;
return null;
}
}
return value;
}
function isLeafNode(attributeConfig) {
}
var attributePaths = [],
i;
for (attributeName in attributeConfig) {
} else {
}
}
}
}
return attributePaths;
}
function getDevicePrintAttributePaths(attributeConfig) {
return getAttributePaths(attributeConfig, []);
}
i,
return false;
}
}
return true;
}
function compareDevicePrintProfiles(attributeConfig, devicePrint, devicePrintProfiles, maxPenaltyPoints) {
j,
i,
vals;
results = [];
if (storedValue === null) {
} else {
}
if (logger.messageEnabled()) {
}
}
if (logger.messageEnabled()) {
}
});
}
return null;
}
if (logger.messageEnabled()) {
}
selectedProfile = null;
if (logger.messageEnabled()) {
}
}
if (selectedProfile === null) {
return false;
}
/* update profile */
vals = [];
}
return true;
}
function matchDevicePrint() {
if (!username) {
} else {
if (logger.messageEnabled()) {
}
var getProfiles = function () {
function isExpiredProfile(devicePrintProfile) {
var expirationDate = new Date(),
return lastSelectedDate < expirationDate;
}
function getNotExpiredProfiles() {
var results = [],
if (!isExpiredProfile(profile)) {
}
}
if (logger.messageEnabled()) {
}
return results;
}
return getNotExpiredProfiles();
},
// Will fail this module but fall-through to next module. Which should be OTP.
} else if (compareDevicePrintProfiles(config.attributes, devicePrint, devicePrintProfiles, config.maxPenaltyPoints)) {
} else {
// Will fail this module but fall-through to next module. Which should be OTP.
}
}
}