2016-09-26 13 views
0

私はグループがDN ismemberofを使用せずにldapグループのメンバー数を取得するには?

と呼ばれています。cn = myGroupが、OU = manegedGroup、dc = example、dc = comの LDAPで、私はismemberof使用せずに、このグループのメンバーの数を取得したいです。私はdnまたはcnを必要としません、代わりにメンバーの必要はありません。

+0

グループのメンバーが割り当てられている方法は?グループメンバーシップはユーザーの属性ですか?または、ユーザーはグループの属性ですか? – heiglandreas

答えて

1

異なるLDAPサーバが異なるグループがメンバーを示すために属性を持つ事前に感謝します。 MSADは属性 "member"を使用し、OIDは "uniquemember"などを使用します。

メンバーの数を取得するには、グループエントリ "cn = myGroup"を検索し、 "member"属性のサイズを取得します。

擬似コード:

//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()); 
} 
関連する問題