PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Cake/Controller/Component/AclComponent.php

https://bitbucket.org/LeThanhDat/firstdummyapp
PHP | 179 lines | 54 code | 13 blank | 112 comment | 5 complexity | 4a286839a4422af3e1601af0018de52a MD5 | raw file
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @package Cake.Controller.Component
  13. * @since CakePHP(tm) v 0.10.0.1076
  14. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  15. */
  16. App::uses('Component', 'Controller');
  17. App::uses('AclInterface', 'Controller/Component/Acl');
  18. /**
  19. * Access Control List factory class.
  20. *
  21. * Uses a strategy pattern to allow custom ACL implementations to be used with the same component interface.
  22. * You can define by changing `Configure::write('Acl.classname', 'DbAcl');` in your core.php. Concrete ACL
  23. * implementations should extend `AclBase` and implement the methods it defines.
  24. *
  25. * @package Cake.Controller.Component
  26. * @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html
  27. */
  28. class AclComponent extends Component {
  29. /**
  30. * Instance of an ACL class
  31. *
  32. * @var AclInterface
  33. */
  34. protected $_Instance = null;
  35. /**
  36. * Aro object.
  37. *
  38. * @var string
  39. */
  40. public $Aro;
  41. /**
  42. * Aco object
  43. *
  44. * @var string
  45. */
  46. public $Aco;
  47. /**
  48. * Constructor. Will return an instance of the correct ACL class as defined in `Configure::read('Acl.classname')`
  49. *
  50. * @param ComponentCollection $collection
  51. * @param array $settings
  52. * @throws CakeException when Acl.classname could not be loaded.
  53. */
  54. public function __construct(ComponentCollection $collection, $settings = array()) {
  55. parent::__construct($collection, $settings);
  56. $name = Configure::read('Acl.classname');
  57. if (!class_exists($name)) {
  58. list($plugin, $name) = pluginSplit($name, true);
  59. App::uses($name, $plugin . 'Controller/Component/Acl');
  60. if (!class_exists($name)) {
  61. throw new CakeException(__d('cake_dev', 'Could not find %s.', $name));
  62. }
  63. }
  64. $this->adapter($name);
  65. }
  66. /**
  67. * Sets or gets the Adapter object currently in the AclComponent.
  68. *
  69. * `$this->Acl->adapter();` will get the current adapter class while
  70. * `$this->Acl->adapter($obj);` will set the adapter class
  71. *
  72. * Will call the initialize method on the adapter if setting a new one.
  73. *
  74. * @param AclInterface|string $adapter Instance of AclInterface or a string name of the class to use. (optional)
  75. * @return AclInterface|void either null, or the adapter implementation.
  76. * @throws CakeException when the given class is not an instance of AclInterface
  77. */
  78. public function adapter($adapter = null) {
  79. if ($adapter) {
  80. if (is_string($adapter)) {
  81. $adapter = new $adapter();
  82. }
  83. if (!$adapter instanceof AclInterface) {
  84. throw new CakeException(__d('cake_dev', 'AclComponent adapters must implement AclInterface'));
  85. }
  86. $this->_Instance = $adapter;
  87. $this->_Instance->initialize($this);
  88. return;
  89. }
  90. return $this->_Instance;
  91. }
  92. /**
  93. * Pass-thru function for ACL check instance. Check methods
  94. * are used to check whether or not an ARO can access an ACO
  95. *
  96. * @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
  97. * @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
  98. * @param string $action Action (defaults to *)
  99. * @return boolean Success
  100. */
  101. public function check($aro, $aco, $action = "*") {
  102. return $this->_Instance->check($aro, $aco, $action);
  103. }
  104. /**
  105. * Pass-thru function for ACL allow instance. Allow methods
  106. * are used to grant an ARO access to an ACO.
  107. *
  108. * @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
  109. * @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
  110. * @param string $action Action (defaults to *)
  111. * @return boolean Success
  112. */
  113. public function allow($aro, $aco, $action = "*") {
  114. return $this->_Instance->allow($aro, $aco, $action);
  115. }
  116. /**
  117. * Pass-thru function for ACL deny instance. Deny methods
  118. * are used to remove permission from an ARO to access an ACO.
  119. *
  120. * @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
  121. * @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
  122. * @param string $action Action (defaults to *)
  123. * @return boolean Success
  124. */
  125. public function deny($aro, $aco, $action = "*") {
  126. return $this->_Instance->deny($aro, $aco, $action);
  127. }
  128. /**
  129. * Pass-thru function for ACL inherit instance. Inherit methods
  130. * modify the permission for an ARO to be that of its parent object.
  131. *
  132. * @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
  133. * @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
  134. * @param string $action Action (defaults to *)
  135. * @return boolean Success
  136. */
  137. public function inherit($aro, $aco, $action = "*") {
  138. return $this->_Instance->inherit($aro, $aco, $action);
  139. }
  140. /**
  141. * Pass-thru function for ACL grant instance. An alias for AclComponent::allow()
  142. *
  143. * @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
  144. * @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
  145. * @param string $action Action (defaults to *)
  146. * @return boolean Success
  147. * @deprecated
  148. */
  149. public function grant($aro, $aco, $action = "*") {
  150. trigger_error(__d('cake_dev', 'AclComponent::grant() is deprecated, use allow() instead'), E_USER_WARNING);
  151. return $this->_Instance->allow($aro, $aco, $action);
  152. }
  153. /**
  154. * Pass-thru function for ACL grant instance. An alias for AclComponent::deny()
  155. *
  156. * @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
  157. * @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
  158. * @param string $action Action (defaults to *)
  159. * @return boolean Success
  160. * @deprecated
  161. */
  162. public function revoke($aro, $aco, $action = "*") {
  163. trigger_error(__d('cake_dev', 'AclComponent::revoke() is deprecated, use deny() instead'), E_USER_WARNING);
  164. return $this->_Instance->deny($aro, $aco, $action);
  165. }
  166. }