如何查找用户是否具有服务中特定全局组的成员身份

本文关键字:全局 身份 成员 服务 何查找 查找 是否 用户 | 更新日期: 2023-09-27 18:35:10

我似乎无法找到某个用户是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,但事实并非如此。

如何查找用户是否具有服务中特定全局组的成员身份

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

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

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