2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2008-05-30 11:40:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Controller.Component
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 0.10.0.1076
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2010-12-22 04:35:46 +00:00
|
|
|
App::uses('Component', 'Controller');
|
2012-01-29 18:54:26 +00:00
|
|
|
App::uses('AclInterface', 'Controller/Component/Acl');
|
2010-12-22 04:35:46 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Access Control List factory class.
|
|
|
|
*
|
2010-03-28 16:17:53 +00:00
|
|
|
* Uses a strategy pattern to allow custom ACL implementations to be used with the same component interface.
|
2014-04-11 19:10:56 +00:00
|
|
|
* You can define by changing `Configure::write('Acl.classname', 'DbAcl');` in your core.php. The adapter
|
|
|
|
* you specify must implement `AclInterface`
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Controller.Component
|
2011-10-15 15:13:26 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-07-04 19:12:42 +00:00
|
|
|
class AclComponent extends Component {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Instance of an ACL class
|
|
|
|
*
|
2011-08-01 02:57:17 +00:00
|
|
|
* @var AclInterface
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_Instance = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-04 22:41:08 +00:00
|
|
|
/**
|
|
|
|
* Aro object.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $Aro;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Aco object
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $Aco;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-03-28 16:17:53 +00:00
|
|
|
* Constructor. Will return an instance of the correct ACL class as defined in `Configure::read('Acl.classname')`
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2014-05-31 21:36:05 +00:00
|
|
|
* @param ComponentCollection $collection Collection instance.
|
|
|
|
* @param array $settings Settings list.
|
2010-12-12 00:01:07 +00:00
|
|
|
* @throws CakeException when Acl.classname could not be loaded.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-07-04 21:09:44 +00:00
|
|
|
public function __construct(ComponentCollection $collection, $settings = array()) {
|
|
|
|
parent::__construct($collection, $settings);
|
2012-01-29 18:56:53 +00:00
|
|
|
$name = Configure::read('Acl.classname');
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!class_exists($name)) {
|
2012-01-29 18:54:26 +00:00
|
|
|
list($plugin, $name) = pluginSplit($name, true);
|
2012-02-21 14:21:15 +00:00
|
|
|
App::uses($name, $plugin . 'Controller/Component/Acl');
|
|
|
|
if (!class_exists($name)) {
|
2011-03-20 15:35:43 +00:00
|
|
|
throw new CakeException(__d('cake_dev', 'Could not find %s.', $name));
|
2010-04-24 03:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->adapter($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets or gets the Adapter object currently in the AclComponent.
|
|
|
|
*
|
|
|
|
* `$this->Acl->adapter();` will get the current adapter class while
|
|
|
|
* `$this->Acl->adapter($obj);` will set the adapter class
|
|
|
|
*
|
|
|
|
* Will call the initialize method on the adapter if setting a new one.
|
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param AclInterface|string $adapter Instance of AclInterface or a string name of the class to use. (optional)
|
|
|
|
* @return AclInterface|void either null, or the adapter implementation.
|
2012-03-14 01:04:56 +00:00
|
|
|
* @throws CakeException when the given class is not an instance of AclInterface
|
2010-04-24 03:03:51 +00:00
|
|
|
*/
|
|
|
|
public function adapter($adapter = null) {
|
|
|
|
if ($adapter) {
|
|
|
|
if (is_string($adapter)) {
|
|
|
|
$adapter = new $adapter();
|
|
|
|
}
|
2010-04-24 03:52:36 +00:00
|
|
|
if (!$adapter instanceof AclInterface) {
|
2011-03-20 15:35:43 +00:00
|
|
|
throw new CakeException(__d('cake_dev', 'AclComponent adapters must implement AclInterface'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-04-24 03:03:51 +00:00
|
|
|
$this->_Instance = $adapter;
|
|
|
|
$this->_Instance->initialize($this);
|
|
|
|
return;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-04-24 03:03:51 +00:00
|
|
|
return $this->_Instance;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* Pass-thru function for ACL check instance. Check methods
|
2010-03-28 16:17:53 +00:00
|
|
|
* are used to check whether or not an ARO can access an ACO
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
|
|
|
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function check($aro, $aco, $action = "*") {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_Instance->check($aro, $aco, $action);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-03-28 16:17:53 +00:00
|
|
|
* Pass-thru function for ACL allow instance. Allow methods
|
|
|
|
* are used to grant an ARO access to an ACO.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
|
|
|
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function allow($aro, $aco, $action = "*") {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_Instance->allow($aro, $aco, $action);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-03-28 16:17:53 +00:00
|
|
|
* Pass-thru function for ACL deny instance. Deny methods
|
|
|
|
* are used to remove permission from an ARO to access an ACO.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
|
|
|
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function deny($aro, $aco, $action = "*") {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_Instance->deny($aro, $aco, $action);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-03-28 16:17:53 +00:00
|
|
|
* Pass-thru function for ACL inherit instance. Inherit methods
|
|
|
|
* modify the permission for an ARO to be that of its parent object.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
|
|
|
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function inherit($aro, $aco, $action = "*") {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_Instance->inherit($aro, $aco, $action);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-03-28 16:17:53 +00:00
|
|
|
* Pass-thru function for ACL grant instance. An alias for AclComponent::allow()
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
|
|
|
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2014-09-02 15:03:22 +00:00
|
|
|
* @deprecated 3.0.0 Will be removed in 3.0.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function grant($aro, $aco, $action = "*") {
|
2013-08-16 09:39:38 +00:00
|
|
|
trigger_error(__d('cake_dev', '%s is deprecated, use %s instead', 'AclComponent::grant()', 'allow()'), E_USER_WARNING);
|
2010-09-09 02:48:21 +00:00
|
|
|
return $this->_Instance->allow($aro, $aco, $action);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-03-28 16:17:53 +00:00
|
|
|
* Pass-thru function for ACL grant instance. An alias for AclComponent::deny()
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
|
|
|
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2014-09-02 15:03:22 +00:00
|
|
|
* @deprecated 3.0.0 Will be removed in 3.0.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function revoke($aro, $aco, $action = "*") {
|
2013-08-16 09:39:38 +00:00
|
|
|
trigger_error(__d('cake_dev', '%s is deprecated, use %s instead', 'AclComponent::revoke()', 'deny()'), E_USER_WARNING);
|
2010-09-09 02:48:21 +00:00
|
|
|
return $this->_Instance->deny($aro, $aco, $action);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-04-24 03:52:36 +00:00
|
|
|
|
2012-03-04 00:27:46 +00:00
|
|
|
}
|