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 supposed to implement a custom Behavior, or perhaps something with WCF Sessions? Any clues would be super-handy.
+2
A:
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();
}
Mitch Baker
2008-11-15 09:06:18
A:
ServiceSecurityContext.Current.WindowsIdentity worked for me - I don't have the Rep to up vote it...
chadbr
2010-06-30 19:54:37