【问题标题】:WindowsIdentity - Difference between Groups and ClaimsWindowsIdentity - 组和声明之间的区别
【发布时间】:2021-03-18 09:49:27
【问题描述】:

我正在尝试使用 SID-s 检查用户是否属于某些组。

我使用WindowsIdentity.Groups,但后来注意到有时它不显示用户属于管理员组。

搜索了一段时间后,我发现 WindowsIdentity.Claims 工作正常(结果中也包括管理员组)。
我在 Claims 上找不到合适的文档。

那么,WindowsIdentity 中的组和声明之间有什么区别,为什么组不显示管理员组而声明显示?
最后,我可以安全地使用声明而不是组吗?

这是我的代码:

var wi = WindowsIdentity.GetCurrent();

var sidToFind = "S-1-5-32-544"; // Hardcoded the sid of administrators group for demo, but in general this is a parameter of a function on my side

// This will NOT include the sid S-1-5-32-544
var groupSids= wi.Groups
    .Where(item => item.Value == sidToFind);

// This will include the sid S-1-5-32-544 and also all the other results that Groups provides.
var claimSids = wi.Claims
    .Where(item => item.Value == sidToFind));

【问题讨论】:

  • 如果您想通过 SID 检查特定用户属于某些组,this 会帮助您。

标签: c# .net windows-identity


【解决方案1】:

组和声明之间存在差异。

  • 组与 WORKGROUP 和 AD 一起使用
  • 声明与 Active Directory 联合身份验证服务一起使用

声明是检查用户身份的更复杂的方法,因为声明不仅存在于 ADFS,您还可以使用或创建额外的 claims token provider

当我们为 WindowsIdentity 调用 Groups 方法时,我们有限制:

//Ignore disabled, logon ID, and deny-only groups.

The role of claims

在基于声明的身份模型中,声明在 联合过程,它们是结果的关键组成部分 所有基于 Web 的身份验证和授权请求都是 决定。该模型使组织能够安全地进行项目 跨安全性的数字身份和权利或索赔 以标准化的方式和企业边界。

因此,如果您仅在 NTLM 中工作 - 您可以安全地使用群组,但如果您希望通过联合(例如 SharePoint、Google 等)工作 - 您必须使用声明。声明包含组,但组不包含声明。

要回答为什么看不到某个组的问题,您需要知道它的属性和位置。正如我在上面写的并给出了链接,获取组列表是有限制的。但是here我找到了这个信息:

SID Name Description
S-1-5-32-544 Administrators A built-in group. After the initial installation of the operating system, the only member of the group is the Administrator account. When a computer joins a domain, the Domain Admins group is added to the Administrators group. When a server becomes a domain controller, the Enterprise Admins group also is added to the Administrators group.

因此,如果您的本地管理员组被禁用 - 当您通过 WindowsIdentity 获取它时,即使该用户包含在其中,您也看不到它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-20
    • 2020-04-20
    • 2011-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 2011-05-23
    相关资源
    最近更新 更多