2011-09-08 66 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? –