Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF - ValidateUserNamePasswordCore() method in custom UserNameSecurityTokenAuthenticator not called
    primarykey
    data
    text
    <p>I have defined an own <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicecredentials.aspx" rel="nofollow">ServiceCredentials</a> provider:</p> <pre><code>class PasswordServiceCredentials : ServiceCredentials { } </code></pre> <p>That provider generates a custom <a href="http://msdn.microsoft.com/en-us/library/system.identitymodel.selectors.securitytokenmanager.aspx" rel="nofollow">SecurityTokenManager</a> in <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicecredentials.createsecuritytokenmanager" rel="nofollow">CreateSecurityTokenManager()</a> method when I start my <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx" rel="nofollow">ServiceHost</a>:</p> <pre><code>public override SecurityTokenManager CreateSecurityTokenManager() { if (this.UserNameAuthentication.UserNamePasswordValidationMode == UserNamePasswordValidationMode.Custom) { return new PasswordSecurityTokenManager(this); } return base.CreateSecurityTokenManager(); } </code></pre> <p>The <em>PasswordSecurityTokenManager</em> class:</p> <pre><code>class PasswordSecurityTokenManager : ServiceCredentialsSecurityTokenManager { } </code></pre> <p>The instance generates a custom <a href="http://msdn.microsoft.com/en-us/library/system.identitymodel.selectors.securitytokenauthenticator.aspx" rel="nofollow">SecurityTokenAuthenticator</a> in <a href="http://msdn.microsoft.com/en-us/library/system.identitymodel.selectors.securitytokenmanager.createsecuritytokenauthenticator" rel="nofollow">CreateSecurityTokenAuthenticator()</a> method:</p> <pre><code>public override SecurityTokenAuthenticator CreateSecurityTokenAuthenticator(SecurityTokenRequirement tokenRequirement, out SecurityTokenResolver outOfBandTokenResolver) { outOfBandTokenResolver = null; return new PasswordSecurityTokenAuthenticator(this.ServiceCredentials .UserNameAuthentication .CustomUserNamePasswordValidator); } </code></pre> <p>The generated instance is a custom <a href="http://msdn.microsoft.com/en-us/library/system.identitymodel.selectors.customusernamesecuritytokenauthenticator.aspx" rel="nofollow">CustomUserNameSecurityTokenAuthenticator</a>.</p> <p><strong>The problem is</strong> that the overwritten <a href="http://msdn.microsoft.com/en-us/library/system.identitymodel.selectors.usernamesecuritytokenauthenticator.validateusernamepasswordcore.aspx" rel="nofollow">ValidateUserNamePasswordCore()</a> method is NOT CALLED at any time:</p> <pre><code>protected override ReadOnlyCollection&lt;IAuthorizationPolicy&gt; ValidateUserNamePasswordCore(String userName, String password) { ReadOnlyCollection&lt;IAuthorizationPolicy&gt; currentPolicies = base.ValidateUserNamePasswordCore(userName, password); List&lt;IAuthorizationPolicy&gt; newPolicies = new List&lt;IAuthorizationPolicy&gt;(); if (currentPolicies != null) { newPolicies.AddRange(currentPolicies.OfType&lt;IAuthorizationPolicy&gt;()); } newPolicies.Add(new PasswordAuthorizationPolicy(userName, password)); return newPolicies.AsReadOnly(); } </code></pre> <p>In my custom <a href="http://msdn.microsoft.com/en-us/library/system.identitymodel.policy.iauthorizationpolicy.aspx" rel="nofollow">IAuthorizationPolicy</a> provider <em>PasswordAuthorizationPolicy</em> I want to set a custom pricipal for the <a href="http://msdn.microsoft.com/en-us/library/system.identitymodel.policy.evaluationcontext.aspx" rel="nofollow">EvaluationContext</a> in <a href="http://msdn.microsoft.com/en-us/library/system.identitymodel.policy.iauthorizationpolicy.evaluate.aspx" rel="nofollow">Evaluate()</a> method.</p> <p>But if the upper method is not called, no additional IAuthorizationPolicy item can be defined.</p> <p>What wrong or missing here?</p> <p>I DO NOT use XML to configure my service, I do this 100% in C# code!</p> <p>EDIT: The code ist based on the following blog article: <a href="http://www.neovolve.com/post/2008/04/07/wcf-security-getting-the-password-of-the-user.aspx" rel="nofollow">http://www.neovolve.com/post/2008/04/07/wcf-security-getting-the-password-of-the-user.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload