PDA

View Full Version : strip base dn



hasdy
Sep 19th, 2007, 04:54 PM
I have my base dn set in the LdapContextSource within the applicationContext configuration.

Sometimes when I'm doing a lookup I have the full DN string of a user (inc. base dn). So when I create a DistinguishedName object with that DN string, and do a lookup.... it won't find it but if I strip out the base dn, it will.

So... I suppose I have to strip out the base dn from my string.

Without hardcoding the base dn in my code, I was thinking I could grab it from the contextSource..... but how do I get this?

The ldaptemplate only has a setContextSource and no get.... so is there an easy way to grab that basedn value?

OR is there even an easier way to approach this?


thanks!

rasky
Sep 20th, 2007, 01:03 AM
The preferred way of getting the full dn of an entry is to use DirContextAdapter.getNameInNamespace(). That automatically prepends the base DN to the dn of the entry.