I had a similar problem in the past and I would consider permissions for each object. What I did was add an element to an object like:
public bool CanUserAccess(User user) { return managerId == user.managerId; }
Then, at the top of each action that provides access to the monitored resource:
public ActionResult Details(int id) { var employee = employeeRepository.Get(id) var user = (CustomIdentity)ControllerContext.HttpContext.User.Identity; if(!employee.CanUserAccess(user)) return new HttpUnauthorizedResult();
This, of course, is not ideal, but it centralizes the processing of permissions and allows you to easily increase complexity in the future (allow access to the chain, special rules for HR, etc.). You can also write another overload / extension to access the User.Identity property for a bit more automation (or at least handle type conversions).
Since I was dealing with ACLs, I would have additional methods / parameters to indicate the main nature of the action (e.g. Read, Write, Delete, Create, etc.).
antijon
source share