H
Houston
I'm trying to use basicHttpBinding with TransportWithMessageCredential and a
custom username validator. The validator is not being executed. I'm sure
I've got a config problem but can't see where. web.config and code follow.
Thanks in advance for any help you can offer.
--Houston
--------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfig">
<security mode="TransportWithMessageCredential" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ToteServiceBehavior"
name="ToteServiceLibrary.ToteDataService">
<endpoint address="mex" binding="mexHttpsBinding"
contract="IMetadataExchange" />
<endpoint address="basic" binding="basicHttpBinding"
bindingConfiguration="basicHttpBindingConfig"
contract="ToteServiceLibrary.iToteDataService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ToteServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<serviceCertificate findValue="snark.mydomain.com"
storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
includeWindowsGroups="false"
customUserNamePasswordValidatorType="ToteServiceLibrary.CustomUserNameValidator,ToteServiceLibrary" />
<windowsAuthentication includeWindowsGroups="false" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\inetpub\trace\SecureToteService.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
namespace ToteServiceLibrary
{
public bool TestSuccess()
{
return true;
}
public bool TestFailure()
{
return false;
}
public class CustomUserNameValidator : UserNamePasswordValidator
{
public override void Validate(String userName, String password)
{
if (null == userName || null == password)
{
throw new SecurityTokenException("Invalid Token");
}
if (!(userName == "user" && password == "password"))
{
throw new SecurityTokenException("Invalid Token");
}
}
}
custom username validator. The validator is not being executed. I'm sure
I've got a config problem but can't see where. web.config and code follow.
Thanks in advance for any help you can offer.
--Houston
--------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfig">
<security mode="TransportWithMessageCredential" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ToteServiceBehavior"
name="ToteServiceLibrary.ToteDataService">
<endpoint address="mex" binding="mexHttpsBinding"
contract="IMetadataExchange" />
<endpoint address="basic" binding="basicHttpBinding"
bindingConfiguration="basicHttpBindingConfig"
contract="ToteServiceLibrary.iToteDataService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ToteServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<serviceCertificate findValue="snark.mydomain.com"
storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
includeWindowsGroups="false"
customUserNamePasswordValidatorType="ToteServiceLibrary.CustomUserNameValidator,ToteServiceLibrary" />
<windowsAuthentication includeWindowsGroups="false" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\inetpub\trace\SecureToteService.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
namespace ToteServiceLibrary
{
public bool TestSuccess()
{
return true;
}
public bool TestFailure()
{
return false;
}
public class CustomUserNameValidator : UserNamePasswordValidator
{
public override void Validate(String userName, String password)
{
if (null == userName || null == password)
{
throw new SecurityTokenException("Invalid Token");
}
if (!(userName == "user" && password == "password"))
{
throw new SecurityTokenException("Invalid Token");
}
}
}