0

At the moment I'm working with a WCF service that is used by an Asp.net MVC application.

For security reasons I'm using a guid that represents a username and pasword. ( When the user logs in, WCF checks the credentials in active directory and creates a record in a databasetable that connects the guid with the username and pasword) When the user uses another service, I send this guid along in the header. I want to impersonate the user in wcf using this guid. I've tried the folowing (using authorizationManager) but this doesn't work.

 public class MyAuthBehaviour :ServiceAuthorizationManager
    {
        public override bool CheckAccess(OperationContext operationContext, ref Message message)
        {

            var index = operationContext.IncomingMessageHeaders.FindHeader("identifier", "");

            if (index >= 0)
            {
                string identifier = operationContext.IncomingMessageHeaders.GetHeader<string>(index);
                AddWindowsID(identifier);
            }           
            return true;
        }

        private void AddWindowsID(string identifier)
        {
            WindowsIdentity wid = AccountBL.GetWindowsIdentity(identifier);
            wid.Impersonate();
        }      
    }

I do get the WindowsIdentity but I can't Impersonate. Is there a way to do this?

To say it short: I want to impersonate a user within WCF before it gets to the actual service method using the guid in the header.

When wid.Impersonate() hits, the client throws this exception:

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

WCF keeps on running.(although other exceptions where trown in the WCF services)

The exception isn't thrown when wid.Impersonate() is executed, it occurs when we're leaving the MyAuthBehaviour class

Gert Hermans
  • 769
  • 1
  • 9
  • 30
  • What happens when the call wid.Impersonate() executes? Does it throw an exception? If so, what? If not, how do you know "I can't impersonate"? – Chris Dickson Aug 28 '12 at 09:38
  • Added some extra info about the exception – Gert Hermans Aug 28 '12 at 09:46
  • 1
    That's not the underlying exception - just the generic error message WCF creates in the client-side channel stack when the service invocation throws an exception. As the message says, you should turn on WCF tracing to see the real exception on the service side. – Chris Dickson Aug 28 '12 at 13:08
  • You were right. The problem wasn't impersonating. earlier on i was experimenting with messagecontracts. This didn't go very well with what i was doing here. When I changed that, impersonating worked fine. – Gert Hermans Aug 28 '12 at 13:33

0 Answers0