I'm implementing system which uses role based access to different methods in classes. For example to perform any action I need to check whether user which uses it can do it.
I can write in each method:
if(User.IsInRole ...) {
} else {
return ... throw ... whatever
}
I was thinking about automating this process for example by adding attributes to this methods or maybe any other solution?
As long as you use principals things are already there...
[PrincipalPermission(SecurityAction.Demand, Role = "A role available on your principal")]
public void Foo()
{
// Will throw an exception if the principal does not have the required role
// Otherwise the method will execute normally
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With