How to impersonate a user in a WCF service?

I authenticate the user in the WCF service through IIS7 using Windows authentication and ASP.NET impersonation.

When debugging locally, I can see System.Security.Principal.WindowsIdentity.GetCurrent (). Name as equal to my Windows credentials. When I deploy this service to the server, WCF does not start if anonymous authentication is enabled.

So, how do we get this WCF service to run on a server with anonymous authentication disabled ?

UPDATE 1 : error message after trying both sentences:

The authentication schemes configured on the host ("IntegratedWindowsAuthentication") do not allow the "WebHttpBinding" ("Anonymous") binding parameters to be configured. Verify that SecurityMode is set to Transport or TransportCredentialOnly. In addition, this can be resolved by changing the authentication scheme for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property in the application configuration file on the item, updating the ClientCredentialType property on the binding, or by setting the AuthenticationScheme property to HttpTransportBindingElement.

UPDATE 2 . Authentication was established as follows:

Application pool:

  • Identity = NetworkService

Web site:

  • Anonymous Authentication = Disabled
  • ASP.NET Authentication = Enabled
  • Windows Authentication = Enabled

WCF application:

  • Anonymous Authentication = Disabled
  • ASP.NET Authentication = Enabled
  • Windows Authentication = Enabled
+4
source share
3 answers

This is a common problem. You need to set the security mode and the corresponding transport element - If you use basicHttpBinding - put the following text in config

<basicHttpBinding> <binding> <security mode="TransportCredentialOnly"> <transport clientCredentialType="Windows" /> </security> </binding> </basicHttpBinding> 

Read the following posts - http://blogs.msdn.com/b/drnick/archive/2007/03/23/preventing-anonymous-access.aspx http://blogs.msdn.com/b/wenlong/archive/2006 /05/18/600603.aspx

+3
source

One of the reasons for the error is that you need to enable keberos delegation on the server hosting ASP.net. this allows Windows authenticated tokens to propagate to the WCF service hosting server.

You are viewing the following link

Impersonation and Delegation in WCF

NTN

Routes

+1
source

There was the same problem. This happened to me because Windows authentication was not included in IIS for the application.

  • Open IIS
  • Choose a web application
  • Click the Identity Icon (IIS)
  • Enable Windows Authentication
0
source

Source: https://habr.com/ru/post/1494981/


All Articles