[英]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.