Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1106559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:48:42+00:00 2026-05-17T01:48:42+00:00

I’m working on custom WCF authentication and authorization and found some articles about UserNamePasswordValidator

  • 0

I’m working on custom WCF authentication and authorization and found some articles about UserNamePasswordValidator and ServiceAuthorizationManager.

I also found clues about using a custom System.ServiceModel.ServiceAuthenticationManager (dead link ), but msdn does not tell a lot about it ( http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceauthenticationmanager.aspx ).

So here I am: anyone knows more about ServiceAuthenticationManager ?

In general, how would you set up custom WCF authentication ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:48:42+00:00Added an answer on May 17, 2026 at 1:48 am

    You’re right, the documentation on this is no help at all.

    The way I have used this class is as follows. Override the Authenticate() method to:

    1. Pull the authentication tokens (e.g. username/password) out of the incoming message
    2. Authenticate the tokens and use them to create an IPrincipal object. This will be the principal that is used during the invocation of the service operation.
    3. Add the IPrincipal object to the message.Properties collection so it can be used later in the WCF processing pipeline

    You can’t just set the thread principal at this point as it is changed later on by WCF.

    The code in the ServiceAuthenticationManager.Authenticate() methods would look something like this:

    public override ReadOnlyCollection<IAuthorizationPolicy> Authenticate(ReadOnlyCollection<IAuthorizationPolicy> authPolicy, Uri listenUri, ref Message message)
    {
       int tokenPosition = message.Headers.FindHeader("Token", "http://customnamespace.org");
       string token = message.Headers.GetHeader<string>(tokenPosition);
    
       IPrincipal user = new CustomPrincipal(token);
    
       message.Properties["Principal"] = user;
    
       return authPolicy;
    }
    

    Then you add a custom authorization policy that

    1. Retrieves the IPrincipal from the message (using the System.ServiceModel.EvaluationContext.Current.IncomingMessageProperties collection).
    2. Pushes the IPrincipal into the EvaluationContext.Properties collection
    3. Makes claims based on the IPrincipal.IsInRole() method

    The code in the IAuthorizationPolicy() method would look like

    public bool Evaluate(EvaluationContext evaluationContext, ref object state)
    {
        IPrincipal user = OperationContext.Current.IncomingMessageProperties["Principal"] as IPrincipal;
        evaluationContext.Properties["Principal"] = user;
        evaluationContext.Properties["Identities"] = new List<IIdentity> { user.Identity };
    
        IList<Claim> roleClaims = this.GetRoleClaims(user);
    
        evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer, roleClaims));
    
        return true;
    }
    

    In the service behaviour configuration, you need to set principalPermissionMode=”Custom” in order for WCF to set the IPrincipal as the principal on the executing thread for the actual service operation invocation.

    <serviceAuthorization principalPermissionMode="Custom"...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.