I need to make some requests to the LDAP directory server, and I use the JNDI directory resources for it. Then I need to do some work with the objects from the query result using their distinguished names. Some of the entries returned by the server contain a slash, and because of this, JNDI escapes the entire name with double quotes:
NamingEnumeration<SearchResult> results = dirContext.search(queryRoot, queryFilter, controls); for (SearchResult result : Collections.list(results)) { String objectName = result.getName(); System.out.println(objectName); }
If one of the objects in the query results has a name, for example: 'b = id / 10, a = 1', it is printed as follows
"b=id/10,a=1"
Note the double quotes around the name. Because of these quotes, I cannot directly create javax.naming.ldap.LdapName from it: with a NamingException "Invalid name" error.
I understand that I can remove these quotes manually, but it seems to be hacked. Is there any way to avoid such an escape? Or maybe there are cleaner methods to do what I need?
PS It's funny that the official JNDI tutorial suggests using LdapName to achieve "easy name manipulation" and even mentions an escape problem, but does not provide any links to the problem described above.
source share