[英]WCF Mixed authentication UserName and WIndows
可以使用 2 種類型的身份驗證:windows 和 wcf 中的用戶名,使用消息安全模式和證書進行身份驗證。 我的用戶名身份驗證 cfg/代碼看起來:
服務器配置:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceCredentialsBehavior">
<serviceCredentials>
<serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" />
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Util.CustomUserNameValidator, Util" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceCredentialsBehavior" name="Service">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="MessageAndUserName">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client/>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
客戶端配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="LocalCertValidation">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService" >
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:48097/WCFServer/Service.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService"
contract="ServiceReference1.IService"
name="WSHttpBinding_IService" behaviorConfiguration="LocalCertValidation">
<identity>
<dns value ="cool" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
改什么,服務器知道windows身份那個訪問嗎?
有趣的問題,如果您真的需要混合身份驗證,您可以嘗試將傳輸設置為一種身份驗證類型。 和消息一樣,我不知道這在實踐中是否可行:但考慮到您可以單獨配置它們,這似乎是合理的:)
您可以查看是否可以為綁定設置類似於下面的內容以獲取 windows 憑據(wsHttpBinding 可以處理 windows 憑據)。
<security mode="Transport">
<transport clientCredentialType="Whatever your authentication method is" />
<message clientCredentialType="Windows" />
</security>
如果你嘗試它,讓我知道它是否有效!
編輯:
哦,根據文檔,可以進行混合身份驗證。 您必須將模式設置為“混合”,因此配置可能如下所示:
<security mode="mixed">
<transport clientCredentialType="Whatever your authentication method is" />
<message clientCredentialType="Windows" />
</security>
從文檔中:
混合安全。 混合安全性為您提供兩全其美的優勢:傳輸安全性確保消息的完整性和機密性,而用戶憑據和聲明被封裝在每條消息中,就像消息安全性一樣。 這允許您使用嚴格的傳輸安全機制無法使用的各種用戶憑據,並利用傳輸安全的性能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.