C# 验证当前经过身份验证的windows用户是否具有委派权限
假设我有一个使用windows身份验证的WCF服务,我想模拟它们并调用另一个WCF服务,如下所示:C# 验证当前经过身份验证的windows用户是否具有委派权限,c#,wcf,windows-authentication,impersonation,C#,Wcf,Windows Authentication,Impersonation,假设我有一个使用windows身份验证的WCF服务,我想模拟它们并调用另一个WCF服务,如下所示: using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate()) { // call another WCF service } 我已经设置了所有配置设置,只要在客户端,它们包括以下行,就可以正常工作: client.ClientCredentials.Windows.AllowedImpersonationLeve
using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
// call another WCF service
}
我已经设置了所有配置设置,只要在客户端,它们包括以下行,就可以正常工作:
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;
但是,在尝试进行调用之前,如何验证用户令牌是否具有委派权限?i、 e.我不控制的客户机已设置AllowedPersonationLevel
如果他们没有设置它,就会抛出各种奇怪的异常(比如无法加载程序集X等)
理想情况下,我希望能够做到以下几点:
using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
if (UserDoesntHaveDelegationRights())
throw new SecurityException("No delegation rights");
// call another WCF service
}
请注意,WindowsIdentity.GetCurrent().ImpersonationLevel
始终等于TokenImpersonationLevel.Impersonation
,因此不幸的是,这不是一个选项。怎么办
if (WindowsIdentity.GetCurrent().ImpersonationLevel != TokenImpersonationLevel.Delegation) ...
这里的定义可能有些混乱。就windows标识而言,可以是:
- 模拟-服务可以在本地模拟用户
- 委派-服务可以远程模拟用户
TokenImpersonationLevel.Delegation
,但它被认为是一种安全风险,很少(如果有)使用<代码>令牌模拟级别。模拟是您可能获得的最高级别。
TokenImpersonationLevel。模拟
很有用。您仍然可以作为模拟用户连接到数据库或进行远程服务调用。但是远程服务(不在同一个框中)不能再次模拟用户。基本的经验法则是“模拟使两台机器能够跳跃”。如果用户的凭证必须“跳”得更远,它将失败
如果您需要在许多服务器之间传递用户的凭据,最好的选择是联合身份安全模型,如Windows身份基础(WIF)。请参阅。
是的,这是我的想法-但是WindowsIdentity.GetCurrent().ImpersonationLevel始终等于Impersonation