简体   繁体   English

Active Directory 嵌套组

[英]Active Directory nested groups

I have a C# 4.0 program working that retrieves all the members for a specific AD group.我有一个 C# 4.0 程序正在运行,可以检索特定 AD 组的所有成员。 In this AD group are other AD groups containing other members.在此 AD 组中是包含其他成员的其他 AD 组。 I need my program to identity that it is a group and retrieve the members in that group.我需要我的程序识别它是一个组并检索该组中的成员。

I know I need to write a recursive program but I was hoping somebody out there might have already done it.我知道我需要编写一个递归程序,但我希望那里有人可能已经完成了。 If not, could somebody tell me the AD property attribute to identify that the member is actual a group?如果不是,有人可以告诉我 AD 属性来识别该成员实际上是一个组吗?

Since you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace.由于您使用的是 .NET 3.5 及更高版本,因此您应该查看System.DirectoryServices.AccountManagement (S.DS.AM) 命名空间。 Read all about it here:在这里阅读所有相关信息:

Basically, you can define a domain context and easily find users and/or groups in AD.基本上,您可以定义域上下文并在 AD 中轻松找到用户和/或组。 Also: the GroupPrincipal has a method called GetMembers which will list all members of that group - optionally, it will do so recursively for you!另外: 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);
}

The new S.DS.AM makes it really easy to play around with users and groups in AD!新的 S.DS.AM 使得在 AD 中与用户和组一起玩变得非常容易!

Assuming you're using the LDAP view into ActiveDirectory, the attribute you're looking for is called "objectClass".假设您在 ActiveDirectory 中使用 LDAP 视图,您要查找的属性称为“objectClass”。 A group shows up with an objectClass of "groupOfNames", I believe;我相信,一个组的对象类为“groupOfNames”; possibly "group".可能是“组”。 Alternatively, just look to see if the object has any "member"s, regardless of object class, and if it does, assume it's some sort of group and recurse.或者,只需查看 object 是否有任何“成员”,无论 object class 是什么,如果有,假设它是某种组并递归。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM