Article

coolguys's picture

Synchronizing an eDirectory GUID to an Oracle Database

Author Info

5 March 2008 - 7:16am
Submitted by: coolguys

article
Reads:

2354

Score:
2
2
1
 
Comments:

0

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;
}


Author Info

5 March 2008 - 7:16am
Submitted by: coolguys




User Comments

© 2009 Novell, Inc. All Rights Reserved.