spring-ldap icon indicating copy to clipboard operation
spring-ldap copied to clipboard

Bad documentation or implementation of NamingException.getResolvedName and .getRemainingName

Open maunzCache opened this issue 8 years ago • 0 comments
trafficstars

I have a use case where I need to pass a DN into a method which then creates all entries for the RDNs which are not yet available.

Example I'd like to pass something like

cn=MyGroup,ou=Tester,ou=Development,dc=www,dc=foo,dc=org

into my method.

The dc parts do exist. This is my current ldap context. But the rest may or may not exist so I need to create those entries. Let's assume the last two RDNs (MyGroup and Tester) do not exist in this example.

When I then try to bind to the example DN (without looking it up first) it will give me an internal LDAP NoSuchObject error and throw a NameNotFoundException (subclass of NamingException). Spring LDAP uses a wrapper to throw it's own NamingException which ist actually a javax.naming.NamingException. This exception has two convenience methods to find out why my binding failed. Those are called in the wrapper and not implemented by the library. Here is the output of those:

.getResolvedName()

ou=Tester,ou=Development

.getRemainingName()

cn=MyGroup,ou=Tester,ou=Development

As you can see the resolved name also lists ou=Tester which is not available at this point but the method says it was possible to resolve the name. Furthermore the remaining name part has the Tester and Development RDNs which where resolved so they are redundant output. Please note that the JDK documentation also suggests that this behavior is incorrect.

From whay I understand the following should be the correct behavior .getResolvedName()

ou=Development

.getRemainingName()

cn=MyGroup,ou=Tester

This is not only what the documentation of the methods suggest but also the (verbose) output from ldapadd

ldap_add: No such object (32) matched DN: ou=Development,dc=www,dc=foo,dc=org

maunzCache avatar Dec 13 '16 10:12 maunzCache