【问题标题】:How to find if a user has a membership to a specific Global Group in a service?如何查找用户是否具有服务中特定全局组的成员资格?
【发布时间】:2014-12-24 17:14:29
【问题描述】:

我似乎无法找到某个用户是 DeployUsersProduction 组的成员。到目前为止,这是我所拥有的:

[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public Modes GetDeployMode()
{
    bool isProd = false;

    WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
    if (windowsIdentity == null || windowsIdentity.Groups == null) { return Modes.DUS; }

    foreach (IdentityReference identityReference in windowsIdentity.Groups)
    {
        try
        {
            var reference = identityReference;
            string group = reference.Translate(typeof (NTAccount)).Value.Trim();

            if (!String.Equals(group, "DeployUsersProduction", StringComparison.OrdinalIgnoreCase)) { continue; }

            isProd = true;
            break;
        }
        catch (Exception ex)
        {
            // Silent catch due to the [Some or all identity references could not be translated]
            // error that sometimes occurs while trying to map an identity.
        }
    }

    return isProd ? Modes.Prod : Modes.DUS;
}

据我所知,我的所有配置、spn、db、perms 等都是正确的。我只有一个用户应该返回 Modes.Prod 而不是。

【问题讨论】:

  • 你有没有想过尝试使用PrincipalContextPrincipal.GetGroups
  • 嗯 ...当我尝试添加 System.DirectoryServices.AccountManagement 时,它甚至无法识别 DirectoryServices 命名空间。
  • 您需要通过使用和右键单击引用来添加引用-->添加...等
  • 呃……忘了那部分。在Principal 下面我没有看到GetGroups() 方法,只有FindByIdentity()
  • 您是否查看了我最初评论中的链接..?

标签: c# asp.net wcf silverlight-5.0 windows-security


【解决方案1】:

答案不是我的方法错误,而是我需要在我正在搜索的组前面加上它的域:

if (!String.Equals(group, @"DOMAIN\DeployUsersProd", StringComparison.OrdinalIgnoreCase)) { continue; }

特别感谢 @DJ KRAZE 提供的链接,这些链接让我编写了自己的输出组的控制台应用程序,以便我弄清楚这一点!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    相关资源
    最近更新 更多