Get Headers and Cookies in JavaScript InfoMap Mechanism

In a previous post, I shared a way to get headers in OTP mapping rules and in the AuthSvcCred Mapping rules.

Since the infomap module is a little bit different, I have included an example of how you can do it there:

importClass(Packages.com.tivoli.am.fim.trustserver.sts.utilities.IDMappingExtUtils);


//Get from headers...
var headerValue = context.get(Scope.REQUEST, 
                   "urn:ibm:security:asf:request:header", "customHeader");
IDMappingExtUtils.traceString("Header Value Acquired: " + headerValue);

//Get from headers...
var headerMap = context.get(Scope.REQUEST, "internal:authsvc:request", "headersMap");
IDMappingExtUtils.traceString("Header Value Acquired: " + headerMap);
var cookieString = "Cookies";
var userAgentString = "User-Agent: ";

//Get a Header
var userAgentArray = headerMap.get("User-Agent");
if (userAgentArray != null && userAgentArray.length == 1 )
{
    userAgentString += userAgentArray[0];
}

//Get the Cookie Header
var cookiesArray = headerMap.get("Cookie");
if (cookiesArray != null && cookiesArray.length == 1)
{
    cookieString = " : " + cookiesArray[0]; 
}

//Output to the template - using the ERROR_MESSAGE Macro. 

macros.put("@ERROR_MESSAGE@", "User-Agent: " + userAgentString +
                                  " CookieString: " + cookieString);

success.setValue(false);

Here is the output into my MACRO for easy debugging:

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:50.0) 
Gecko/20100101 Firefox/50.0 Num Cookies: 1 Values: Cookies : 
JSESSIONID=0000I-m8cLcUr5toauaZ_0Agpcn:3ccabff4-c62d-41d1-b1fc-
de6b0b896b9b:2c61fed1-dba6-4f3b-a4ff-694a310b88f6:5d8cd5c1-62a4-
4f55-8a8d-bb831e86e24b; AnotherCookie=AUeXJbfnWt33PIMZ3tvfyP0SuvRc
SShKd28shnJHyCAz_0bRhiWw_8pf8m46xTCrO-sYe35PzQ_LK9B8d0ZpXd2Fiso9-3
ciH6Ay9AcMWpUFSBTzwUutZAiGqtdo1sKJ

Fairly simple, and then it’s a standard JavaScript process to process the cookies by name. Of which there are countless examples on the internet, for example:

http://stackoverflow.com/questions/5639346/what-is-the-shortest-function-for-reading-a-cookie-by-name-in-javascript

Some of the useful things that this can enable:

  • Custom behaviour for remember me.
  • Reading in the fingerprint cookie (ac.uuid) to make an infoMap call to Context Based Access.
  • Reading in the referrer header for prefilling details on a page.

Comments are closed.

WordPress.com.

Up ↑

%d bloggers like this: