123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- /**
- *
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: ccl4j
- * (C) Copyright IBM Corp. 2009, 2010
- * US Government Users Restricted Rights – Use, duplication or disclosure restricted
- * by GSA ADP Schedule Contract with IBM Corp.
- *
- */
- /**
- * A Javascript file that provides a set of functions to retrieve the parameters of the cam passport cookie. A web64 encoded
- * value is expected.
- *
- * Functions provided:
- * canCurrentUserCallLogon
- * getPassportGeneration
- * getPassportID
- * getVersion
- * isLoggingEnabled
- * isCamConfiguredForAnonymous
- * isCurrentUserAnonymous
- * areCamNamespacesConfigured
- *
- */
- var web64EncodedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789*-";
- var web64PadChar = '_';
- // delimiter for fields in the cookie.
- var DELIMITER = ";";
- // indicates that a feature is enabled.
- var FLAG_SET = "1";
- var PID_HEADER_SIZE = 4;
- var PID_HEADER_NAMESPACES_CONFIGURED_FLAG_START = 0;
- var PID_HEADER_NAMESPACES_CONFIGURED_FLAG_END = 1;
- var PID_HEADER_ANONYMOUS_CONFIGURED_FLAG_START = 1;
- var PID_HEADER_ANONYMOUS_CONFIGURED_FLAG_END = 2;
- var PID_HEADER_NAMED_USER_FLAG_START = 2;
- var PID_HEADER_NAMED_USER_FLAG_END = 3;
- // The cookie can have 2 formats.
- // The new format is:
- // version;passportID;loggingEnabled;passportGeneration;canUserCallLogon;
- // i.e.
- // 1;010:d1c8943e-0cf8-94f4-a5dc-a052647fc099:0231092414;0;3;0;
- // The old format is:
- // passportID
- // i.e. 010:d1c8943e-0cf8-94f4-a5dc-a052647fc099:0231092414
- function web64Decode(text)
- {
- if(text == null || text.length == 0 || text.length % 4 != 0)
- return text;
-
- //web64 Decoding. Note: Does currently not support UTF8, or charCodeAt() values above 255.
- //Initialize the decode object based on the encode string.
- var decodeChars = {};
- for (var i=0; i<64; i++)
- {
- decodeChars[web64EncodedChars.charAt(i)] = i;
- }
- decodeChars[web64PadChar] = 64;
- var decodedString = "";
- var sourceLength = text.length;
- for (var i=0; i<sourceLength; i+=4)
- {
- //Get the next 4 characters. The last two characters could be padding characters, which will have a value of 64.
- var charValue1 = decodeChars[text.charAt(i)];
- var charValue2 = decodeChars[text.charAt(i+1)];
- var charValue3 = decodeChars[text.charAt(i+2)];
- var charValue4 = decodeChars[text.charAt(i+3)];
- decodedString += String.fromCharCode((charValue1 << 2) + (charValue2 >> 4));
- charValue2 = (charValue2 & 15) << 4;
- if (charValue3 != 64)
- {
- decodedString += String.fromCharCode(charValue2 + (charValue3 >> 2));
- charValue3 = (charValue3 & 3) << 6;
- if (charValue4 != 64)
- {
- decodedString += String.fromCharCode(charValue3 + charValue4);
- }
- }
- }
- return decodedString;
- }
- function parse(camPassportCookie)
- {
- // set defaults
- var cookieObj = new Object();
- cookieObj.version = 0;
- cookieObj.passportId = null;
- cookieObj.loggingEnabled = true;
- cookieObj.passportGeneration = 0;
- cookieObj.canUserCallLogon = true;
-
- var values = new Array();
-
- try
- {
- if (camPassportCookie != null && camPassportCookie.length > 0)
- {
- if (camPassportCookie.charAt(3) == ':')
- {
- // old format
- cookieObj.passportId = camPassportCookie;
- cookieObj.passportGeneration = 1;
- }
- else
- {
- // get version
- var startPos = 0;
- var endPos = camPassportCookie.indexOf(DELIMITER, startPos);
- if(endPos == -1)
- throw "";
- values[0] = camPassportCookie.substring(startPos, endPos);
-
- startPos = endPos + 1;
-
- // get passportId
- endPos = camPassportCookie.indexOf(DELIMITER, startPos);
- if(endPos == -1)
- throw "";
- values[1] = camPassportCookie.substring(startPos, endPos);
-
- startPos = endPos + 1;
-
- // get loggingEnabled
- endPos = camPassportCookie.indexOf(DELIMITER, startPos);
- if(endPos == -1)
- throw "";
- values[2] = camPassportCookie.substring(startPos, endPos);
-
- startPos = endPos + 1;
-
- // get passportGeneration
- endPos = camPassportCookie.indexOf(DELIMITER, startPos);
- if(endPos == -1)
- throw "";
- values[3] = camPassportCookie.substring(startPos, endPos);
-
- startPos = endPos + 1;
-
- // get canUserCallLogon
- endPos = camPassportCookie.indexOf(DELIMITER, startPos);
- if(endPos == -1)
- throw "";
- values[4] = camPassportCookie.substring(startPos, endPos);
- }
- }
- }
- catch(err)
- {
- }
-
- if (values.length == 5)
- {
- // cam passport cookie is valid, copy the values
- cookieObj.version = values[0];
- cookieObj.passportId = values[1];
- cookieObj.loggingEnabled = values[2];
- cookieObj.passportGeneration = values[3];
- cookieObj.canUserCallLogon = values[4];
- }
-
- return cookieObj;
- }
- function canCurrentUserCallLogon(/* web64 encoded string */ camPassportCookie)
- {
- var decodedValue = web64Decode(camPassportCookie);
- if (parse(decodedValue).canUserCallLogon == FLAG_SET)
- return true;
- else
- return false;
- }
- function getPassportGeneration(/* web64 encoded string */ camPassportCookie)
- {
- var decodedValue = web64Decode(camPassportCookie);
- return parse(decodedValue).passportGeneration;
- }
- function getPassportID(/* web64 encoded string */ camPassportCookie)
- {
- var decodedValue = web64Decode(camPassportCookie);
- return parse(decodedValue).passportId;
- }
- function getVersion(/* web64 encoded string */ camPassportCookie)
- {
- var decodedValue = web64Decode(camPassportCookie);
- return parse(decodedValue).version;
- }
- function isLoggingEnabled(/* web64 encoded string */ camPassportCookie)
- {
- var decodedValue = web64Decode(camPassportCookie);
- if (parse(decodedValue).loggingEnabled == FLAG_SET)
- return true;
- else
- return false;
- }
- function isCamConfiguredForAnonymous(/* web64 encoded string */ camPassportCookie)
- {
- var decodedValue = web64Decode(camPassportCookie);
- var passportId = parse(decodedValue).passportId;
- if (passportId != null && passportId.length > PID_HEADER_SIZE)
- {
- var flagBit =
- passportId.substring(PID_HEADER_ANONYMOUS_CONFIGURED_FLAG_START, PID_HEADER_ANONYMOUS_CONFIGURED_FLAG_END);
- if (flagBit == FLAG_SET)
- return true;
- }
-
- return false;
- }
- function isCurrentUserAnonymous(/* web64 encoded string */ camPassportCookie)
- {
- var decodedValue = web64Decode(camPassportCookie);
- var passportId = parse(decodedValue).passportId;
- if (passportId != null && passportId.length > PID_HEADER_SIZE)
- {
- var flagBit = passportId.substring(PID_HEADER_NAMED_USER_FLAG_START, PID_HEADER_NAMED_USER_FLAG_END);
- if (flagBit == FLAG_SET)
- return false;
- else
- return true;
- }
-
- return false;
- }
- function areCamNamespacesConfigured(/* web64 encoded string */ camPassportCookie)
- {
- var decodedValue = web64Decode(camPassportCookie);
- var passportId = parse(decodedValue).passportId;
- if (passportId != null && passportId.length > PID_HEADER_SIZE)
- {
- var flagBit =
- passportId.substring(PID_HEADER_NAMESPACES_CONFIGURED_FLAG_START, PID_HEADER_NAMESPACES_CONFIGURED_FLAG_END);
- if (flagBit == FLAG_SET)
- return true;
- }
- return false;
- }
|