What is the best way to retrieve a WindowsIdentity from a ClaimsIdentity

喜欢而已 提交于 2019-12-06 05:51:04

问题


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;
    }
}
  1. Just call the constructor of WindowsIdentity with the upn:

    WindowsIdentity winId = new WindowsIdentity(upn);

  2. 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!


回答1:


  1. WindowsIdentity winId = S4UClient.UpnLogon(upn);

Used by Excel Services and PerformancePoint services.

Its cached once used. Has some other checks against it as well.



来源:https://stackoverflow.com/questions/5040564/what-is-the-best-way-to-retrieve-a-windowsidentity-from-a-claimsidentity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!