First we need to encode the objectGUID byte array into a hexadecimal representation with escaped backslashes () for each byte
private String encodeToHexWithEscape(byte[] bytes) {
StringBuilder hexBuilder = new StringBuilder();
for (byte b : bytes) {
// Format each byte as a two-digit hex value with a leading backslash
hexBuilder.append(String.format("\\%02X", b & 0xFF));
}
return hexBuilder.toString();
}
Then use it in filter for ldap search:
String hexEncodedGUID = encodeToHexWithEscape(objectGUID);
String filter = String.format("(objectGUID=%s)", hexEncodedGUID);
// Perform the search
ldapTemplate.search(
"", // Base DN (modify according to your directory structure)
filter,
new MyContextMapper()
);