私は何日もの間、カスタムUserNamePasswordValidatorを.Net 4.5WCFWebサービスのnetHttpsBindingで動作させるように努めてきました。私の問題は、バリデーターが呼び出されたり強制されたりすることがないため、任意のクレデンシャル(またはクレデンシャルなし)がアクセスを許可することです。
wsHttpBindingにほぼ同じ構成を使用でき、それが機能するため、構成が正しいと確信しています。これがweb.configです...
<services>
<service name="MyNamespace.MyService" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="wsHttpBinding" contract="MyNamespace.IMyService" />
<!-- This one doesn't authenticate
<endpoint address="" binding="netHttpsBinding" contract="MyNamespace.IMyService" />
-->
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding>
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
<netHttpsBinding>
<binding>
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</netHttpsBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyNamespace.MyValidator, MyAssembly"/>
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
それが重要な場合のバリデーターは次のとおりです...
using System.IdentityModel.Selectors;
using System.ServiceModel;
namespace MyNamespace
{
public class MyValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (null == userName || null == password)
throw new FaultException("Username or Password were not set.");
if (!(userName == "MyUser" && password == "MyPassword"))
throw new FaultException("Unknown Username or Incorrect Password");
}
}
}
UserNamePasswordValidatorがnetHttpsBindingで機能しない理由を誰かが知っていますか?または私が間違っていることは何ですか?