【发布时间】:2013-03-01 01:51:23
【问题描述】:
鉴于我有一个使用 Windows 身份验证的 WCF 服务,并且我想模拟它们并调用另一个 WCF 服务,如下所示:
using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
// call another WCF service
}
我已经设置了所有的配置设置,它工作正常,只要在客户端,它们包括以下行:
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;
但是,在尝试调用用户令牌是否具有委托权限之前,我该如何验证?即我无法控制的客户端设置了 AllowedPersonationLevel?
如果他们没有设置它,就会抛出各种奇怪的异常(比如无法加载程序集 X 等)。
理想情况下,我希望能够做到以下几点:
using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
if (UserDoesntHaveDelegationRights())
throw new SecurityException("No delegation rights");
// call another WCF service
}
请注意,WindowsIdentity.GetCurrent().ImpersonationLevel 始终等于 TokenImpersonationLevel.Impersonation,因此很遗憾,这不是一个选项。
【问题讨论】:
标签: c# wcf windows-authentication impersonation