2011-09-08 36 views
0

我正在寻找一种方式来通知正在运行的WPF应用程序新的模拟Windows用户已通过身份验证。我想我可以通过WCF & NetNamedPipeBinding来做到这一点,但我无法通过回调来传递模拟WindowsIdentity。我的情况如下:通过WCF回叫发送客户端的WindowsIdentity或WindowsPrincipal/IPrincipal?

WPF客户端身份验证应用程序(认证用户) - > WCF Windows服务(做Somestuff &通过回调通知给用户更改任何正在运行的应用程序) - > WPF运行的应用程序(获得通过回调新的WindowsIdentity ServiceSecurityContext刷新应用程序与基于IPrincipal的新权限)

我想我可以使用模拟来模拟新的身份验证用户,并使用ServiceSecurityContext.Current获取客户端应用程序的WindowsIdentity在回调到已经运行的WPF应用程序,但它doesn'似乎是可能的。

我基本上是试图做到以下几点:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/ee23ff54-80da-47f4-946d-5c2d77e81309

对我怎么能通知新的WindowsIdentity的一个已经运行的应用程序的任何想法?任何意见,将不胜感激。

+0

你实际上是试图冒充回调身份(这是引用论坛上发帖问的),或做你只是想把它作为数据发送? –

+0

在这一点上,我不介意做任何一个(无论哪个工作)。如果我可以将它作为数据发送或者在回调中模拟身份,那么解决方案将是有益的。 – CaMiX

回答

1

所以这couldn”用回调来完成,但我能够通过授权完成我想要的任务。我必须在目标应用程序上实现WCF服务,并让中间服务(WCF Windows服务)调用目标应用程序的WCF服务来通知/发送WindowsIdentity。

中间业务:

[OperationBehavior(Impersonation = ImpersonationOption.Required)] 
public void MyServiceMethod(){ 
    DoStuff(); 
    ServiceSecurityContext securityContext = ServiceSecurityContext.Current; 

    using (securityContext.WindowsIdentity.Impersonate()) { 
      EndpointAddress backendServiceAddress = new EndpointAddress("net.pipe://localhost/TargetAppService"); 

      ChannelFactory<IService> channelFactory = new ChannelFactory<IService>(new NetNamedPipeBinding(), backendServiceAddress); 
      IService channel = channelFactory.CreateChannel(); 

      channel.SetIdentity(); 
    } 
} 

目标应用的服务:

[OperationBehavior(Impersonation = ImpersonationOption.Allowed)] 
    public void SetIdentity() { 
     ServiceSecurityContext securityContext = ServiceSecurityContext.Current; 
     if (securityContext != null && securityContext.WindowsIdentity != null) { 
      Console.WriteLine("Identity's Username: "+securityContext.WindowsIdentity.Name); 
     } 
    } 
0

如果您只需要回拨客户端中新近通过身份验证的用户的信息,那么最好的办法就是传递一个包含相关信息的自定义DTO。

(允许通过身份验证的WindowsIdentity从服务发送到任意回调客户端将开放一些可怕的安全漏洞,这大概是为什么它不能在WCF工作)。

+0

不幸的是,我不能这样做,因为我不得不处理依赖于IPrinciapl(WindowsPrincipal)的不可修改的传统API。 – CaMiX

+0

他们是否只需要一个IPrincipal,还是他们确实需要一个WindowsPrincipal? –