Can anyone explain the following C # behavior? I wrote a small console application to learn about CAS, but I cannot understand why the following lines of code work:
string[] myRoles = new string[] { "role1", "role2", "role3" };
GenericIdentity myIdentity = new GenericIdentity("myUsername", "customAuthType");
GenericPrincipal myPrincipal = new GenericPrincipal(myIdentity, myRoles);
System.Threading.Thread.CurrentPrincipal = myPrincipal;
Console.WriteLine(SecurityManager.IsGranted(new PrincipalPermission(null, "role1")));
Console.WriteLine(SecurityManager.IsGranted(new PrincipalPermission(null, "roleX")));
The "true" output for calls to SecurityManager.IsGranted ().
If I then add the following lines:
new PrincipalPermission(null, "role1").Demand();
new PrincipalPermission(null, "roleX").Demand();
the first call request passes, and the second (as expected) raises a SecurityException.
Why SecurityManager.IsGranted () - does not return false for permission "roleX"?
Madiking
source
share