none
Secure WCF service using username and passowd - Validate function dosent hit using customUserNamePasswordValidatorType. RRS feed

  • Question

  • I'm trying to secure my wcf service with username and password , 
    There is no errors but the Validate function dosent hit .
    This is my web.config : 

        <?xml version="1.0"?>
    <configuration>
    
    
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
    
        <services>
          <service name="oClearOut.oClearOutService" behaviorConfiguration="Behavior1">
            <endpoint address="wsHttp" binding="wsHttpBinding" contract="oClearOut.IoClearOutService" bindingConfiguration="Binding1" />
            <endpoint address="mex"    binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
    
        <bindings>
    
          <wsHttpBinding>
    
            <binding name="Binding1">
              <security mode="Message">
                <message clientCredentialType="UserName"/>
              </security>
            </binding>
            
            <binding name="WSHttpBinding_IoClearService" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
              bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
              textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
              <security mode="Message">
                <transport clientCredentialType="Windows" proxyCredentialType="None"
                  realm="" />
                <message clientCredentialType="Certificate" negotiateServiceCredential="true"
                  algorithmSuite="Default" establishSecurityContext="false" />
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
        <client>
    
          <endpoint address="Some url" behaviorConfiguration="wsHttpCertificateBehavior"
           binding="wsHttpBinding"       bindingConfiguration="WSHttpBinding_IoClearService"
           contract="srv.IoClearService" name="WSHttpBinding_IoClearService">
            <identity>
              <certificate encodedValue="dfdfdfdfdf_AwAAAAEAAAAUAAAAxo3wtffgbyeKyLvvsGl1timlTSPE+JSog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aW9uYWwlMjBDQSgxKS5jcnQwIQYJKwYBBAGCNxQCBBQeEgBXAGUAYgBTAGUAcgB2AGUAcjANBgkqhkiG9w0BAQUFAAOCAQEAcK7kPLQU/T/uniZje/Ec583XtSlRKOIV61UG6gyYdzCQzstlUAgVASaaFY/MV2OjdbzBPYT39W7GoFBwB6WFRFQzko+7wepM/fuwQV5P1GEWDhrtDlaKQc89a2E5msg3Ew/d+ZU0sIa1h/m0B/hM/SLVOT3lF/gI22C2hsZi6KlUztdBssBRfkTp3IqprLMFl4v9CfCgCBe1ykkr2hsmyhPZk1IWyQgL4xmm1hsb4I3yVoJbLMCslMYnOI02B+kkW3GXI8JMjGoVHeSCcOzfkRpveAl8UuerJxECddESlv52JKgaEMmScTvlLFXz3Cu9VKGlwFzWpI41nvAjF+2cug==" />
            </identity>
          </endpoint>
    
        </client>
        <behaviors>
          <endpointBehaviors>
            <behavior name="wsHttpCertificateBehavior">
              <clientCredentials>
                <!--certificate storage path in the client -->
                <clientCertificate findValue="crtWebServices" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
                <serviceCertificate>
                  <authentication revocationMode="NoCheck" certificateValidationMode="PeerTrust"/>
                </serviceCertificate>
              </clientCredentials>
            </behavior>
          </endpointBehaviors>
    
        
          <serviceBehaviors>
            <behavior name="Behavior1">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceCredentials>
        
                <serviceCertificate findValue="crtWebServices"
                      storeLocation="LocalMachine"
                      storeName="My"
                      x509FindType="FindBySubjectName" />
                
                <userNameAuthentication userNamePasswordValidationMode="Custom" 
                 customUserNamePasswordValidatorType="oClearOut.AuthCs,oClearOut" />
       
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
    
        </behaviors>
       
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
         <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    </configuration>
    


    and my validate function  : 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ServiceModel;
    using System.IdentityModel.Selectors;
    using System.Security.Principal;
    
    
    namespace oClearOut
    {
        class AuthCs: UserNamePasswordValidator
        {
            public override void Validate(string userName, string password)
            {
                if(  userName==null ||  password==null)
                {
                    throw new ArgumentNullException();
                }
    
                if (!(userName == "sdsdsd" && password == "sdsdsdsdsd"))
                {
                    throw new FaultException("Incorrect Username or Password");
                }
            }
        }
    }
    




    The dll name is oClearOut


    There is any mistakes on the code ? 
    Why the Validate Function dosent Hit ? 
    Thanks in advance , 

    Poli . 

            
    Thursday, June 7, 2012 8:04 AM

Answers

All replies