My setup is a little complicated so let me go over that first.
We have a WCF web service that gets data from various sources through several different API’s and returns that data to the client. The requested security is that it be done over HTTPS(working)
The IIS standard is that the app pool must be set to use the basic IIS network service account and that .net impersonation should be used.
My problem is that the web service should always run under an AD process ID regardless of who calls it, but that it should also check what AD groups the caller is in to determine what functions are accessible. Now I can setup my web.config to use and this kind of works for making it always run as Blah but then I don’t know how to also make it impersonate/check the calling user to see what functions they have access too.
**edit: forgot to mention the calling client should be able to pass a UN/PASS instead of just its windows token. The wcf service should verfiy its a valid AD UN and PASS as well as poll what groups it in.
It sounds like you want
HostingEnvironment.ImpersonateExample:
Well, that seems counter-intuitive, but I’ve run into worse policies in my day, so I’m hardly one to judge. 😉
As I mentioned in my comment, there are overloads of Impersonate that will allow you to impersonate an arbitrary account. In order to do this, you must obtain the windows identity token for that user, and this is non-trivial, and not, to my knowledge, something that you can do 100% in managed code. You’ll have to use unmanaged code, and you’ll have to know the username and password of the impersonated account within your application. This is far less secure than simply setting the account as the App Pool ID, if you ever want to argue the point with your network architect, BTW. Just some ammo for ya.
Anyway, here’s some example code I adapted from the internets: