I have a WCF service, hosted in a WindowService, using nettcpbinding in which I want to perform check in the C# code if the sender belongs to a specific AD group.
Is it possible? if so, how?
I have a WCF service, hosted in a WindowService, using nettcpbinding in which I want to perform check in the C# code if the sender belongs to a specific AD group.
Is it possible? if so, how?
Well assuming that the WCF client and server are on the same domain, you could do something like that:
On the client side, you allow using the windows identity to authenticate the client:
using System.Security.Principal;
....
ServiceReference.ServiceClient client = new ServiceReference.ServiceClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Identification;
On the server side, you retrive the caller windows identity and test if it belongs to the group:
WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity;
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(callerWindowsIdentity);
var isInRole = windowsPrincipal.IsInRole("Users");