2012-01-29 18:54:26 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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)
|
2012-01-29 18:54:26 +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
|
2012-01-29 18:54:26 +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)
|
2012-01-29 18:54:26 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2012-12-03 21:46:52 +00:00
|
|
|
* @package Cake.Controller.Component.Acl
|
2012-01-29 18:54: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
|
2012-01-29 18:54:26 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2012-01-29 18:54:26 +00:00
|
|
|
App::uses('AclInterface', 'Controller/Component/Acl');
|
2012-03-11 01:57:18 +00:00
|
|
|
App::uses('Hash', 'Utility');
|
2013-02-01 15:46:25 +00:00
|
|
|
App::uses('ClassRegistry', 'Utility');
|
2012-01-29 18:54:26 +00:00
|
|
|
|
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* DbAcl implements an ACL control system in the database. ARO's and ACO's are
|
|
|
|
* structured into trees and a linking table is used to define permissions. You
|
2012-01-29 18:54:26 +00:00
|
|
|
* can install the schema for DbAcl with the Schema Shell.
|
|
|
|
*
|
|
|
|
* `$aco` and `$aro` parameters can be slash delimited paths to tree nodes.
|
|
|
|
*
|
|
|
|
* eg. `controllers/Users/edit`
|
|
|
|
*
|
|
|
|
* Would point to a tree structure like
|
|
|
|
*
|
2015-01-09 12:47:25 +00:00
|
|
|
* ```
|
2012-01-29 18:54:26 +00:00
|
|
|
* controllers
|
|
|
|
* Users
|
|
|
|
* edit
|
2015-01-09 12:47:25 +00:00
|
|
|
* ```
|
2012-01-29 18:54:26 +00:00
|
|
|
*
|
2012-12-03 21:46:52 +00:00
|
|
|
* @package Cake.Controller.Component.Acl
|
2012-01-29 18:54:26 +00:00
|
|
|
*/
|
2016-04-08 12:33:26 +00:00
|
|
|
class DbAcl extends CakeObject implements AclInterface {
|
2012-01-29 18:54:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
2012-02-21 14:21:15 +00:00
|
|
|
$this->Permission = ClassRegistry::init(array('class' => 'Permission', 'alias' => 'Permission'));
|
|
|
|
$this->Aro = $this->Permission->Aro;
|
|
|
|
$this->Aco = $this->Permission->Aco;
|
2012-01-29 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the containing component and sets the Aro/Aco objects to it.
|
|
|
|
*
|
2014-06-05 04:15:45 +00:00
|
|
|
* @param AclComponent $component The AclComponent instance.
|
2012-01-29 18:54:26 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 14:06:25 +00:00
|
|
|
public function initialize(Component $component) {
|
2012-01-29 18:54:26 +00:00
|
|
|
$component->Aro = $this->Aro;
|
|
|
|
$component->Aco = $this->Aco;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given $aro has access to action $action in $aco
|
|
|
|
*
|
|
|
|
* @param string $aro ARO The requesting object identifier.
|
|
|
|
* @param string $aco ACO The controlled object identifier.
|
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success (true if ARO has access to action in ACO, false otherwise)
|
2012-01-29 18:54:26 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#checking-permissions-the-acl-component
|
|
|
|
*/
|
|
|
|
public function check($aro, $aco, $action = "*") {
|
2012-02-21 14:21:15 +00:00
|
|
|
return $this->Permission->check($aro, $aco, $action);
|
2012-01-29 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow $aro to have access to action $actions in $aco
|
|
|
|
*
|
|
|
|
* @param string $aro ARO The requesting object identifier.
|
|
|
|
* @param string $aco ACO The controlled object identifier.
|
|
|
|
* @param string $actions Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $value Value to indicate access type (1 to give access, -1 to deny, 0 to inherit)
|
|
|
|
* @return bool Success
|
2012-01-29 18:54:26 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#assigning-permissions
|
|
|
|
*/
|
|
|
|
public function allow($aro, $aco, $actions = "*", $value = 1) {
|
2012-02-21 14:21:15 +00:00
|
|
|
return $this->Permission->allow($aro, $aco, $actions, $value);
|
2012-01-29 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deny access for $aro to action $action in $aco
|
|
|
|
*
|
|
|
|
* @param string $aro ARO The requesting object identifier.
|
|
|
|
* @param string $aco ACO The controlled object identifier.
|
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2012-01-29 18:54:26 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#assigning-permissions
|
|
|
|
*/
|
|
|
|
public function deny($aro, $aco, $action = "*") {
|
|
|
|
return $this->allow($aro, $aco, $action, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Let access for $aro to action $action in $aco be inherited
|
|
|
|
*
|
|
|
|
* @param string $aro ARO The requesting object identifier.
|
|
|
|
* @param string $aco ACO The controlled object identifier.
|
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2012-01-29 18:54:26 +00:00
|
|
|
*/
|
|
|
|
public function inherit($aro, $aco, $action = "*") {
|
|
|
|
return $this->allow($aro, $aco, $action, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow $aro to have access to action $actions in $aco
|
|
|
|
*
|
|
|
|
* @param string $aro ARO The requesting object identifier.
|
|
|
|
* @param string $aco ACO The controlled object identifier.
|
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2012-01-29 18:54:26 +00:00
|
|
|
* @see allow()
|
|
|
|
*/
|
|
|
|
public function grant($aro, $aco, $action = "*") {
|
|
|
|
return $this->allow($aro, $aco, $action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deny access for $aro to action $action in $aco
|
|
|
|
*
|
|
|
|
* @param string $aro ARO The requesting object identifier.
|
|
|
|
* @param string $aco ACO The controlled object identifier.
|
|
|
|
* @param string $action Action (defaults to *)
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2012-01-29 18:54:26 +00:00
|
|
|
* @see deny()
|
|
|
|
*/
|
|
|
|
public function revoke($aro, $aco, $action = "*") {
|
|
|
|
return $this->deny($aro, $aco, $action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an array of access-control links between the given Aro and Aco
|
|
|
|
*
|
|
|
|
* @param string $aro ARO The requesting object identifier.
|
|
|
|
* @param string $aco ACO The controlled object identifier.
|
|
|
|
* @return array Indexed array with: 'aro', 'aco' and 'link'
|
|
|
|
*/
|
|
|
|
public function getAclLink($aro, $aco) {
|
2012-02-21 14:21:15 +00:00
|
|
|
return $this->Permission->getAclLink($aro, $aco);
|
2012-01-29 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the keys used in an ACO
|
|
|
|
*
|
|
|
|
* @param array $keys Permission model info
|
|
|
|
* @return array ACO keys
|
|
|
|
*/
|
|
|
|
protected function _getAcoKeys($keys) {
|
2012-02-21 14:21:15 +00:00
|
|
|
return $this->Permission->getAcoKeys($keys);
|
2012-01-29 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-04 00:27:46 +00:00
|
|
|
}
|