Hi,
can anybody please explain the following c# behaviour? I have written a small console application just to learn about CAS, but I can not seem to understand why the following lines of code work like they do:
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 output is "true" for both SecurityManager.IsGranted() calls.
If I then add the following lines:
new PrincipalPermission(null, "role1").Demand();
new PrincipalPermission(null, "roleX").Demand();
the first demand call passes, but the second one (as expected) causes a SecurityException.
Why does not the SecurityManager.IsGranted()-call return false for the "roleX" permission?