Problem

A Forum reader recently asked:

“Has anyone ever taken the GUID from eDir and synced it to a table in a JDBC Driver connected database? Our database developers would like to use the GUID translated to string from eDirectory as a key on their end, to ensure the unique reference to a user whose ID is synced to the Oracle table.

I think you are supposed to do some base64 to string conversion. Is this available in Policy Builder, or do I have to write something from scratch?”

And here is the response from Father Ramon …

Solution

Well, Base64 is a string format, so it may or may not already meet the need, but I suppose you are looking for one of the more canonical string representations of a GUID. There is no built-in way to perform this conversion; it requires calls to ECMAScript or Java to do at least part of the work.

Here is some ECMAScript that should do the trick:

importClass(Packages.com.novell.xml.util.Base64Codec);

/**
  * Convert a Base64 encoded GUID attribute value to an ASCII string
  * in the format the NDS2NDS driver uses as its association.
  *
  * @param {String}    s    Base64 encoded GUID attribute value
  *
  * @type String
  * @return ASCII string
  *
  * @throws IOException -
  */
function guid2Association(s)
{
     var bytes = Base64Codec.decode(s);
     var s1 = encodeAsciiHex(bytes);
     return '{' +
         s1.substring(6, 8) +
         s1.substring(4, 6) +
         s1.substring(2, 4) +
         s1.substring(0, 2) +
         '-' +
         s1.substring(10, 12) +
         s1.substring(8, 10) +
         '-' +
         s1.substring(14, 16).toLowerCase() +
         s1.substring(12, 14).toLowerCase() +
         '-' +
         s1.substring(16, 20) +
         '-' +
         s1.substring(20) +
         '}';
}

var digits = [
     "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
     "A", "B", "C", "D", "E", "F"
];


function encodeAsciiHex(abyte0)
{
     var buffer = "";
     for(var i = 0; i < abyte0.length; i++)
     {
         var byte0 = abyte0[i];
         buffer += digits[byte0 >> 4 & 0xf];
         buffer += digits[byte0 & 0xf];
     }

     return buffer;
}

2 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 5 (2 votes, average: 5.00 out of 5)
You need to be a registered member to rate this post.
Loading...
Categories: Uncategorized

Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

Leave a Reply

One Comment

  • ffreitas says:

    The code above works well inside the IDM engine where the com.novell.xml.util.Base64Codec package is available.
    An option in pure ECMA that works in modern browsers ( see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/atob for the browser support matrix) would be:

    /**
    * Convert a Base64 encoded GUID attribute value to an ASCII string
    * in the format the NDS2NDS driver uses as its association.
    *
    * @param {String} s Base64 encoded GUID attribute value
    *
    * @type String
    * @return ASCII string
    *
    * @throws IOException –
    */
    function guid2Association(s)
    {
    var s1 = base64toHEX(s)
    return ‘{‘ +
    s1.substring(6, 8) +
    s1.substring(4, 6) +
    s1.substring(2, 4) +
    s1.substring(0, 2) +
    ‘-‘ +
    s1.substring(10, 12) +
    s1.substring(8, 10) +
    ‘-‘ +
    s1.substring(14, 16).toLowerCase() +
    s1.substring(12, 14).toLowerCase() +
    ‘-‘ +
    s1.substring(16, 20) +
    ‘-‘ +
    s1.substring(20) +
    ‘}’;
    }

    // From https://stackoverflow.com/questions/39460182/decode-base64-to-hexadecimal-string-with-javascript

    function base64toHEX(base64) {
    var raw = atob(base64);
    var HEX = ”;
    for ( i = 0; i < raw.length; i++ ) {
    var _hex = raw.charCodeAt(i).toString(16)
    HEX += (_hex.length==2?_hex:'0'+_hex);
    }
    return HEX.toUpperCase();
    }

By: coolguys
Mar 5, 2008
7:16 am
Reads:
3,100
Score:
5
Active Directory Authentication Automation Cloud Computing Cloud Security Configuration Customizing Data Breach DirXML Drivers End User Management Identity Manager Importing-Exporting / ICE/ LDIF Intelligent Workload Management IT Security Knowledge Depot LDAP Monitoring Open Enterprise Server Passwords Reporting Secure Access Supported Troubleshooting Workflow