仅在 web.config 终结点绑定配置中拥有自定义用户名验证程序就足够了吗?
本文关键字:程序 验证 用户 自定义 config web 结点 绑定 拥有 配置 仅在 | 更新日期: 2023-09-27 17:56:16
我有一个客户用户名/密码验证器。 在 web.config 的终结点绑定配置属性中将其包含在 web.config 中是否足够,或者我是否需要在 Service 方法中显式调用它。 我注意到当我不称它为服务操作时,它不会被调用。 我做错了什么吗?
这就是我定义绑定部分的方式:
<bindings>
<wsHttpBinding>
<binding name="CustomAuthentication">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
这是我定义服务节点的方式:
<service behaviorConfiguration="CustomValidator" name="Test.TestService">
我的端点属性具有其绑定配置 = "自定义身份验证"
这就是我在服务行为中定义行为的方式:
<behavior name="CustomValidator">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="Test.CustomUserNameValidator, FuzionSync"/>
<serviceCertificate findValue="MyWebSite" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
</serviceCredentials>
<serviceMetadata httpGetEnabled="True"/>
</behavior>
当我运行 wcf 测试客户端来调用服务调用时,它甚至不调用 Validate 方法。 我让它调用的唯一方法是将它放在要显式调用的操作中。
需要在绑定配置和服务行为中指定此项。这是我们的一个项目中的样子(重要部分clientCredentialType="UserName"
和<serviceCredentials>
元素):
<bindings>
<wsHttpBinding>
<binding name="SSLWithCustomAuthentication">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None" />
<message clientCredentialType="UserName"
negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="customAuthenticationBehavior">
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="Namespace.YourValidator, AssemblyName"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
然后让您的服务使用 behaviorConfiguration="customAuthenticationBehavior"
.
请注意,我认为 WCF 不允许在没有 SSL 的情况下使用用户名身份验证。