【发布时间】:2017-01-15 06:30:22
【问题描述】:
我正在使用 WindowsPrincipal 的 IsInRole 方法来检查 WPF 和 Winforms 应用程序中的组成员身份。我正在生成一个身份令牌,它可以用于任何 AD 用户(不一定是实际登录到计算机的用户 - 取决于我在做什么,我不一定要进行身份验证,我只使用基本信息级令牌(我认为它的正确名称是“身份令牌”)。
此代码第一次在特定计算机上运行时,操作系统会为指定的用户生成身份令牌。然后 IsInRole 函数使用该令牌来验证组成员身份。它很快,所以我真的很喜欢它。但是,创建 WindowsIdentity/WindowsPrincipal 的后续调用会引用现有令牌,而不是创建新令牌。我知道如何更新令牌的唯一方法是注销计算机或重新启动(这会清除令牌缓存)。有谁知道重置缓存身份令牌的更好方法?
示例代码 C#:
Using System.Security.Principal;
WindowsIdentity impersonationLevelIdentity = new WindowsIdentity("Some_UserID_That_Isn't_Me", null);
WindowsPrincipal identityWindowsPrincipal = new WindowsPrincipal(impersonationLevelIdentity);
If (identityWindowsPrincipal.IsInRole("AN_AD_GROUP")) { ...
VB:
Imports System.Security.Principal
Dim impersonationLevelIdentity = New WindowsIdentity("Some_UserID_That_Isn't_Me", Nothing)
Dim identityWindowsPrincipal = New WindowsPrincipal(impersonationLevelIdentity)
if identityWindowsPrincipal.IsInRole("AN_AD_GROUP") then...
【问题讨论】:
标签: c# vb.net windows-identity isinrole windows-principal