I am just trying out spring ldap /odmnow. Seems interesting and cool. sorry if the below question is too dumb!
I am trying to use spring ldap /odm to retreive some attributes from out ldap.Is there is a way to configure multiple base names in
or in
@Entry(objectClasses = { "person"} base={..CAN I GIVE MULTIPLE BASENames here..}) public class LdapUser {
@Id
private Name dn;
The app I am developing has users defined under one OU and internal TESTERs defined in another ou in our AD. So I am trying to see if I can use the same ldap entry class for looking up everyone.
I am not very familiar with Spring LDAP but (IIRC) LDAP itself can only search from a single node (base). So, looking at the documentation, you might have to do a search from the organization (
o=xx
) with an LDAPQueryBuilder, adding conditions for theou
s. See the javadocs.The
ContextSource
base is intended to specify the base of all operations on theContextSource
, and is typically set to the domain controller DN.You can use ODM without specifying a base on the
@Entry
(or using a base DN higher up in the tree), but in that case you will typically use the@DnAttribute
annotation in order to have the framework automatically build DNs for you (mainly needed when persisting entries back to LDAP).If we assume your users are in the following structure:
dc=example,dc=com,ou=USERS
dc=example,dc=com,ou=TESTERS
Now, if you specify base
dc=example,dc=com
on the ContextSource you can have ODM handle this automatically as described briefly below:The above will handle automatic mapping of LDAP entries to and from the Person class. Now, if you want to find all persons, do:
If you want to find all testers you would do:
No expert here, mind you. With XML config at least, you can wire an LdapTemplate instance. One suggestion might be to make a new implementation called something like DelegatingLdapTemplate that gets injected with two regular templates (one per basename) and then delegates to them appropriately (or just calls one, then the other if the first one return 0 results), and use this in place of a normal template instance. This of course makes sense only if your use case really warrants this behavior (e.g. if you never know where to search for the user and have to check both locations). Otherwise, just make two separate beans.