开发者

WCF customUserNamePasswordValidatorType

开发者 https://www.devze.com 2023-01-09 10:40 出处:网络
I have a customUserNamePasswordValidatorType and I want to set the service credentials in code in an IServiceBehavior ApplyDispatchBehavior() implementation.

I have a customUserNamePasswordValidatorType and I want to set the service credentials in code in an IServiceBehavior ApplyDispatchBehavior() implementation.

If I set it in code like this the problem is the validator never executes:

     serviceHostBase.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator =
            new BigIPUsernamePasswordValidator() ;
        serviceHostBase.Credentials.UserNameAuthentication.UserNamePasswordValidationMode =
            UserNamePasswordValidationMode.Custom;

If I set in the config then it does:

<serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="Custom" $customUserNamePasswordValidatorType="Quad.WCF.Security.BigIPUsernamePasswordValidator, Quad.WCF" /> </serviceCredentials>

The behavior is set as an attribute on the service class and if I set a breakpoint I can see the above code be开发者_如何学Going executed.

It's my understanding everything in the configuration should be able to be set in code. But this doesn't work when setting it in the IServiceBehavior ApplyDispatchBehavior() implementation.

Any one have any idea if this should be working or how I should be doing it differently through code?


I have implemented this and it works:

ServiceHost customServiceHost = new ServiceHost(type);
customServiceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = System.ServiceModel.Security.UserNamePasswordValidationMode.Custom;
customServiceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new MyCustomUserNameValidator();
customServiceHost.AddServiceEndpoint(typeof(IServiceContract), customBinding, "https://localhost:443");
customServiceHost.Open();

My custom validator is as simple as (example only, don't use one like this!)

public class MyCustomUserNameValidator: UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        // Example Only
        return;
    }
}

Do you get any specific exceptions or does it simply not appear to get called?

0

精彩评论

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

关注公众号