https://github.com/tomkyle/rbac
RBAC: Roles, Permissions and ACL for PHP/MySQL
https://github.com/tomkyle/rbac
Last synced: 4 days ago
JSON representation
RBAC: Roles, Permissions and ACL for PHP/MySQL
- Host: GitHub
- URL: https://github.com/tomkyle/rbac
- Owner: tomkyle
- License: mit
- Created: 2014-03-05T20:40:22.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-03-12T08:32:43.000Z (over 12 years ago)
- Last Synced: 2024-12-29T11:45:34.394Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 230 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
#tomkyle/rbac
Role-based access control solution, extracted from my legacy codebase.
It provides a **permissions** and **roles** system as well as a simple **ACL implementation.**
[](https://scrutinizer-ci.com/g/tomkyle/RBAC/)
##Core concepts
###Roles
A client may be associated with certain roles, e.g. *Authors* or *Admins*.
These are stored in a `RolesStorage` object that contains role IDs.
```php
contains( 2 ) ? "YES" : "NO";
```
###ACL
A service may be restricted to certain roles.
`AccessControlList` as an extension of `RolesStorage` will do that:
```php
setAccessControlList( new AccessControlList( 1, 2) );
$user = new MyUser;
$user->setRoles( new RolesStorage( 2, 3 ) );
echo $service->isAllowed( $user ) ? "YES" : "NO";
```
###Permissions
A client may be allowed or disallowed to do certain things.
`PermissionsStorage` will do that:
```php
hasPermission( "my_action" ) ? "YES" : "NO";
```
##Installation
This library has no dependencies except a PDO connection. Install from command line or `composer.json` file:
#####Command line
composer require tomykle/rbac
#####composer.json
"require": {
"tomkyle/rbac": "dev-master"
}
#####MySQL
This package comes with two MySQL dumps, `install.sql.dist` and `install.sample-data.sql.dist`. Simply execute their contents; former installs tables, indices and unique constraints, dropping existing tables; latter adds sample data. See comments in table info or field comments.
The databasa schema uses InnoDB tables for better transaction and relation handling, although currently not using these features (since I never have worked with it yet).
##Database
Roles, Permissions and their respective associations to clients are stored in a bunch of database tables:
| Table | Description |
| :----- | :---------- |
| tomkyle_roles | Defines all roles (aka *user groups*) the application works with. |
| tomkyle_permissions | Holds permissions the application works with.|
| tomkyle_permissions_roles_mm | Associates permissions with one or many roles. |
| tomkyle_clients_roles_mm | Associates a client with one or many roles.|
| tomkyle_clients_permissions_adjust | Adjusts a clients' permissions, overriding the ones he is granted or permitted due to his roles |
##Administration
Sorry, currently there is no administration tool available. I used to manage them manually in the database. Anyhow, `unique` constraints will prevent you from adding doublettes. So if you have to delete a certain role or permission, do not forget the relation tables that refer to their primary key.