A quick question about securing data access for different user roles/types.
I have a web application (standard create/edit/view/delete) that utilizes user roles pretty heavily.
First a quick (abstracted) overview.
I have some hierarchical entity relationships:
Organizational Entities
Business Entities
Many business entities are grouped under one organizational entity
This leaves me with 3 types of users (abstracted a bit) who all have access to different data:
Admins - can see/manage everything
Organizational Admins - can see/manage everything created by any business entity below their organizational entity
Business Users - can create/see/manage anything created by their specific business entity (this is the only user type that can create new objects)
So, being a web app this data is all stored in a DB (MySQL) and the challenge is finding a clean way to put controls around the data access piece to ensure that a user is only accessing data that they have rights to see.
Much of the SQL is dynamically generated, so what we do today is a lot of "if" checking user types and dynamically altering or appending the appropriate "WHERE" clause to the query in every place where we make these calls. It works, but it's not very clean or maintainable and it makes me cringe a little when I think about it. It makes it extremely difficult to add new user types or to change the business logic of existing user types. I can't help but think that there must be a better way. I have a few ideas, but nothing that I think I could actually get to implementation without tripping over a multitude of problems, so I'm hoping someone can give me some insight into "industry standard" on how this sort of thing is handled.
I have a web application (standard create/edit/view/delete) that utilizes user roles pretty heavily.
First a quick (abstracted) overview.
I have some hierarchical entity relationships:
Organizational Entities
Business Entities
Many business entities are grouped under one organizational entity
This leaves me with 3 types of users (abstracted a bit) who all have access to different data:
Admins - can see/manage everything
Organizational Admins - can see/manage everything created by any business entity below their organizational entity
Business Users - can create/see/manage anything created by their specific business entity (this is the only user type that can create new objects)
So, being a web app this data is all stored in a DB (MySQL) and the challenge is finding a clean way to put controls around the data access piece to ensure that a user is only accessing data that they have rights to see.
Much of the SQL is dynamically generated, so what we do today is a lot of "if" checking user types and dynamically altering or appending the appropriate "WHERE" clause to the query in every place where we make these calls. It works, but it's not very clean or maintainable and it makes me cringe a little when I think about it. It makes it extremely difficult to add new user types or to change the business logic of existing user types. I can't help but think that there must be a better way. I have a few ideas, but nothing that I think I could actually get to implementation without tripping over a multitude of problems, so I'm hoping someone can give me some insight into "industry standard" on how this sort of thing is handled.