Joseph Michael Pesch
VP Programming

Declarative Security Checks for User Name and/or Role Permission

by 6. January 2009 18:46

[PrincipalPermissionAttribute(SecurityAction.Demand, Name =  "UserName", Role = "UserRole")]
publicstaticvoid SecurityTestEntryPoint(bool flag)
{
  if (flag)
  {
    // This is more secure code...

    SecurityTest(flag, "");
  }
  else

  {
    // This is less secure code...

    SecurityTest(flag);
  }
}
[PrincipalPermissionAttribute(SecurityAction.Demand, Role = "ManagerRole")]
publicstaticvoid SecurityTest(bool flag, string MoreSecure)
{
  // This is more secure code...

}
[PrincipalPermissionAttribute(SecurityAction.Demand, Role = "ManagerRole")]
[PrincipalPermissionAttribute(SecurityAction.Demand, Role = "UserRole")]
publicstaticvoid SecurityTest(bool flag)
{
  // This is less secure code...

}

NOTE: You can stack multiple attributes for an OR condition, however, you cannot create an AND condition. As in the example above the less secure method will let both "ManagerRole" users and "UserRole" users access itself.

Topic Links:

http://msdn.microsoft.com/en-us/library/dswfd229(VS.71).aspx

http://bytes.com/groups/net-c/267605-cas-multiple-permissions

 

Tags: ,

C# | Security

Comments are closed