Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Ath
Contributor
Contributor

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

Labels (1)
1 Solution

Accepted Solutions
Aami
Contributor III
Contributor III

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



}

View solution in original post

4 Replies
Aami
Contributor III
Contributor III

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



}

TSivakumar
Contributor
Contributor

Thanks Aami

I have used the routine. Working for me. I have used '{'+objectGUID.convertObjectGUIDToString(row1.objectGUID)+'}' to get curly brackets around them. Thanks again

VictorFaure
Contributor II
Contributor II

Thanks. It's a shame the components sets output schema as String for such columns and don't convert them as String, in my case it resulted in java object identifier being transferred around instead of the GUID... The component should not work this way.