2017-05-15 45 views
0

我有一個WCF服務,託管在WindowService中,使用nettcpbinding,如果發件人屬於特定的AD組,需要在其中執行檢查。針對服務器端的ActiveDirectory組的WCF調用程序進行驗證

可能嗎?如果是這樣,怎麼樣?

+0

這是可能的,但實現取決於應用程序的拓撲結構(爲前充足,服務如何託管:IIS,Windows服務,控制檯應用程序e.t.c.是在同一網絡/域中訪問服務的客戶端,是windows身份驗證Kerberos或NTLM e.t.c.)。 –

+0

@lonut Ungureanu - WindowsService(更新了問題) – Joezer

回答

1

那麼假設WCF客戶端和服務器在同一個域,你可以做這樣的事情:

在客戶端,您允許使用Windows身份驗證客戶端:

using System.Security.Principal; 
.... 
ServiceReference.ServiceClient client = new ServiceReference.ServiceClient(); 
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Identification; 

在服務器端,你retrive來電Windows標識和測試它是否屬於組:

WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity; 
    WindowsPrincipal windowsPrincipal = new WindowsPrincipal(callerWindowsIdentity); 
    var isInRole = windowsPrincipal.IsInRole("Users"); 
相關問題