【发布时间】: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