From 1887d3b038d6e9b8e59af6dbf816d7718d8e0157 Mon Sep 17 00:00:00 2001 From: Sven-Torben Janus Date: Tue, 17 Sep 2019 20:11:47 +0200 Subject: [PATCH] KEYCLOAK-10942 Incorporate comments from code review see https://github.com/keycloak/keycloak/pull/6251/files#r325212980 --- .../idm/store/ldap/LDAPOperationManager.java | 1 - .../storage/ldap/idm/store/ldap/LDAPUtil.java | 35 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPOperationManager.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPOperationManager.java index ce0446fa7a..bcb72d5334 100644 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPOperationManager.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPOperationManager.java @@ -658,7 +658,6 @@ public class LDAPOperationManager { } public String decodeEntryUUID(final Object entryUUID) { - String id; if (entryUUID instanceof byte[]) { if (this.config.isObjectGUID()) { return LDAPUtil.decodeObjectGUID((byte[]) entryUUID); diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPUtil.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPUtil.java index e4d17e4047..53e22e3164 100644 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPUtil.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/idm/store/ldap/LDAPUtil.java @@ -129,35 +129,42 @@ public class LDAPUtil { public static String decodeObjectGUID(byte[] objectGUID) { StringBuilder displayStr = new StringBuilder(); - byte[] withLittleEndian = new byte[] { objectGUID[3], objectGUID[2], objectGUID[1], objectGUID[0], - objectGUID[5], objectGUID[4], - objectGUID[7], objectGUID[6], - objectGUID[8], objectGUID[9], objectGUID[10], objectGUID[11], objectGUID[12], objectGUID[13], objectGUID[14], objectGUID[15] - }; - displayStr.append(convertToDashedString(withLittleEndian)); + displayStr.append(convertToDashedString(objectGUID)); return displayStr.toString(); } + /** + *

Decode a raw byte array representing the value of the guid attribute retrieved from Novell + * eDirectory.

+ * + * @param guid A raw byte array representing the value of the guid attribute retrieved from + * Novell eDirectory. + * + * @return A string representing the decoded value in the form of [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]. + */ public static String decodeGuid(byte[] guid) { - StringBuilder displayStr = new StringBuilder(); - displayStr.append(convertToDashedString(guid)); - return displayStr.toString(); + byte[] withBigEndian = new byte[] { guid[3], guid[2], guid[1], guid[0], + guid[5], guid[4], + guid[7], guid[6], + guid[8], guid[9], guid[10], guid[11], guid[12], guid[13], guid[14], guid[15] + }; + return convertToDashedString(withBigEndian); } private static String convertToDashedString(byte[] objectGUID) { StringBuilder displayStr = new StringBuilder(); - displayStr.append(prefixZeros((int) objectGUID[0] & 0xFF)); - displayStr.append(prefixZeros((int) objectGUID[1] & 0xFF)); - displayStr.append(prefixZeros((int) objectGUID[2] & 0xFF)); 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[4] & 0xFF)); displayStr.append(prefixZeros((int) objectGUID[5] & 0xFF)); + displayStr.append(prefixZeros((int) objectGUID[4] & 0xFF)); displayStr.append("-"); - displayStr.append(prefixZeros((int) objectGUID[6] & 0xFF)); 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));