I'm trying to create an authorization scheme for my ASP.NET MVC application where an Enum is used to set permissions. For example:
[Flags]
enum Permissions
{
ReadAppointments = 1,
WriteAppointments = 2 | ReadAppointments,
ReadPatients = 4,
WritePatients = 8 | ReadPatients,
ReadInvoices = 16,
WriteInvoices = 32 | ReadInvoices
...
}
But I don't really like that because it really doesn't make it clear that Write always includes Read.
I then realized that a requirement would be that a user might have NO access to, for example, Appointments.
Essentially, I'd want a "bitfield" with 3 states: none, readonly, full (read/write). I'd like to still use an enum bitfield since it's easy to store in a DB (as an int). Also it's very easy to see if a permission is set.
Does anyone have any idea how this could be easily accomplished using an Enum... or am I going in the completely wrong direction?
EDIT: I'm really trying to avoid storing permission definitions in the DB since I really want things to be changeable without having to modify much on the DB end. It'd be really nice to know how a large scale application would do this.