Converting ObjectSID & objectGUID from active directory to readable format

Four Stars Ath
Four Stars

Converting ObjectSID & objectGUID from active directory to readable format

Hi All ,

We are retrieving the data from LDAP active directory and ObjectSID & objectGUID are fetched in a non readable format. Is there any easy way to convert them to readable format? 

 

Appreciate all the responses. TIA

Eleven Stars

Re: Converting ObjectSID & objectGUID from active directory to readable format

Five Stars

Re: Converting ObjectSID & objectGUID from active directory to readable format

The below routine works well to convert ObjectSID & objectGUID from active directory to readable format.

Call the routine in Tmap to convert objectSID and objectGUID.
Tostring.convertObjectGUIDToString(row.ColumnName)

Tostring.convertObjectSidToString(row.ColumnName)

 

package routines;

public class Tostring {

//converts objectSID to readable string format

public static String convertObjectSidToString(byte[] objectSid) {
int offset, size;
if (objectSid[0] != 1)
throw new IllegalArgumentException("objectSid revision must be 1");

StringBuilder stringSidBuilder = new StringBuilder("S-1-");
int subAuthorityCount = objectSid[1] & 0xFF;
long identifierAuthority = 0;
offset = 2;
size = 6;
for (int i = 0; i < size; i++) {
identifierAuthority |= (long) (objectSid[offset + i] & 0xFF) << (8 * (size - 1 - i));
}
if (identifierAuthority < Math.pow(2, 32)) {
stringSidBuilder.append(Long.toString(identifierAuthority));
} else {
stringSidBuilder.append("0x").append(
Long.toHexString(identifierAuthority).toUpperCase());
}
offset = 8;
size = 4; // 32-bits (4 bytes) for each SubAuthority
for (int i = 0; i < subAuthorityCount; i++, offset += size) {
long subAuthority = 0;
for (int j = 0; j < size; j++) {
subAuthority |= (long) (objectSid[offset + j] & 0xFF) << (8 * j);
}
stringSidBuilder.append("-").append(subAuthority);
}

return stringSidBuilder.toString();
}

//converts objectGUID to readable string format

public static String convertObjectGUIDToString(byte[] objectGUID) {
StringBuilder displayStr = new StringBuilder();
displayStr.append(prefixZeros((int) objectGUID[3] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[2] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[1] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[0] & 0xFF));
displayStr.append("-");
displayStr.append(prefixZeros((int) objectGUID[5] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[4] & 0xFF));
displayStr.append("-");
displayStr.append(prefixZeros((int) objectGUID[7] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[6] & 0xFF));
displayStr.append("-");
displayStr.append(prefixZeros((int) objectGUID[8] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[9] & 0xFF));
displayStr.append("-");
displayStr.append(prefixZeros((int) objectGUID[10] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[11] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[12] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[13] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[14] & 0xFF));
displayStr.append(prefixZeros((int) objectGUID[15] & 0xFF));
return displayStr.toString();
}


private static String prefixZeros(int value) {
if (value <= 0xF) {
StringBuilder sb = new StringBuilder("0");
sb.append(Integer.toHexString(value));

return sb.toString();

} else {
return Integer.toHexString(value);
}
}



}

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog