Skip to content
Advertisement

Storing application permissions in a database

I’m developing an application for our company that eventually will have lots of ways of restricting users to particular sections/modules. While the application is still small, I’d like to move to a new method of storing permissions that, as the application grows, will remain easy to maintain and query.

Currently in our MySQL database we have a table called “user” which stores the user’s ID, username and password. In a separate table called “user_acl” is the following:

JavaScript

We only have 3 modules at the minute, but over time more will be created and permissions for each will need to be added.

Rather than create a column for each permission, is there any other way or storing this information?

Advertisement

Answer

I would do it this way.

JavaScript

and then I can assign multiple permissions to the user using a many to many relationship table

JavaScript

This design will allow me to add as many permission as I want, and assign it to as many user as i want.

While the above design go with your requirement, I have my own method of implementing ACL in my application. I am posting it here.

My method of implementation of ACL goes like this:

  1. User will be assigned a role (Admin, guest, staff, public)
  2. A role will have one or many permissions assigned to them (user_write, user_modify, report_read) etc.
  3. Permission for the User will be inherited from the role to which he/she is
  4. User can be assigned with manual permission apart from the permission inherited from role.

To do this I have come up with the following database design.

JavaScript

This gives me more control over the ACL. I can allow superadmins to assign permission by themselves, and so on. As I said this is just to give you the idea.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement