使用search.context在LDAP中搜索组



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

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

我假设您将使用Spring LDAP,因为这个问题被标记为Spring LDAP。使用Spring LDAPX,你会这样做:

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域类(有关详细信息,请参阅参考文档):

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

有关使用用户和组的完整应用程序示例,请查看Spring LDAP用户admin示例。