嗨,我是一个开发人员,但ldap编程新手。我能够通过提供DN=ou=app1、ou=development、ou=Group来访问我们的Ldap服务器,并将我的搜索级别设置为subtree_scope,并且能够到达on level down,这将我置于DN=cn=admin,DN=ou=app1,ou=development,ou=Group。通过展开这个DN,我看到了Member(4)、OU(1)、cn(1)和Objectclasses:top和groupOfNames。我正在尝试使用uid=user条目访问这4个用户。当我尝试访问uid时,收到以下消息
UID...javax.naming.directory.SearchResult类
找到的cn=Admin为空:
属性是..无属性
以下是我的代码片段。如果需要,我可以提供更多
controls.setReturningAttributes("uid");
String filter="(objectClass=groupOfNames)";
NamingEnumeration objs = ctx.search("",filter, controls);
while (objs.hasMoreElements())
{
SearchResult match = (SearchResult)objs.nextElement();
System.out.println(" UID...\t"+ match.getClass());
System.out.println(match.getClassName());
System.out.println("Found "+match.getName()+":");
System.out.println("Attributes are..\t"+match.getAttributes());
Attributes attrs = match.getAttributes();
NamingEnumeration e = attrs.getAll();
while (e.hasMoreElements())
{
Attribute attr = (Attribute) e.nextElement();
System.out.println("Attribute and its class..\t"+attr.getClass());
}
System.out.println("---------------------------------------");
}
}发布于 2013-11-23 05:55:35
SearchControls定义搜索要返回的属性。必须已将其“”returningAttributes“”属性设置为“”new String“”。“”将其保留为null以获取所有属性,或指定所需的属性。
https://stackoverflow.com/questions/20154599
复制相似问题