使用search.context在LDAP中搜索组

时间:2014-05-08 10:16:58

标签: ldap openldap ldap-query spring-ldap ldapconnection

如何在LDAP中搜索组(groupOfNames)作为输入我只能传递组名。创建的组的名称是唯一的。 我只使用LDAP eclipse插件来搜索组Hierarchy。 我希望JAVA代码通过它的cn(通用名称)搜索组,这将是唯一的。

如,

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

1 个答案:

答案 0 :(得分:0)

我假设您将使用Spring LDAP,因为问题已标记为。使用Spring LDAP 2.x,您可以执行以下操作:

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;
                  }
                });

或者,如果您正在使用Spring LDAP ODM并正确地注释了您的Group域类(有关详细信息,请参阅reference documentation):

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

有关使用用户和群组的完整应用示例,请查看Spring LDAP user admin sample

相关问题