2017-09-04 220 views
0

我已經成功創建了一個WCF服務,它根據在IIS中配置的鏈驗證傳入客戶端證書。但是,由於這只是支持身份驗證的安全機制,我還需要Windows用戶調用我的WCF服務來處理授權。WCF客戶端證書驗證+ Windows身份驗證

通常提取Windows用戶時,你會做這樣的

ServiceSecurityContext.Current.WindowsIdentity.Name 

當我的服務配置了安全模式TransportWithMessageCredentials,在ServiceSecurityContextPrimaryIdentity將返回證書的SubjectNameWindowsIdentity將是空的。

看看客戶端配置,我指定的WsHttpBinding這樣

private static Binding GetHttpsBinding() 
{ 
    var binding = new WSHttpBinding(); 
    binding.Security.Mode = SecurityMode.TransportWithMessageCredential; 
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; 
    binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; 

    return binding; 
} 

客戶端證書被添加喜歡的代理客戶是這樣的:

private static void ApplyClientCertificate(HelloServiceClient client) 
{ 
    client.ClientCredentials.ClientCertificate.SetCertificate(

     storeLocation: StoreLocation.CurrentUser, 
     storeName: StoreName.My, 
     findType: X509FindType.FindBySubjectName, 
     findValue: "ClientCertificatesTest" 

    ); 
} 

切換兩個ClientCredentialType值使綁定看起來像這樣

private static Binding GetHttpsBinding() 
{ 
    var binding = new WSHttpBinding(); 
    binding.Security.Mode = SecurityMode.TransportWithMessageCredential; 
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; 
    binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; 

    return binding; 
} 

將如上所述解壓縮Windows憑據,但是當提交無效證書或根本沒有證書時也會被接受!因此認證要求未得到滿足。我還可以補充說,當這種配置方式在服務器端執行X509CertificateValidator時不會觸發,因此我懷疑沒有添加客戶端證書。

當然,必須有一些方法來添加客戶端證書進行身份驗證,並添加Windows憑據來處理WCF中的授權?有沒有其他方式可以添加證書,而不是將其添加到客戶端證書中?

提前致謝!

回答

0

因此,這個問題的答案將是創建自己的CustomBinding以獲得Windows Credentails和證書驗證。