I have a WCF Service that is using Impersonation. I have verified that the correct Identity is being used through the following method that I added to my service for purposes of debugging.
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public AuthUser GetUser()
{
AuthUser user = new AuthUser();
user.UserName = WindowsIdentity.GetCurrent().Name;
return user;
}
Without specifying the [OperationBehavior] I receive NT AUTHORITY\NETWORK SERVICE
, as I'd expect. With the attribute I see the user returned that I expect DOMAIN\DOMAINUSER
.
The service is currently still returning an error that it does not have access to perform file operations in the following line:
FileStream fs = new FileStream(filename, FileMode.Create,FileAccess.Write);
I have verified that the directory has Full Access for the domain user through checking the Active Directory groups and memberships.
I have defined <identity impersonate="true" />
in the web.config of the service and have defined this in the client-side code:
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation
If relevant, this is my service-side binding:
<wsHttpBinding>
<binding name="default" maxReceivedMessageSize="200000">
<security mode="Message">
<message clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
Anonymous access is enabled in IIS as I'm letting WCF handle the authentication.