Search code examples
javaactive-directoryspring-ldapldap-query

How to fix the exception java.lang.ClassCastException: java.lang.String cannot be cast to [B while getting the objctGUID from AD?


I'm trying to fetch an unique identifier from windows AD. But at the following line of code:

byte[] objGUIDByteArr = (byte[]) attrs.get("objectGUID").get();

I'm getting the following exception

java.lang.ClassCastException: java.lang.String cannot be cast to [B

How to fix this & get the byte[] value from the objectGUID?


Solution

  • We must pass a base environment property to let spring LDAP know that objectGUID has to be returned in java.naming.ldap.attributes.binary format instead of the default String format.