Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. <?php
  2. class RbacCommand extends CConsoleCommand
  3. {
  4. private $_authManager;
  5.  
  6. public function getHelp()
  7. {
  8. return <<<EOD
  9. USAGE
  10. rbac
  11.  
  12. DESCRIPTION
  13. This command generates an initial RBAC authorization hierarchy.
  14. EOD;
  15. }
  16.  
  17. public function run($args)
  18. {
  19. if(($this->_authManager = Yii::app()->authManager) === null)
  20. {
  21. echo "Error: an authorization manager, named 'authManager' must be configured to use this command. \n";
  22. echo "If you already added 'authManager' component in application configuration, \n";
  23. echo "please quit and re-enter the yiic shell. \n";
  24. return;
  25. }
  26.  
  27. echo "This command will create three roles: Owner, Member and Reader and the following permissions: \n";
  28. echo "create, read, update and delete user\n";
  29. echo "create, read, update and delete project\n";
  30. echo "create, read, update and delete issue\n";
  31. echo "Would you like to continue? [Yes|No] ";
  32.  
  33. if(!strncasecmp(trim(fgets(STDIN)),'y',1))
  34. {
  35. //for user
  36. $this->_authManager->clearAll();
  37. $this->_authManager->createOperation("createUser","create a new user");
  38. $this->_authManager->createOperation("readUser","read user profile information");
  39. $this->_authManager->createOperation("updateUser","update a users information");
  40. $this->_authManager->createOperation("deleteUser","remove a user from a project");
  41.  
  42. //for projects
  43. $this->_authManager->createOperation("createProject","create a new project");
  44. $this->_authManager->createOperation("readProject","read project information");
  45. $this->_authManager->createOperation("updateProject","update project information");
  46. $this->_authManager->createOperation("deleteProject","delete a project");
  47.  
  48. //for issues
  49. $this->_authManager->createOperation("createIssue","create a new issue");
  50. $this->_authManager->createOperation("readIssue","read issue information");
  51. $this->_authManager->createOperation("updateIssue","update issue information");
  52. $this->_authManager->createOperation("deleteIssue","delete an issue from a project");
  53.  
  54. //create the reader role and add the appropriate permissions as children to this role
  55. $role=$this->_authManager->createRole("reader");
  56. $role->addChild("readUser");
  57. $role->addChild("readProject");
  58. $role->addChild("readIssue");
  59.  
  60. //create the member role, and add the appropriate permissions, as well as the reader role itself, as children
  61. $role=$this->_authManager->createRole("member");
  62. $role->addChild("reader");
  63. $role->addChild("createIssue");
  64. $role->addChild("updateIssue");
  65. $role->addChild("deleteIssue");
  66.  
  67. //create the owner role, and add the appropriate permissions, as well as both the reader and member roles as children
  68. $role=$this->_authManager->createRole("owner");
  69. $role->addChild("reader");
  70. $role->addChild("member");
  71. $role->addChild("createUser");
  72. $role->addChild("updateUser");
  73. $role->addChild("deleteUser");
  74. $role->addChild("createProject");
  75. $role->addChild("updateProject");
  76. $role->addChild("deleteProject");
  77.  
  78. //provide a message indicating success
  79. echo "Authorization hierarchy successfully generated.";
  80.  
  81. }
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement