I'm trying to understand role based security and I have the following method:
[PrincipalPermission(SecurityAction.Demand, Role = "Administrators")]
static void Test()
{
//administratos only can call this code
}
What I wanna do is that only users that are members of the Windows Administrators group can call this code, however, if I do the following, it works:
GenericIdentity genericIdentity = new GenericIdentity("test", "test");
GenericPrincipal genericPrincipal = new GenericPrincipal(genericIdentity, new string[] { "Administrators" });
AppDomain.CurrentDomain.SetThreadPrincipal(genericPrincipal);
Test();
So, how can I make it work only if the user is in the Administrators wi开发者_运维问答ndows group?
thanks!
Have you set the PrincipalPolicy? You need that to check roles against Windows groups.
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
精彩评论