检查Active Directory对象的授权

时间:2011-07-22 05:46:25

标签: c# .net security active-directory authorization

我想测试一个任意用户是否具有对特定Active Directory对象的属性的写访问权。我认为解决方案的一部分似乎是这样的:

NTAccount Account = new NTAccount("Domain\\XYZ");
SecurityIdentifier Sid =
(SecurityIdentifier)Account.Translate(typeof(SecurityIdentifier));

这似乎允许我从用户的字符串表示中获得具体的表示。我认为的另一个难题是:

string strMemberString = "LDAP://OU=Test,DC=Domain,DC=local";
DirectoryEntry computers = new DirectoryEntry();
computers.Path = strMemberString;
computers.Options.SecurityMasks = SecurityMasks.Owner | SecurityMasks.Group
| SecurityMasks.Dacl | SecurityMasks.Sacl;

foreach (DirectoryEntry computer in computers.Children)
{
   if (computer.Name == "CN=Test")
   {
      ActiveDirectorySecurity sdc = computer.ObjectSecurity;
      //...

不知道从哪里去。我该如何完成?我应该采用完全不同的方式吗?我正在使用.net 4.0。

我希望解决方案完全是BCL代码,而不是PInvoke或WMI。

2 个答案:

答案 0 :(得分:0)

我认为最好的方法是查找一个类,该类提供“有效权限”,如AD对象安全选项卡中高级​​对话框的选项卡所示:

enter image description here

它还存在一个名为ACLDiag.exe的命令行工具,可以执行您想要的操作。


(编辑)的 要查找用户所属的群组,您可以

  • 编写一个递归查询程序,它在大型组织中表现不佳。

  • 使用名为“LDAP_MATCHING_RULE_IN_CHAIN”的特殊匹配规则(请参阅Search Filter Syntax for more information)。我在this other question中举了一个例子。它有点长,但据我所知,这是检索安全和通讯组的唯一方法。

  • 使用“tokenGroups”属性。它是一个计算属性,用于保存用户所属的每个SecurityGroup的ID,包括间接组。我认为这是你可以使用的那个,它提供了UserPrincipal.GetAuthorizationGroups方法(在System.DirectoryServices.AccountManagement命名空间中,并在.Net 3.5中引入)

答案 1 :(得分:0)

您需要检查allowedAttributesEffective属性。