I have a requirement for entity-level authorization that's frankly over my head. I'm hoping to get some guidance on this permission structure, how I might implement it in .NET 4.5, and if there are ways I could improve it.
Here it goes:
I have a set of data structured as follows:
Where
- a
Fleet
is a collection of zero or moreCars
. - a
Fleet
can contain otherFleets
Fleets can be later reorganized and moved around for organizational purposes.
I have several roles with permissions in the system that pertain to these entities:
- Owner: Can add or remove cars from the fleet
- Manager: Assigns drivers to cars
- Driver: is allowed to simply drive the car
- Mechanic: is allowed to fix the car
The authorization logic allows for a User
in the system to be granted access to either a Fleet
or a Car
with one or more roles.
Here are some scenarios to help explain:
- If I grant
User
Jim access toFleet
#5 with the role ofDriver
, he is allowed to drive any Car under fleet #2. The resulting permissions allow him to drive cars #4, 5, 6 - If I grant user Maura access to
Car #1
as a Mechanic, the resulting permissions allow her to fix only car #1. - If I grant user Sarah access to Fleet #2 with the roles
Owner
andMechanic
, she is allowed to add and remove cars to fleets #2, 4, 5 AND she is allowed to fix cars #1, 2, 3, 4, 5, 6. - If I grant user Jeremy access to fleet #1 as an
Owner
AND to Fleet #6 as aDriver
, the resulting permissions allow him to add and remove cars to all fleets AND drive cars #7, 8. He cannot drive any other car other than #7 and 8.
What is a good approach to this entity-level authorization?
If it matters, we're using .NET 4.5.1 with EF6 Code First, built on top of ASP.net Boilerplate.