IBM Security Verify

 View Only
Expand all | Collapse all

ISAM - Getting Error While Using PluginUtils Class

  • 1.  ISAM - Getting Error While Using PluginUtils Class

    Posted Wed December 09, 2020 09:08 AM
    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
    ------------------------------


  • 2.  RE: ISAM - Getting Error While Using PluginUtils Class

    Posted Wed December 09, 2020 09:45 AM
    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$Decoder
    java.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
    ------------------------------



  • 3.  RE: ISAM - Getting Error While Using PluginUtils Class

    Posted Wed December 09, 2020 11:49 AM
    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
    ------------------------------



  • 4.  RE: ISAM - Getting Error While Using PluginUtils Class

    Posted Thu December 10, 2020 01:03 AM
    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
    ------------------------------



  • 5.  RE: ISAM - Getting Error While Using PluginUtils Class

    Posted Thu December 10, 2020 07:12 AM
    Edited by Dries Eestermans Thu December 10, 2020 07:12 AM
    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
    ------------------------------



  • 6.  RE: ISAM - Getting Error While Using PluginUtils Class

    Posted Thu December 10, 2020 08:19 AM
    Hi Dries,

    Thanks for the Help!.

    yes, it's working fine.


    ------------------------------
    Mukesh
    ------------------------------



  • 7.  RE: ISAM - Getting Error While Using PluginUtils Class

    Posted Wed February 28, 2024 12:59 PM

    Hi Dries,

    I was trying the way you recommended to encode a string to base64 in an info map mapping rule which is 

    importClass(Packages.com.tivoli.am.fim.base64.BASE64Utility);
    
    let base64encodedString = java.util.Base64.getEncoder().encodeToString("examplestring");

    but it's giving me this error:

    Can't find method java.util.Base64$Encoder.encodeToString(string)

    Any ideas?



    ------------------------------
    Amal Aldoss
    ------------------------------



  • 8.  RE: ISAM - Getting Error While Using PluginUtils Class

    Posted Thu December 10, 2020 12:57 AM
    Hi Jon,

    So basically, I want to use other functions also. there is a hash function in PluginUtils Class. which I want to use to hash 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.

    ------------------------------
    Mukesh
    ------------------------------



  • 9.  RE: ISAM - Getting Error While Using PluginUtils Class

    Posted Thu December 10, 2020 09:49 AM
    Try this, notice the use of importPackage instead of importClass:

    importPackage(com.tivoli.am.rba.extensions);
    PluginUtils.encodeBase64("mukesh");
    
    ​


    ------------------------------
    Enio Padilla
    ------------------------------