【问题标题】:How do I query delegation properties of an active directory user account?如何查询 Active Directory 用户帐户的委派属性?
【发布时间】:2010-05-05 21:42:38
【问题描述】:

我正在编写一个实用程序来审核 WCF 服务的配置。为了正确地从客户端传递凭据,通过 WCF 服务返回到 SQL 后端,必须在 Active Directory 中配置用于运行服务的域帐户,并设置“信任此用户进行委派”(属性 ->“委派” “ 标签)。

使用 C#,我如何访问 Active Directory 中此选项卡上的设置。在过去的 5 个小时里,我一直试图在网络上找到它,但似乎找不到它。

这是我到目前为止所做的:

using (Domain domain = Domain.GetCurrentDomain())

{ Console.WriteLine(domain.Name);

// get domain "dev" from MSSQLSERVER service account
DirectoryEntry ouDn = new DirectoryEntry("LDAP://CN=Users,dc=dev,dc=mydomain,dc=lcl");
DirectorySearcher search = new DirectorySearcher(ouDn);

// get sAMAccountName "dev.services" from MSSQLSERVER service account
search.Filter = "(sAMAccountName=dev.services)";
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("userAccountControl");

SearchResult result = search.FindOne();
if (result != null)
{
    Console.WriteLine(result.Properties["displayName"][0]);
    DirectoryEntry entry = result.GetDirectoryEntry();

    int userAccountControlFlags = (int)entry.Properties["userAccountControl"].Value;
    if ((userAccountControlFlags & (int)UserAccountControl.TRUSTED_FOR_DELEGATION) == (int)UserAccountControl.TRUSTED_FOR_DELEGATION)
        Console.WriteLine("TRUSTED_FOR_DELEGATION");
    else if ((userAccountControlFlags & (int)UserAccountControl.TRUSTED_TO_AUTH_FOR_DELEGATION) == (int)UserAccountControl.TRUSTED_TO_AUTH_FOR_DELEGATION)
        Console.WriteLine("TRUSTED_TO_AUTH_FOR_DELEGATION");
    else if ((userAccountControlFlags & (int)UserAccountControl.NOT_DELEGATED) == (int)UserAccountControl.NOT_DELEGATED)
        Console.WriteLine("NOT_DELEGATED");

    foreach (PropertyValueCollection pvc in entry.Properties)
    {
        Console.WriteLine(pvc.PropertyName);
        for (int i = 0; i < pvc.Count; i++)
        {
            Console.WriteLine("\t{0}", pvc[i]);
        }
    }

}

}

“userAccountControl”似乎不是正确的属性。我认为它与“帐户”选项卡上的“帐户选项”部分相关联,这不是我们想要的,但这是迄今为止我得到的最接近的。

所有这一切的理由是:我们无权在 QA 或生产环境中设置服务,因此连同我们的书面说明(众所周知,仅部分遵循)我正在创建一个工具来审核设置(WCF 和 SQL)来确定设置是否正确。这将允许部署服务的人员运行此实用程序并验证所有设置是否正确 - 为我们节省数小时的头痛并减少部署期间的停机时间。

【问题讨论】:

    标签: active-directory


    【解决方案1】:

    可能为时已晚,但是嗯...找到了,所以我想我会分享它。

    有问题的属性称为“msDS-AllowedToDelegateTo”,它只会出现在配置了 SPN 值的帐户中,但它会为您提供一个完整的列表,其中列出了您的对象受信任用于委托的所有服务。

    希望这可以避免其他人不得不花几个小时阅读 kerberos 规范。

    【讨论】:

      【解决方案2】:

      好吧,我错了。当我第一次运行它时 userAccountControl 没有设置 TRUSTED_FOR_DELEGATION 。我不知道这是否是缓存问题。我添加了:

      entry.RefreshCache(new string[] {"userAccountControl"});

      以确保它不会缓存该值。我不知道这是否有效,但我添加了它以防万一。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-26
        • 1970-01-01
        • 2023-03-26
        相关资源
        最近更新 更多