Forward slashes in the names returned by JNDI query to LDAP server

…衆ロ難τιáo~ 提交于 2019-12-05 18:16:52

If an AttributeValue has LDAP-specific syntax, the characters are converted (using the defined syntax specification) to UTF-8 and only the following characters must be escaped:

  • ' ' (space) at the beginning of the string
  • ' ' (space) at the end of the string
  • '"'
  • '+' (the plus character indicates a multi-valued RDN)
  • , (the comma character separates components of the distinguished name)
  • ;
  • <
  • >
  • \

The forward slash is a valid character and need not be escaped, therefore it must be handled by the application and the API used by that application. As you noted, the forward slash has "special meaning" to JNDI. JNDI is poorly designed in many respects, this is only one of the many. Consider using the UnboundID LDAP SDK for new code.

For example, add the following entry:

dn: uid=abc/def,ou=people,dc=example,dc=com
objectClass: top
objectClass: person
objectClass: inetOrgPerson
uid: abc/def
cn: abc/def
sn: abc/def
userPassword: this entry is used to test http://stackoverflow.com/questions/11690529/forward-slashes-in-the-names-returned-by-jndi-query-to-ldap-server

retrieve the entry just added:

ldapsearch -h localhost -p 10389 -D 'cn=RootDn'  -b dc=example,dc=com -s sub '(uid=abc/def)' 1.1
Enter bind password: 
version: 1
dn: uid=abc/def,ou=people,dc=example,dc=com

see also

The search result return by SearchResult.getName() is of the form of CompositeName. Try to use it like this:

Name itemPart = new CompositeName(result.getName())
Name absoluteName = new LdapName(myBasePath).addAll(itemPart)
// or
String sAbsoluteName = ctx.composeName(new LdapName(myBasePath), itemPart)

Strange escaping will be removed from absoluteName.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!