I'm in the process of a building an access control system as part of a web framework I am developing. I want to make it super flexible and awesome. Can you help me by providing input and insight on my design? Here is my work so far (my specific questions are at the bottom):
Users
- Users have a username (32 characters, no spaces) and password
- Users have one or more e-mail addresses that must be verified
- Users may login using either their username or any of their e-mail addresses
- Users may be associated to zero or many accounts
Accounts
- Accounts represent one or more users
- Each user may have specific permissions or roles for an account (e.g., account owner or "can add new user")
- All accounts are tied to an account type
Account Types
- Account types have zero or many account type roles
- Account types have zero or many account type features
Account Type Roles
- E.g., "Owner", "Administrator", "Power User", "Guest", etc.
- Account type roles are a collection of account type permissions
Account Type Permissions
- Account type permissions are specific actions in the system that application logic will verify against
- They may reference a parent, so they can be hierarchically grouped
- E.g.:
- "User Management"
- "Add User"
- "Remove User"
- "User Management"
- These permissions may be specifically for an account type feature
Account Type Features
- Account type features may be activated on an account to give it more permissions
- E.g., "Standard Account" or "Premium Account"
- These features, if activated on an account, will give the account owner greater access to the system
- They are tracked when they are activated or deactivated and can be billed against periodically or on demand
Questions
What is the best way to have application logic check against a user action? I was thinking of storing all of a user's permissions in an object for their session (which would require a logout/login to refresh permissions, which I am not a fan of - any ideas on real time permission management?):
{
"All Permissions": {
"User Management": {
"Add User",
"Delete User"
},
"Premium Account": {
"Download Files",
"Upload Files"
},
}
}
I would then declare permissions that are required for a specific action in the system. Maybe something like:
Permission::require('Add User');
If the declared permissions were not in the users permission object, the request would fail. This seems kind of intense for each user action though. Also, what if another subset of permissions has the string "Add User"?
Thanks in advance for any help with this!