wcf security - WCF with transport authentication using certificates and message authentication using username/password -


i'm trying configure wcf service implement 2 factor authentication. idea being there message level authentication username/password (ws security) , transport level authentication using client certificate.

step 1: message level authentication

i've built wcf service uses message level authentication username/password. works great. see credentials passed client in soap header , service authenticates , authorizes user.

the system.servicemodel.servicesecuritycontext.current.primaryidentity object system.security.principal.windowsidentity type , has following property values:

  • authenticationtype = basic
  • impersonationlevel = impersonation
  • isanonymous = false
  • isauthenticated = true
  • name = ad account (domain\accountname)

the system.servicemodel.servicesecuritycontext.current.windowsidentity object windowsidentity , has same property values above.

step 2: transport level authentication certificates

then built new wcf service uses transport authentication certificates. again, works great.

the system.servicemodel.servicesecuritycontext.current.primaryidentity object system.identitymodel.claims.x509identity type , has following property values:

  • authenticationtype = x509
  • isauthenticated = true
  • name = subject attribute of certificate, thumbprint

the system.servicemodel.servicesecuritycontext.current.windowsidentity object system.security.principal.windowsidentity type , has following property values:

  • authentication type = ""
  • impersonationlevel = anonymous
  • isanonymous = true
  • isauthenticated = false

step 3: transport level authentication certificates & active directory mapping

next, turned on active directory mapping creating service behavior , setting servicecredientials\clientcertificate\authentication mapclientcertificatetowindowsaccount attribute true.

the service appears correctly map certificate active directory account.

the system.servicemodel.servicesecuritycontext.current.primaryidentity object system.security.principal.windowsidentity type , has following property values:

  • authenticationtype = ssl/pct
  • impersonationlevel = identification
  • isanonymous = false
  • isauthenticated = true
  • name = ad account (domain\accountname)

the system.servicemodel.servicesecuritycontext.current.windowsidentity object windowsidentity , has same property values above.

step 4: message level authentication , transport authentication

with above scenarios working, want combine them. created web service username password message level authentication , certificate transport authentication, active directory user mapping disabled.

<?xml version="1.0"?> <configuration>   <appsettings>         <add key="aspnet:usetaskfriendlysynchronizationcontext" value="true" />   </appsettings>   <system.web>     <compilation debug="true" targetframework="4.5" />     <httpruntime targetframework="4.5"/>   </system.web>    <system.servicemodel>     <services>       <service name="wcftransportauthcertificatemessageauthusername.service1"                behaviorconfiguration="mapclientcertificates">         <endpoint binding="custombinding"                bindingconfiguration="transportcertificateauthentication_messageusernameauthenticiation"                   contract="wcftransportauthcertificatemessageauthusername.iservice1">         </endpoint>       </service>     </services>      <bindings>           <custombinding>         <binding name="transportcertificateauthentication_messageusernameauthenticiation">           <textmessageencoding messageversion="soap11"></textmessageencoding>           <security authenticationmode="usernameovertransport"></security>           <httpstransport requireclientcertificate="true"></httpstransport>         </binding>       </custombinding>     </bindings>      <behaviors>       <servicebehaviors>         <behavior>           <servicemetadata httpgetenabled="true" httpsgetenabled="true"/>           <servicedebug includeexceptiondetailinfaults="false"/>         </behavior>          <behavior name="mapclientcertificates">           <servicemetadata httpgetenabled="true" httpsgetenabled="true"/>           <servicedebug includeexceptiondetailinfaults="false"/>            <servicecredentials>             <clientcertificate>               <authentication mapclientcertificatetowindowsaccount="false" includewindowsgroups="true" />             </clientcertificate>           </servicecredentials>         </behavior>        </servicebehaviors>     </behaviors>      <protocolmapping>       <add binding="basichttpsbinding" scheme="https"/>     </protocolmapping>      <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" />    </system.servicemodel>    <system.webserver>     <modules runallmanagedmodulesforallrequests="true"/>     <directorybrowse enabled="true"/>   </system.webserver>  </configuration> 

the system.servicemodel.servicesecuritycontext.current.primaryidentity object system.security.principal.genericidentity type , has following property values:

  • authentication type = ""
  • isauthenticated = false
  • name = ""

the system.servicemodel.servicesecuritycontext.current.windowsidentity object system.identitymodel.claims.x509identity type , has following property values:

  • authenticationtype = x509
  • isauthenticated = true
  • name = subject attribute of certificate, thumbprint

so @ point, can see details of certificate credentials, not of message credentials. first question - why can't see message level credentials?

step 5: message level authentication , transport authentication ad mapping.

now turn on ad user mapping setting servicecredientials\clientcertificate\authentication mapclientcertificatetowindowsaccount attribute true.

the system.servicemodel.servicesecuritycontext.current.primaryidentity object system.security.principal.genericidentity type , has following property values:

  • authentication type = ""
  • isauthenticated = false
  • name = ""

the system.servicemodel.servicesecuritycontext.current.windowsidentity object system.security.principal.windowsidentity type , has following property values:

  • authenticationtype = ""
  • impersonationlevel = anonymous
  • isauthenticated = false
  • isanonymous = true
  • name = ""

authentication appears happening correctly @ both transport , message level. if specify incorrect username/password in soap header, soap fault back. if not provide client certificate, or provide untrusted one, error so here, understand system.servicemodel.servicesecuritycontext.current.windowsidentity system.security.principal.windowsidentity type because service configured map ad account, why did not map?


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -