【问题标题】:Active Directory nested groupsActive Directory 嵌套组
【发布时间】:2011-07-16 00:40:26
【问题描述】:

我有一个 C# 4.0 程序正在运行,可以检索特定 AD 组的所有成员。在此 AD 组中是包含其他成员的其他 AD 组。我需要我的程序来识别它是一个组并检索该组中的成员。

我知道我需要编写一个递归程序,但我希望有人可能已经这样做了。如果没有,有人可以告诉我 AD 属性来识别该成员实际上是一个组吗?

【问题讨论】:

标签: c# active-directory


【解决方案1】:

由于您使用的是 .NET 3.5 及更高版本,因此您应该查看 System.DirectoryServices.AccountManagement (S.DS.AM) 命名空间。在此处阅读所有相关信息:

基本上,您可以定义域上下文并在 AD 中轻松找到用户和/或组。另外:GroupPrincipal 有一个名为 GetMembers 的方法,它将列出该组的所有成员 - 可选地,它会为您递归地这样做!

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find the group you're interested in
GroupPrincipal myGroup = GroupPrincipal.FindByIdentity(ctx, "SomeGroup");

// if you found it - get its members
if (myGroup != null)
{
   // if your call the GetMembers, you can optionally specify a "Recursive" flag - done here
   var allMembers = myGroup.GetMembers(true);
}

新的 S.DS.AM 让在 AD 中与用户和组一起玩变得非常容易!

【讨论】:

  • 感谢您提供有关 S.DS.AM 的提示。它只是让我免去了编写递归程序的痛苦!!!!
  • GetMembers(true) 有一个限制,例如Domain Users 根本不返回。为了得到它们,你必须递归调用GetMembers(false)
  • @WernfriedDomscheit 还有什么限制?
  • 我不知道GetMembers(true)GetMembers(false) 之间的确切区别。但我注意到没有返回“域用户”,这促使我使用 false 而不是 true
  • @WernfriedDomscheit:这可能是所谓的“主要组”,实际上这些“GetMembers”调用中的任何一个都不会返回......
【解决方案2】:

假设您在 ActiveDirectory 中使用 LDAP 视图,您要查找的属性称为“objectClass”。我相信,一个组的对象类为“groupOfNames”;可能是“组”。或者,只需查看对象是否有任何“成员”,无论对象类如何,如果有,则假设它是某种组并递归。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多