Article
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;
}
Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).
It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.
Related Articles
User Comments
- Be the first to comment! To leave a comment you need to Login or Register
- 6167 reads


0