1

「ネストされた」が私が必要とする言葉であるかどうかはわかりませんが、説明は次のとおりです。

ユーザー「ジョン」がいます。「ジョン」はグループ「A」のメンバーです。グループ「B」には、グループ「A」がメンバーとして含まれています。

したがって、推移的には、「John」もグループ「B」のメンバーである必要があります。

ジョンのグループを取得すると、次のようにして、「B」ではなく「A」のみが取得されます。

DirectorySearcher searcher = new DirectorySearcher();
DirectoryEntry rootEntry = new DirectoryEntry(_ldap, _loginName, _password, AuthenticationTypes.ReadonlyServer);

searcher.SearchRoot = rootEntry;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(sAMAccountName=" + filter.Split('\\')[1] + ")(objectClass=user))";
searcher.PropertiesToLoad.Add("memberOf");
searcher.PropertiesToLoad.Add("displayname");

SearchResult sr = searcher.FindOne();

どうすればこれを達成できますか?

ありがとうございました!

4

1 に答える 1

3

I ended up using the "tokenGroups" property of the user, which seems to return all the groups the user is in, even the ones in which he is member transitively.

here's my code:

DirectorySearcher searcher = new DirectorySearcher();
DirectoryEntry rootEntry = new DirectoryEntry(_ldap, _loginName, _password, AuthenticationTypes.ReadonlyServer);

searcher.SearchRoot = rootEntry;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(sAMAccountName=" + filter.Split('\\')[1] + ")(objectClass=user))";
searcher.PropertiesToLoad.Add("memberOf");
searcher.PropertiesToLoad.Add("displayname");

SearchResult sr = searcher.FindOne();
DirectoryEntry userDirectoryEntry = result.GetDirectoryEntry();
userDirectoryEntry.RefreshCache(new string[] { "tokenGroups" });

foreach (byte[] byteEntry in userDirectoryEntry.Properties["tokenGroups"])
{
   if (CompareByteArrays(byteEntry, objectSid))
   {
         isMember = true;
         break;
   }
}

It's a mix of this and this link, where objectSid is the objectSID of the group which I find by name.

Thanks a lot for your help!

于 2014-12-05T14:59:37.163 に答える