簡體   English   中英

在每次調用時重新驗證WCF UserNamePasswordValidator上的憑據

[英]Revalidate Credentials on WCF UserNamePasswordValidator on each call

我在NetTcp上的WCF上使用自定義用戶名/密碼驗證程序,以驗證連接到我的WCF服務的客戶端。 我注意到的是,一旦客戶端通過身份驗證,再也不會再次驗證,這意味着如果我想撤消客戶端的訪問權限,我需要手動強制他斷開連接。

我的serviceHost配置如下所示:

_serviceHost.Description.Behaviors.Add(credentialsBehavior);
_serviceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
_serviceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = _userValidator;
_serviceHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
_serviceHost.Credentials.ServiceCertificate.SetCertificate(AppSettingsManager.I.CertificateStoreLocation, AppSettingsManager.I.CertificateStoreName, AppSettingsManager.I.CertificateFindBy, AppSettingsManager.I.CertificateFindValue);

和我的客戶使用ChannelFactory連接:

var client = new DuplexChannelFactory<T>(new InstanceContext(this), binding, endpointAddress);
client.Credentials.UserName.UserName = ConnectionProperties.Authentication.Credentials.Username;
client.Credentials.UserName.Password = ConnectionProperties.Authentication.Credentials.Password;
client.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = AppSettingsManager.I.CertificateValidationMode;

client.CreateChannel();

有沒有辦法在每次通話時或周期性地驗證客戶端憑據?

一般來說,調用后,服務器會自動關閉連接,這取決於綁定的以下參數。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-timeout-values-on-a-binding
當然,我們也可以在客戶端上手動關閉它。

client.Close()

另外,我無法理解你的觀點。 會話是連續的,您在調用服務之前已在代碼片段中設置了憑據。 你永遠不會再次獲得驗證是什么意思?
在我看來,如果要撤消客戶端的訪問權限,可以更改服務器端的驗證邏輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM