Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class RbacCommand extends CConsoleCommand
- {
- private $_authManager;
- public function getHelp()
- {
- return <<<EOD
- USAGE
- rbac
- DESCRIPTION
- This command generates an initial RBAC authorization hierarchy.
- EOD;
- }
- /**
- * Execute the action.
- * @param array command line parameters specific for this command
- */
- public function run($args)
- {
- //ensure that an authManager is defined as this is mandatory for creating an auth heirarchy
- if(($this->_authManager=Yii::app()->authManager)===null)
- {
- echo "Error: an authorization manager, named 'authManager'
- must be configured to use this command.\n";
- echo "If you already added 'authManager' component in
- application configuration,\n";
- echo "please quit and re-enter the yiic shell.\n";
- return;
- }
- //provide the oportunity for the use to abort the request
- echo "This command will create three roles: superadmin, admin1, and
- normaluser and the following premissions:\n";
- echo "create, read, update and delete user\n";
- echo "Would you like to continue? [Yes|No] ";
- //check the input from the user and continue if they indicated yes to the above question
- if(!strncasecmp(trim(fgets(STDIN)),'y',1))
- {
- //first we need to remove all operations, roles, child relationship and assignments
- $this->_authManager->clearAll();
- //create the lowest level operations for users
- $this->_authManager->createOperation("createUser","create a new user");
- $this->_authManager->createOperation("readUser","read user profile information");
- $this->_authManager->createOperation("updateUser","update a users information");
- $this->_authManager->createOperation("deleteUser","remove a user");
- $role=$this->_authManager->createRole("normaluser");
- $role->addChild("readUser");
- $role=$this->_authManager->createRole("admin1");
- $role->addChild("normaluser");
- $role->addChild("createUser");
- $role->addChild("updateUser");
- $role=$this->_authManager->createRole("superadmin");
- $role->addChild("normaluser");
- $role->addChild("admin1");
- $role->addChild("createUser");
- $role->addChild("updateUser");
- $role->addChild("deleteUser");
- //provide a message indicating success
- echo "Authorization hierarchy successfully generated.";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement