假设我在
OU=Groups,DC=contaco,DC=com,ct
我可以找到子 OU 中的所有组,但找到用户“bobdole”所属的所有组的唯一方法是查看每个组,看看他是否在“成员”字段中。
不幸的是,当我查看用户“bobdole”时,我没有看到包含所有这些列表的 memberOf 字段,因此我必须枚举每个组\分布列表并查看他是哪个成员。
难道就没有更有效的方法来做到这一点吗?我在c#
这将返回用户所属的所有角色(组)。
public string[] GetRolesForUser(DirectoryEntry user)
{
user.RefreshCache(new string[] { "tokenGroups" });
var irc = new IdentityReferenceCollection(user.Properties["tokenGroups"].Count);
foreach (byte[] sidBytes in user.Properties["tokenGroups"])
irc.Add(new SecurityIdentifier(sidBytes, 0));
var coll = new StringCollection();
irc = irc.Translate(typeof(NTAccount));
foreach (var ir in irc)
{
if (ir is NTAccount)
{
coll.Add(ir.ToString());
}
}
var accounts = new string[coll.Count];
coll.CopyTo(accounts, 0);
return accounts;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)