C# 针对服务器端WCF调用方的ActiveDirectory组进行验证
我有一个WCF服务,托管在WindowsService中,使用nettcpbinding,如果发送者属于特定的广告组,我想在其中执行C代码检查C# 针对服务器端WCF调用方的ActiveDirectory组进行验证,c#,wcf,client-server,nettcpbinding,windows-identity,C#,Wcf,Client Server,Nettcpbinding,Windows Identity,我有一个WCF服务,托管在WindowsService中,使用nettcpbinding,如果发送者属于特定的广告组,我想在其中执行C代码检查 可能吗?如果是这样,怎么做?假设WCF客户端和服务器位于同一个域上,您可以这样做: 在客户端,您允许使用windows标识对客户端进行身份验证: using System.Security.Principal; .... ServiceReference.ServiceClient client = new ServiceReference.Servic
可能吗?如果是这样,怎么做?假设WCF客户端和服务器位于同一个域上,您可以这样做: 在客户端,您允许使用windows标识对客户端进行身份验证:
using System.Security.Principal;
....
ServiceReference.ServiceClient client = new ServiceReference.ServiceClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Identification;
在服务器端,您可以检索呼叫者windows标识并测试它是否属于以下组:
WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity;
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(callerWindowsIdentity);
var isInRole = windowsPrincipal.IsInRole("Users");
这是可能的,但实现取决于应用程序拓扑(例如,服务如何承载:IIS、Windows服务、控制台应用程序e.t.c.,客户端是否在同一网络/域中访问服务,Windows身份验证Kerberos或NTLM e.t.c。)。@lonut Ungureanu-WindowsService(更新了问题)