views:

871

answers:

1

I am writing a WCF Service which would allow access to operations based on AD user group. If the logged in user is part of groupA, allow him to do operationA, but not operationB and so on and so forth. Now for this I have to pass NetworkCredentials to the service like

factory.Credentials.Windows.AllowedImpersonationLevel = 
                     TokenImpersonationLevel.Identification;
factory.Credentials.Windows.AllowNtlm = true;
factory.Credentials.Windows.ClientCredential.username = "username";
factory.Credentials.Windows.ClientCredential.password = "pwd";
factory.Credentials.Windows.ClientCredential.domain = "mycompany.com";

I want that the user need not enter his credentials for calling service operation. It should take from Thread.CurrentPrincipal. Can anyone help me out in this regards as to how to pass network credentials.

A: 

Why don't you just specify the security mode to be "Windows integrated" security on your binding? This is the default on net.Tcp and wsHttp bindings - the Windows credentials of the currently logged in user will be sent across the wire to the server.

No need to explicitly set those credentials again, really.

Marc

marc_s
Do you mean I should just remove the above code from my client? If yes, it still takes the ASPNET account as the default credentials. Can u post in some code to help me out? Thanks for the reply.
Ashish
AHA - ASP.NET - you didn't mention that in your original POST!
marc_s
It depends on how you have ASP.NET set up - if you connect to your ASP.NET site anonymously, you'll "loose" your credentials and ASP.NET will connect to your WCF service with its own credentials. If you have set up Windows authentication for the ASP.NET app (in IIS Manager), you should be fine, I think.
marc_s