My understanding has always been that security attributes on methods will override security attributes on class, but that doesn't seem to be the case any more as the simple code below demonstrates:
class Program
{
[PrincipalPermission(SecurityAction.Demand, Authenticated = true)] //<-- this passes
class DumbClass
{
[PrincipalPermission(SecurityAction.Demand, Role = "ffff")] //<-- this passes (but shouldn't)
public string EchoMethod(string input)
{
return input;
}
}
static void Main(string[] args)
{
Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity("manual"));
//this should throw becuase the principal is not in the role "ffff"
//BUT DOESN'T
Console.WriteLine(new DumbClass().EchoMethod("this"));
}
}
If I remove the declaration on the class then I get the expected security exception. Am I missing something really obvious. I'm using .Net 4.5