gozoro / yii2-rbac-console
RBAC configuration and managment tool in the console.
Installs: 8
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.5.9
- yiisoft/yii2: ~2.0.0
README
RBAC configuration and managment tool in the console.
Installation
composer require gozoro/yii2-rbac-console
Preparation
Create console controller commands\RbacController.php
.
namespace app\commands; class RbacController extends \gozoro\yii2\rbac\console\RbacController; { public function findIdentityByUsername($username) { //TODO:: Return an instance of the class with interface \yii\web\Identity // example: //return UserIdentity::find()->where(['username'=>$username])->one(); } public function findIdentityById($userId) { //TODO:: Return an instance of the class with interface \yii\web\Identity // example: //return UserIdentity::find()->where(['id'=>$userId])->one(); } }
Controller actions
-
./yii rbac/init
Performs initial RBAC configuration (remembers user roles, deletes all data, revert data from the config, restores users roles). You can use it after adding new roles or removing not need roles. -
rbac/show-config
Displays config (default config:@app/config/rbac.php
). -
rbac/roles
Displays a list of roles from AuthManager. -
rbac/permissions
Displays a list of permissions from AuthManager. -
rbac/rules
Displays a list of rules from AuthManager. -
rbac/show
(default) Displays a list of roles and users. -
rbac/show-user
Displays roles and permissions of user. -
rbac/assign
Assigns a role (or a permission) to a user. -
rbac/unassign
Revokes role or permission from a user. -
rbac/unassign-all
Revokes all roles and permissions from a user.
Configuration
Create config @app/config/rbac.php
.
Example:
return [ // Permission list 'permissions' =>[ 'read' => 'permissions for read something', // permission_name => description 'write' => 'permissions for write something', // permission_name => description 'permission_master' => $permision, // permission_name => permission object 'permission_slave' => [ // permission_name => permission as array 'name' => ..., 'description' => ..., 'data' => ..., ], ], // Role list 'roles' => [ 'role_admin' => 'Administrator role', // role_name => description 'role_manager' => 'Manager role', // role_name => description 'role_viewer' => $role, // role_name => role_object 'role_something' => [ // role_name => role as array 'name' => ..., 'description' => ..., 'data' => ..., ], ], // Rule list 'rules' => [ \WriteRule:class => ['write'], // rule for permission "write" $rule => ['write', 'read'], // rule object for permissions "write" and "read" ], // Mapping roles to permissions 'access' => [ 'permission_master' => ['permission_slave'], 'role_admin' => ['read', 'write'], // array of permissions 'role_manager' => ['read', 'permission_master'], ], ];
Use command ./yii rbac/init
to initialize or re-initialize RBAC-scheme from config.