Gar*_*eth 3 c# impersonation wcf windows-authentication
鉴于我有一个使用Windows身份验证的WCF服务,我想模仿它们并调用另一个WCF服务,如下所示:
using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
// call another WCF service
}
Run Code Online (Sandbox Code Playgroud)
我已经设置了所有配置设置,它工作正常,只要在客户端,它们包括以下行:
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;
Run Code Online (Sandbox Code Playgroud)
但是,在尝试拨打用户令牌具有委派权限的呼叫之前,我该如何验证?即我无法控制的客户端设置了AllowedPersonationLevel?
如果他们没有设置它,会抛出各种奇怪的异常(比如无法加载程序集X等).
理想情况下,我希望能够做到以下几点:
using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
if (UserDoesntHaveDelegationRights())
throw new SecurityException("No delegation rights");
// call another WCF service
}
Run Code Online (Sandbox Code Playgroud)
请注意,WindowsIdentity.GetCurrent().ImpersonationLevel 总是等于TokenImpersonationLevel.Impersonation,所以不幸的是,这不是一个选项.
定义中可能存在一些混淆.在模拟级别方面,Windows标识可以是:
委派的能力如此强大,以至于它在Active Directory中受到高度限制:
以下是如何启用委派帐户.它需要Active Directory域管理员才能进行更改.我曾经工作的每个公司环境都有一个不允许委托的政策.
回到你的问题:
因此,虽然TokenImpersonationLevel.Delegation存在,但它被认为是安全风险,并且很少(如果曾经)使用过.TokenImpersonationLevel.Impersonation是你可能获得的最高水平.
TokenImpersonationLevel.Impersonation很有用.您仍然可以作为模拟用户连接到数据库或进行远程服务调用.但是远程服务(不在同一个盒子上)不能再次冒充用户.基本的经验法则是"假冒可以使两台机器跳跃".如果用户的凭据必须"跳"得更远,它将失败.
如果需要在许多服务器之间传递用户凭据,则最佳选择是联合安全模型,例如Windows Identity Foundation(WIF).请参阅Active Directory中的身份管理.
| 归档时间: |
|
| 查看次数: |
3910 次 |
| 最近记录: |