Recently I got a question about impersonation in WCF. What should we do in order to impersonate the client?

It’s simple:

Client Side

// Create a client with given client endpoint configurationMyServiceClient client = new MyServiceClient();client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;

Server Side

if (ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Impersonation ||   ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Delegation){     // Impersonate.  using(ServiceSecurityContext.Current.WindowsIdentity.Impersonate())  {       Console.WriteLine("Impersonating the caller");   }}

Similar Posts:

Tags:



6 Comments to “Client Impersonation in WCF”

  1. maord | June 22nd, 2009 at 23:09

    This comment originally written by:
    Recently I got a question about impersonation in WCF. What should we do in order to impersonate the client? It's simple!

  2. maord | June 22nd, 2009 at 23:09

    This comment originally written by:JD Stuart

    I'm using Silverlight as a client, and I already enabled my web application to use aspNetContext = true.

    The ServiceSecurityContext.Current is always null.

    How do I impersonate a Active Directory user, in my wcf service, using Silverlight as my client?

  3. maord | June 22nd, 2009 at 23:09

    This comment originally written by:Maor David-Pur

    Hi Marc

    You should catch this issue – probably you cannot impersonate your client.

  4. maord | June 22nd, 2009 at 23:09

    This comment originally written by:Marc S

    What if ServiceSecurityContext.Current is null?

  5. maord | June 22nd, 2009 at 23:09

    This comment originally written by:Maor David-Pur

    Mr. Lavian, it’s screen resolution issue.

    This is the code:

    if (ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Impersonation ||             ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Delegation)        

    {   // Impersonate.

       using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())  

     {  Console.WriteLine("Impersonating the caller");  

     }

    }

  6. maord | June 22nd, 2009 at 23:09

    This comment originally written by:Gilad Lavian

    I cant see the code after:

    "ImpersonationLevel == TokenImpersonationLevel.Impersonation "

    Can you please fix it…

Leave a Comment