https://github.com/codemix/hybridauthmanager
An AuthManager for Yii that stores the hierarchy in a flat PHP file and the assignments in DB
https://github.com/codemix/hybridauthmanager
Last synced: 10 months ago
JSON representation
An AuthManager for Yii that stores the hierarchy in a flat PHP file and the assignments in DB
- Host: GitHub
- URL: https://github.com/codemix/hybridauthmanager
- Owner: codemix
- License: mit
- Created: 2013-08-05T13:09:31.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-08-22T19:12:32.000Z (over 12 years ago)
- Last Synced: 2025-01-20T01:34:47.587Z (12 months ago)
- Language: PHP
- Homepage:
- Size: 78.1 KB
- Stars: 0
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
HybridAuthManager
=================
An AuthManager for Yii that stores the hierarchy in a flat PHP file and the assignmens in DB.
This class is a combination of CDbAuthManager and CPhpAuthManager:
* The authorization hierarchy is stored in a flat PHP file
* Authorization assignments are stored in the database
This is useful if the authorization hierarchy is almost static and not very complex.
You can manage the authorization hierarchy in data/auth.php. To not loose the comments there,
you should avoid to call any method to create auth items or add child items - even though it's supported.
## Installation
We recommend to install the extension with [composer](http://getcomposer.org/). Add this to
the `require` section of your `composer.json`:
'codemix/hybridautmanager' : 'dev-master'
> Note: There's no stable version yet.
If you haven't yet, you should also add an alias to composer's vendor directory.
```php
$vendor = realpath(__DIR__.'/../vendor');
return array(
'alias' => array(
'vendor' => realpath(__DIR__.'/../vendor'), // Fix this path
),
...
```
## Configuration
Add this configuration to your `main.php`:
```php
'components' => array(
'authManager' => array(
'class' => 'vendor.codemix.hybridautmanager.HybridAuthManager',
),
...
),
```
Just as with [`CPhpAuthManager`](http://www.yiiframework.com/doc/api/1.1/CPhpAuthManager) you'll
need to supply a file with auth rules. By default this is in `data/auth.php`. But here you only
have to supply the auth hierarchy:
```php
return array(
// Admin == Root (Full permissions).
'Admin' => array(
'type' => CAuthItem::TYPE_ROLE,
'description' => 'Administrator',
'children' => array(
'manageUser',
'managePosts',
),
),
'manageUser' => array(
'type' => CAuthItem::TYPE_TASK,
'children' => array(
'createUser',
'updateUser',
'deleteUser',
'readUser',
),
),
'createUser' => array('type' => CAuthItem::TYPE_OPERATION),
'updateUser' => array('type' => CAuthItem::TYPE_OPERATION),
'deleteUser' => array('type' => CAuthItem::TYPE_OPERATION),
'readUser' => array('type' => CAuthItem::TYPE_OPERATION),
);
```
The content of this file will be cached unless you set `cacheID` to `null`.
The actual Role assignments will be saved in a DB table `auth_assignments` by default.
You can change this name with the `assignmentTable` property of the `authManager` component.
## Caching
The component can cache the RBAC hierarchy and auth assignments. You can configure
the cache component ID on `cacheID`.
### Caching hierarchy
By default the hierarchy file content is cache `3600` seconds. You can configure this
through `hierarchyCachingDuration`.
### Caching auth assigments
You can set the number of seconds to cache auth assignments in `assignmentCachingDuration`.
The assignments will be cached per user to avoid DB calls on each request. By default this
is set to `0` which means, that assignments will only be cached throughout the current
requests, i.e. on consecutive calls of `checkAccess()`.
Set this property to `false` to completely disable caching.