0

How can I search a group(groupOfNames) in LDAP where as an input I can only pass the group name.Names of the groups created are unique. I am using LDAP eclipse plugin only, to search the group Hierarchy. I want the JAVA Code to search the group through it's cn(common name) which will be unique.

e.g.,

void searchGroupName("sampleGroup")
{
context.search(String groupRoot,String sampleGroup,SearchControls ctls);
}
Ankit
  • 1
  • 5

1 Answers1

0

I'm assuming you will be using Spring LDAP, since the question is tagged with that. Using Spring LDAP 2.x you would do something along the lines of:

Group group = ldapTemplate.searchForObject(
                query().base(groupRoot).where("cn").is(sampleGroup),
                new AbstractContextMapper<Group>({
                  protected Group doMapFromContext(DirContextOperations ctx) {
                    // Build Group instance here using ctx.getStringAttribute()
                    return Group;
                  }
                });

Or, if you're using Spring LDAP ODM and have annotated your Group domain class appropriately (see the reference documentation for details on that):

Group group = ldapTemplate.findOne(
                 query().where("cn").is(sampleGroup), 
                 Group.class);

For a complete application example working with users and groups, check out the Spring LDAP user admin sample.

marthursson
  • 3,242
  • 1
  • 18
  • 28