0
我有一组名为DN如何在不使用ismemberof的情况下获得ldap组中成员的数量?
:CN =为myGroup,OU = manegedGroup,DC =例如,DC = com的 在LDAP和我想获得该组的成员的数量,而不使用ismemberof。我不想要任何DN或CN,而只需要没有成员。
预先感谢
我有一组名为DN如何在不使用ismemberof的情况下获得ldap组中成员的数量?
:CN =为myGroup,OU = manegedGroup,DC =例如,DC = com的 在LDAP和我想获得该组的成员的数量,而不使用ismemberof。我不想要任何DN或CN,而只需要没有成员。
预先感谢
不同LDAP服务器具有不同的组属性,以表示的成员。 MSAD使用属性“成员”,OID使用“唯一成员”等。
要获得成员数量,请搜索组条目“cn = myGroup”并获取“成员”属性的大小。
伪代码:
//Create initial dir context to dc=example,dc=com
env.put(DirContext.PROVIDER_URL, "ldap://<host>:<port>/dc=example,dc=com");
ctx = new InitialDirContext(env);
//Set returning attributes in search control
SearchControls controls = new SearchControls();
controls.setReturningAttributes(new String[] { "cn", "uniquemember"});
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//Set search filter
String filter = "(cn=myGroup)";
//Search for the group under the correct OU passing filter and control
NamingEnumeration<SearchResult> searchResult =ctx.search("ou=manegedGroup",
filter, controls);
//Get the size of the member attributes which is count of group members
while (searchResult.hasMoreElements()) {
SearchResult ser = searchResult.next();
Attributes attribs = ser.getAttributes();
Attribute attrib = attribs.get("member");
System.out.println("member count : "+attrib.size());
}
如何组成员分配?组员身份是用户的属性吗?或者用户是该组的一个属性? – heiglandreas