如何冒充客户端的wcf调用

时间:2009-07-03 14:53:33

标签: wcf security impersonation

我需要一些关于WCF和授权的帮助。 目前我有一个客户端,它在Windows服务中托管作为.NET远程处理对象,并且正在调用WCF服务(使用wshttpbinding)。 WCF服务正在使用基于消息的安全性的Windows身份验证。

Windows服务正在使用特殊帐户运行。 一旦客户端调用到达.NET远程处理对象,thread.currentprincipal就会被设置为客户端提供的主体,因此所有操作都是使用客户端的凭据执行的。 到目前为止没问题,现在我的问题出现了: 应使用客户端用户凭据调用wcf服务。 Afaik WCF使用WindowsIdentity.GetCurrent创建呼叫的授权信息。由于Thread.CurrentPrincipal拥有我想用于调用的身份,我认为(hread.CurrentPrincipal.Identity为WindowsIdentity).Impersonate()完成这项工作。

但是现在我得到的不是WCF安全异常这个异常: System.ComponentModel.Win32Exception:安全包中没有可用的凭据

调用堆栈:    at System.IdentityModel.SspiWrapper.AcquireCredentialsHandle(String package,CredentialUse intent,AuthIdentityEx& authdata)    at System.ServiceModel.Security.SecurityUtils.GetCredentialsHandle(String package,NetworkCredential credential,Boolean isServer,String [] additionalPackages)    在System.ServiceModel.Security.SecurityUtils.GetCredentialsHandle(SecurityBindingElement sbe,ClientCredentials clientCredentials)    在System.ServiceModel.Security.SecurityUtils.GetCredentialsHandle(SecurityBindingElement sbe,BindingContext context)    在System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.OnOpening()    在System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpening()    在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)    在System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan超时)    在System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider,TimeSpan timeout)    在System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan超时)    在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)    在System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan超时)    在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)    在System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel频道,TimeSpan超时)    在System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan超时,CallOnceManager级联)    在System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan超时)    在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)    在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs)    在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)    在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

是的,任何帮助 马丁

编辑:我犯了一个错误导致了这个异常,因为我在模仿后忘了创建channelfactory,但是现在我又得到另一个例外,我不确定如何处理它: System.IO.FileLoadException:无法加载文件或程序集'System.IdentityModel.Selectors,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'或其依赖项之一。未提供所需的模拟级别,或者提供的模拟级别无效。 (来自HRESULT的异常:0x80070542)

1 个答案:

答案 0 :(得分:2)

必须允许Windows服务正在运行的用户模拟用户。

有一项名为“认证后模拟客户端”的权利

http://blogs.technet.com/askperf/archive/2007/10/16/wmi-troubleshooting-impersonation-rights.aspx

相关问题