Hi Mukesh,
That's basically due to restrictions put in place for the various different components (type of mapping rules), see Jon's link which shows the JavaScript whitelist that shows which packages you can use in which type of Mapping Rule.
Alternatively, depending on your hashing requirements, you could use `OAuthMappingExtUtils`, but I don't know what type of Mapping Rule you're implementing this in, so your luck may be limited, a snippet either way:
importClass(Packages.com.tivoli.am.fim.base64.BASE64Utility);
importClass(Packages.com.tivoli.am.fim.trustserver.sts.utilities.OAuthMappingExtUtils);
let sha256Sum = BASE64Utility.encode(OAuthMappingExtUtils.SHA256Sum(new java.lang.String("examplestring")));
let sha384Sum = BASE64Utility.encode(OAuthMappingExtUtils.SHA384Sum(new java.lang.String("examplestring")));
let sha512Sum = BASE64Utility.encode(OAuthMappingExtUtils.SHA512Sum(new java.lang.String("examplestring")));
This is something I have used in an InfoMap and I guess it should still work with latest ISVA.
Regards,
------------------------------
Dries Eestermans
IS4U
------------------------------
Original Message:
Sent: Thu December 10, 2020 01:02 AM
From: Mukesh Bhati
Subject: ISAM - Getting Error While Using PluginUtils Class
Hi Dries,
Thanks for your inputs.
for encoding, the code provided by you is working fine. but I want to use other functions from PluginUtils class like a hash function to hash the string data.
and I used MechanismRegistrationHelper class in infoMap its works but when I use the same class in information point(PIP) where I'm getting the same Error.
so, I want to know why some classes are working fine in infoMap and others throwing an error?
------------------------------
Mukesh
Original Message:
Sent: Wed December 09, 2020 11:49 AM
From: Dries Eestermans
Subject: ISAM - Getting Error While Using PluginUtils Class
Hi Mukesh, Jon,
You can Base64 Util class using:
importClass(Packages.com.tivoli.am.fim.base64.BASE64Utility);let base64encodedString = java.util.Base64.getEncoder().encodeToString("examplestring");
That should give you a Base64 Encoded Java String.
Regarding the atob() and btoa() I previously used polyfills for that, not sure if still necessary with the latest ISVA release or that the polyfills I used still work, haven't tested it yet:
/* * Section for atob and btoa. * https://github.com/davidchambers/Base64.js/blob/master/base64.js * The polyfills don't work in ISAM, so I modified them to work <dries.eestermans@spamfree.org>. */const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';function InvalidCharacterError(message) { this.message = message;}InvalidCharacterError.prototype = new Error ();InvalidCharacterError.prototype.name = 'InvalidCharacterError';if (!Object.prototype.atob) { // decoder // [https://gist.github.com/1020396] by [https://github.com/atk] Object.prototype.atob = function(input) { var str = (String (input)).replace (/[=]+$/, ''); // #31: ExtendScript bad parse of /= if (str.length % 4 === 1) { throw new InvalidCharacterError ("'atob' failed: The string to be decoded is not correctly encoded."); } for ( // initialize result and counters var bc = 0, bs, buffer, idx = 0, output = ''; // get next character buffer = str.charAt (idx++); // eslint-disable-line no-cond-assign // character found in table? initialize bit storage and add its ascii value; ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, // and if not first of each 4 characters, // convert the first 8 bits to one ascii character bc++ % 4) ? output += String.fromCharCode (255 & bs >> (-2 * bc & 6)) : 0 ) { // try to find character in table (0-63, not found => -1) buffer = chars.indexOf (buffer); } return output; };}if (!Object.prototype.btoa) { // encoder // [https://gist.github.com/999166] by [https://github.com/nignag] Object.prototype.btoa = function(input) { var str = String (input); for ( // initialize result and counter var block, charCode, idx = 0, map = chars, output = ''; // if the next str index does not exist: // change the mapping table to "=" // check if d has no fractional digits str.charAt (idx | 0) || (map = '=', idx % 1); // "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8 output += map.charAt (63 & block >> 8 - idx % 1 * 8) ) { charCode = str.charCodeAt (idx += 3 / 4); if (charCode > 0xFF) { throw new InvalidCharacterError ("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); } block = block << 8 | charCode; } return output; };}
Hope it helps.
Regards,
------------------------------
Dries Eestermans
IS4U
Original Message:
Sent: Wed December 09, 2020 09:45 AM
From: Jon Harry
Subject: ISAM - Getting Error While Using PluginUtils Class
Hi Mukesh,
According to this page: https://www.ibm.com/support/knowledgecenter/SSPREK_10.0.0/com.ibm.isva.doc/config/concept/con_otp_customize_mapping_rules_gs_aac.htm
it should be possible to import that class - although that error message is one I've seen when trying to import a class that is not allowed.
These classes are also listed as allowed:
java.util.Base64$Decoderjava.util.Base64$Encoder
I also wonder if the JavaScript native atob() and btoa() functions are available instead?
Jon.
------------------------------
Jon Harry
Consulting IT Security Specialist
IBM
Original Message:
Sent: Wed December 09, 2020 09:07 AM
From: Mukesh Bhati
Subject: ISAM - Getting Error While Using PluginUtils Class
Hello All,
I want to encode a string in base64 in infoMap for that I'm trying to use PluginUtils class.
but getting the following error
{
"exceptionMsg": "Function importClass must be called with a class; had \"[JavaPackage com.tivoli.am.rba.extensions.PluginUtils]\" instead. (test#1)",
"state": "",
"message": "",
"mechanism": "urn:ibm:security:authentication:asf:mechanism:test"
}
infoMap code:
importClass(Packages.com.tivoli.am.rba.extensions.PluginUtils);
importClass(Packages.com.tivoli.am.fim.trustserver.sts.utilities.IDMappingExtUtils);
IDMappingExtUtils.traceString("encoded "+PluginUtils.encodeBase64("mukesh"));
can anyone help me?
------------------------------
Mukesh
------------------------------