I\'m pretty green with web services and WCF, and I\'m using Windows integrated authentication - how do I get the username on the server-side interface? I believe that I\'m s
Try looking at ServiceSecurityContext.Current.WindowsIdentity
To get the WCF Service caller username:
var callerUserName = ServiceSecurityContext.Current.WindowsIdentity.Name;
have you tried WindowsIdentity.GetCurrent();
?
Here is a snippet of service code that shows how you could retrieve and use the WindowsIdentity associated with the caller of a WCF service.
This code is assuming that you are accepting most of the defaults with your configuration. It should work without any problems with the Named Pipe or the Net TCP binding.
the p.Demand() will determine if the user is in the windows group specified by the permissionGroup variable.
private static void DemandManagerPermission()
{
// Verify the use has authority to proceed
string permissionGroup = ConfigurationManager.AppSettings["ManagerPermissionGroup"];
if (string.IsNullOrEmpty(permissionGroup))
throw new FaultException("Group permissions not set for access control.");
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
var p = new PrincipalPermission(ServiceSecurityContext.Current.WindowsIdentity.Name, permissionGroup, true);
p.Demand();
}