Reputation: 22466
for a customer, I need to implement the following scenario:
What I am looking for is a way to implement the impersonation in one place instead of each service method separately.
How can I implement this in the service?
Thanks for your help,
Markus
Upvotes: 0
Views: 1102
Reputation: 495
Actually this link gives the answer: ServiceAuthorizationBehavior.ImpersonateCallerForAllOperations
A Snippet:
For details, including how impersonation is performed when using Allowed together with the ServiceAuthorizationBehavior.ImpersonateCallerForAllOperations property, see Delegation and Impersonation with WCF and How to: Impersonate a Client on a Service.
Below is the literal link.
Upvotes: 0
Reputation: 3337
Perhaps this example can get you on the way: taken from here
public class HelloService : IHelloService
{
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public string Hello(string message)
{
WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity;
if (callerWindowsIdentity == null)
{
throw new InvalidOperationException
("The caller cannot be mapped to a Windows identity.");
}
using (callerWindowsIdentity.Impersonate())
{
EndpointAddress backendServiceAddress = new EndpointAddress("http://localhost:8000/ChannelApp");
// Any binding that performs Windows authentication of the client can be used.
ChannelFactory<IHelloService> channelFactory = new ChannelFactory<IHelloService>(new NetTcpBinding(), backendServiceAddress);
IHelloService channel = channelFactory.CreateChannel();
return channel.Hello(message);
}
}
}
Upvotes: 1