从 ClaimsIdentity 检索 WindowsIdentity 的最佳方法是什么
到目前为止,我找到了两种从 ClaimsIdentity 获取 WindowsIdentity 对象的解决方案。 首先,我提取用户主体名称 (upn)。
ClaimsIdentity ci = (ClaimsIdentity) Thread.CurrentPrincipal.Identity;
string upn = null;
foreach (Claim c in ci.Claims)
{
if (c.ClaimType == ClaimTypes.Upn)
{
upn = c.Value;
break;
}
}
只需使用 upn 调用 WindowsIdentity 的构造函数即可:
WindowsIdentity winId = new WindowsIdentity(upn);
使用 Windows 令牌服务 (c2WTS) 声明:
WindowsIdentity winId = S4UClient.UpnLogon(upn);
解决方案 1 对我来说似乎是更简单、更容易的解决方案,但我不明白 c2WTS 的目的?
有什么建议吗?
tnx!
So far I found out two solutions to get a WindowsIdentity object from a ClaimsIdentity.
First I extract the user principal name (upn).
ClaimsIdentity ci = (ClaimsIdentity) Thread.CurrentPrincipal.Identity;
string upn = null;
foreach (Claim c in ci.Claims)
{
if (c.ClaimType == ClaimTypes.Upn)
{
upn = c.Value;
break;
}
}
Just call the constructor of WindowsIdentity with the upn:
WindowsIdentity winId = new WindowsIdentity(upn);
Use Claims to Windows Token Service (c2WTS):
WindowsIdentity winId = S4UClient.UpnLogon(upn);
Solution 1 seems for me the simpler and easier solution, but then i don't understand the purpose of the c2WTS?
Any suggestions?
tnx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WindowsIdentity winId = S4UClient.UpnLogon(upn);
由 Excel Services 和 PerformancePoint 服务使用。
一旦使用就会被缓存。还有一些其他检查。
WindowsIdentity winId = S4UClient.UpnLogon(upn);
Used by Excel Services and PerformancePoint services.
Its cached once used. Has some other checks against it as well.