开发者

What is going on with customUserNamePasswordValidatorType?

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. Unfor开发者_StackOverflow社区tunately, 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!


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜