【问题标题】:WCF CustomUserNamePasswordValidatorWCF 自定义用户名密码验证器
【发布时间】:2011-03-30 11:55:03
【问题描述】:

我在正确配置 WCF 以确保安全时遇到问题。下面的配置根本无法识别我正在尝试使用 CustomUserNamePasswordValidator。当我测试服务时,Validator 类会被忽略,就好像我从未配置过任何东西一样。任何人都可以在此配置中发现问题吗?任何帮助将不胜感激。

<?xml version="1.0"?>

  <service behaviorConfiguration="defaultServiceBehavior" name="SSAServices.SelfServiceAdvertiserService">
    <endpoint address="/2.4/SelfServiceAdvertiserService.svc" binding="wsHttpBinding" contract="SSAServiceContracts.Two_Four.ISelfServiceAdvertiserService" bindingConfiguration="serviceBinding" />
 </service>
    </services>
<bindings>
  <wsHttpBinding>
    <binding name="serviceBinding" >
      <security mode="Message">
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
    <behavior name="defaultServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="ServiceAuthenticationBase, SSAServices" />
      </serviceCredentials>
    </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
</system.webServer>

【问题讨论】:

  • 您有任何错误吗?该服务是否适用于此配置?
  • 该服务确实有效。它只是忽略了配置。
  • 这可能与我使用 VS 开发服务器有关吗?

标签: .net wcf wcf-security


【解决方案1】:

我认为问题的原因在这里:

customUserNamePasswordValidatorType="ServiceAuthenticationBase, SSAServices" 

你应该用它的命名空间和类名来声明你的类型:

customUserNamePasswordValidatorType="SSAServices.ServiceAuthenticationBase, SSAServices"

customUserNamePasswordValidatorType="类型,程序集"

希望这会有所帮助。

【讨论】:

  • @Impluse 可能是在正确的轨道上。 ServiceAuthenticationBase 类可能位于根命名空间中,并且需要在 customUserNamePasswordValidatorType 属性值中完全限定。检查此链接中的信息时,配置似乎正确:msdn.microsoft.com/en-us/library/aa702565.aspx
  • 是的,我确实尝试过。事实上,我可以用任何东西(“blahType”)代替这些值,而且我不会遇到任何失败。
  • 我唯一想尝试的是从头开始创建一个简单的 WCF 服务,并使用自定义验证器对其进行配置,如链接大纲所示。这是一种将验证所需的配置与当前服务配置隔离的方法。
【解决方案2】:

好的,我问了一个问题,看看这个绑定是否有效 - 因为我怀疑 - 但我还是发布我的答案,因为我看不到它是如何工作的。

消息安全需要加密,为此您还需要协商。所以你需要在beahviour部分为你的服务设置一个X509证书:

                     <serviceCredentials>
                            <serviceCertificate findValue="MyCert" storeLocation="LocalMachine"
                                 storeName="My" x509FindType="FindBySubjectName" />
                            <userNameAuthentication userNamePasswordValidationMode="Custom"
                                 customUserNamePasswordValidatorType="type, assembly" />
                     </serviceCredentials>

还要确保您也开启协商功能:

                <security mode="Message">
                    <message clientCredentialType="UserName" negotiateServiceCredential="true" />
                </security>

【讨论】:

  • 我已经尝试过设置它,但它似乎仍然绕过了配置。我已经按照您所说的方式进行了设置,当我查询 ServiceSecurityContext 时,我看到它是基于匿名访问进行身份验证的。我不确定这里有什么问题。我已经阅读了几个示例,但没有一个真正显示出与我正在使用的配置不同的配置。
猜你喜欢
  • 2011-10-23
  • 1970-01-01
  • 2021-06-30
  • 1970-01-01
  • 1970-01-01
  • 2020-10-16
  • 1970-01-01
  • 1970-01-01
  • 2012-11-13
相关资源
最近更新 更多