DbAcl.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @package Cake.Controller.Component.Acl
  12. * @since CakePHP(tm) v 0.10.0.1076
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. App::uses('AclInterface', 'Controller/Component/Acl');
  16. App::uses('Hash', 'Utility');
  17. /**
  18. * DbAcl implements an ACL control system in the database. ARO's and ACO's are
  19. * structured into trees and a linking table is used to define permissions. You
  20. * can install the schema for DbAcl with the Schema Shell.
  21. *
  22. * `$aco` and `$aro` parameters can be slash delimited paths to tree nodes.
  23. *
  24. * eg. `controllers/Users/edit`
  25. *
  26. * Would point to a tree structure like
  27. *
  28. * {{{
  29. * controllers
  30. * Users
  31. * edit
  32. * }}}
  33. *
  34. * @package Cake.Controller.Component.Acl
  35. */
  36. class DbAcl extends Object implements AclInterface {
  37. /**
  38. * Constructor
  39. *
  40. */
  41. public function __construct() {
  42. parent::__construct();
  43. $this->Permission = ClassRegistry::init(array('class' => 'Permission', 'alias' => 'Permission'));
  44. $this->Aro = $this->Permission->Aro;
  45. $this->Aco = $this->Permission->Aco;
  46. }
  47. /**
  48. * Initializes the containing component and sets the Aro/Aco objects to it.
  49. *
  50. * @param AclComponent $component
  51. * @return void
  52. */
  53. public function initialize(Component $component) {
  54. $component->Aro = $this->Aro;
  55. $component->Aco = $this->Aco;
  56. }
  57. /**
  58. * Checks if the given $aro has access to action $action in $aco
  59. *
  60. * @param string $aro ARO The requesting object identifier.
  61. * @param string $aco ACO The controlled object identifier.
  62. * @param string $action Action (defaults to *)
  63. * @return boolean Success (true if ARO has access to action in ACO, false otherwise)
  64. * @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#checking-permissions-the-acl-component
  65. */
  66. public function check($aro, $aco, $action = "*") {
  67. return $this->Permission->check($aro, $aco, $action);
  68. }
  69. /**
  70. * Allow $aro to have access to action $actions in $aco
  71. *
  72. * @param string $aro ARO The requesting object identifier.
  73. * @param string $aco ACO The controlled object identifier.
  74. * @param string $actions Action (defaults to *)
  75. * @param integer $value Value to indicate access type (1 to give access, -1 to deny, 0 to inherit)
  76. * @return boolean Success
  77. * @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#assigning-permissions
  78. */
  79. public function allow($aro, $aco, $actions = "*", $value = 1) {
  80. return $this->Permission->allow($aro, $aco, $actions, $value);
  81. }
  82. /**
  83. * Deny access for $aro to action $action in $aco
  84. *
  85. * @param string $aro ARO The requesting object identifier.
  86. * @param string $aco ACO The controlled object identifier.
  87. * @param string $action Action (defaults to *)
  88. * @return boolean Success
  89. * @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#assigning-permissions
  90. */
  91. public function deny($aro, $aco, $action = "*") {
  92. return $this->allow($aro, $aco, $action, -1);
  93. }
  94. /**
  95. * Let access for $aro to action $action in $aco be inherited
  96. *
  97. * @param string $aro ARO The requesting object identifier.
  98. * @param string $aco ACO The controlled object identifier.
  99. * @param string $action Action (defaults to *)
  100. * @return boolean Success
  101. */
  102. public function inherit($aro, $aco, $action = "*") {
  103. return $this->allow($aro, $aco, $action, 0);
  104. }
  105. /**
  106. * Allow $aro to have access to action $actions in $aco
  107. *
  108. * @param string $aro ARO The requesting object identifier.
  109. * @param string $aco ACO The controlled object identifier.
  110. * @param string $action Action (defaults to *)
  111. * @return boolean Success
  112. * @see allow()
  113. */
  114. public function grant($aro, $aco, $action = "*") {
  115. return $this->allow($aro, $aco, $action);
  116. }
  117. /**
  118. * Deny access for $aro to action $action in $aco
  119. *
  120. * @param string $aro ARO The requesting object identifier.
  121. * @param string $aco ACO The controlled object identifier.
  122. * @param string $action Action (defaults to *)
  123. * @return boolean Success
  124. * @see deny()
  125. */
  126. public function revoke($aro, $aco, $action = "*") {
  127. return $this->deny($aro, $aco, $action);
  128. }
  129. /**
  130. * Get an array of access-control links between the given Aro and Aco
  131. *
  132. * @param string $aro ARO The requesting object identifier.
  133. * @param string $aco ACO The controlled object identifier.
  134. * @return array Indexed array with: 'aro', 'aco' and 'link'
  135. */
  136. public function getAclLink($aro, $aco) {
  137. return $this->Permission->getAclLink($aro, $aco);
  138. }
  139. /**
  140. * Get the keys used in an ACO
  141. *
  142. * @param array $keys Permission model info
  143. * @return array ACO keys
  144. */
  145. protected function _getAcoKeys($keys) {
  146. return $this->Permission->getAcoKeys($keys);
  147. }
  148. }