IsInRole获得新的安全令牌

Jef*_*eff 6 c# vb.net windows-principal isinrole windows-identity

我正在使用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")) { ...
Run Code Online (Sandbox Code Playgroud)

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...
Run Code Online (Sandbox Code Playgroud)

Jef*_*eff 0

事实证明我错了。是缓存,不过好像是在AD端。最终,在我创建新的 IdentityWindowsPrincipal 后,它会更新为正确的组成员身份。