'Spring ldapTemplate: how to lookup fully qualified DN with configured base DN?
When I do a lookup for a DN with Springs ldapTemplate, I have to omit the configured base DN.
For example when the base DN is configured as dc=company,dc=com, a working lookup would be like
ldapTemplate.lookup("ou=whatever,ou=groups")
When I pass the fully qualified DN
ldapTemplate.lookup("ou=whatever,ou=groups,dc=company,dc=com")
the lookup fails and complains that the DN ou=whatever,ou=groups,dc=company,dc=com,dc=company,dc=com (note the doubled base at the end) does not exist.
As a consequence, when I do lookups based on returned DNs from previous lookups, I have to remove the base from the end of the DN.
This is quite annoying and I am almost sure that there is a better way to do this.
So, how can I do a lookup for a fully qualified DN with a configured base DN?
I know there is a query method that takes a base argument, but this seems to be made for more real queries, not simple lookups.
Example use of the accepted answer of @jzheaux
LdapName fqdn = ... //fully qualified DN with base DN that is returned from lookup
LdapName baseDn = ((LdapContextSource) ldapTemplate.getContextSource()).getBaseLdapName();
LdapName lookupDn = LdapUtils.removeFirst(fqdn, baseDn);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
