Search code examples
c#.netwcfsecurity-roles

How do I list the requesting user's roles in a WCF service?


Just started getting to grips with WCF security. How do I list a user's roles at the service?

E.g.

// Could use declarative security here, i.e. using PrincipalPermission attribute
public string MyService()
{
    // Would like some code that does something like:
    foreach( Role role in CurrentUser.Roles )
    {
    }
}

Thanks


Solution

  • When dealing with Windows groups you can use this code:

    foreach (IdentityReference idRef in WindowsIdentity.GetCurrent().Groups)
    {
        Console.WriteLine(idRef.Translate(typeof(NTAccount)).Value);
    }