开发者

Role Based Security in the Administrators windows group

开发者 https://www.devze.com 2023-01-03 02:19 出处:网络
I\'m trying to understand role based security and I have the following method: [PrincipalPermission(SecurityAction.Demand, Role = \"Administrators\")]

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消