tags:

views:

31

answers:

2

I have been creating a custom username/password validator for a WCF service and ran across the configuration item customUserNamePasswordValidatorType. I've been able to make my code work by following examples, but I just don't understand what is going on. Unfortunately, the MSDN article doesn't provide much detail.

This is the sample that Microsoft provides:

<serviceCredentials>
  <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Microsoft.ServiceModel.Samples.CalculatorService.CustomUserNameValidator, service" />
</serviceCredentials>

I'm trying to understand what the two parameters are to customUserNamePasswordValidatorType: "Microsoft.ServiceModel.Samples.CalculatorService.CustomUserNameValidator" and "service".

Can someone please help me understand what these parameters mean?

Thanks!

+2  A: 

The first part is the class name fully qualified by the namespace, the second is the assembly the class is in.

Steve Ellinger
Thanks for the help!
Jacob
+1  A: 

This first parameter is the fully qualified name of the function the custom validation. The second parameter is the name of the assembly that function is contained in.

Taken from a much better example of how to use custom validators (modified slightly to fit your example)

namespace Microsoft.ServiceModel.Samples.CalculatorService
{
    public class CustomUserNameValidator : UserNamePasswordValidator
    {
     // This method validates users. It allows in two users, 
     // test1 and test2 with passwords 1tset and 2tset respectively.
     // This code is for illustration purposes only and 
     // MUST NOT be used in a production environment because it 
     // is NOT secure.
     public override void Validate(string userName, string password)
     {
      if (null == userName || null == password)
      {
       throw new ArgumentNullException();
      }

      if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset"))
      {
       throw new FaultException("Unknown Username or Incorrect Password");
       }
      }
     }
}

The above would be complied inside a assembly named service.

Scott Chamberlain
Great! Thank you!
Jacob