2012-01-29 18:54:26 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://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.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://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-12-22 22:48:15 +00:00
|
|
|
* IniAcl implements an access control system using an INI file. An example
|
2012-01-29 18:54:26 +00:00
|
|
|
* of the ini file used can be found in /config/acl.ini.php.
|
|
|
|
*
|
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 IniAcl extends CakeObject implements AclInterface {
|
2012-01-29 18:54:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array with configuration, parsed from ini file
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $config = null;
|
|
|
|
|
|
|
|
/**
|
2012-03-11 01:57:18 +00:00
|
|
|
* The Hash::extract() path to the user/aro identifier in the
|
2012-12-22 22:48:15 +00:00
|
|
|
* acl.ini file. This path will be used to extract the string
|
2012-01-29 18:54:26 +00:00
|
|
|
* representation of a user used in the ini file.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $userPath = 'User.username';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize method
|
|
|
|
*
|
2014-06-05 04:15:45 +00:00
|
|
|
* @param Component $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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No op method, allow cannot be done with IniAcl
|
|
|
|
*
|
|
|
|
* @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 allow($aro, $aco, $action = "*") {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No op method, deny cannot be done with IniAcl
|
|
|
|
*
|
|
|
|
* @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 deny($aro, $aco, $action = "*") {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No op method, inherit cannot be done with IniAcl
|
|
|
|
*
|
|
|
|
* @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 = "*") {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main ACL check function. Checks to see if the ARO (access request object) has access to the
|
|
|
|
* ACO (access control object).Looks at the acl.ini.php file for permissions
|
|
|
|
* (see instructions in /config/acl.ini.php).
|
|
|
|
*
|
|
|
|
* @param string $aro ARO
|
|
|
|
* @param string $aco ACO
|
2012-03-04 00:27:46 +00:00
|
|
|
* @param string $action Action
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2012-01-29 18:54:26 +00:00
|
|
|
*/
|
2012-03-04 00:27:46 +00:00
|
|
|
public function check($aro, $aco, $action = null) {
|
2012-09-14 17:26:30 +00:00
|
|
|
if (!$this->config) {
|
2012-01-29 18:54:26 +00:00
|
|
|
$this->config = $this->readConfigFile(APP . 'Config' . DS . 'acl.ini.php');
|
|
|
|
}
|
|
|
|
$aclConfig = $this->config;
|
|
|
|
|
|
|
|
if (is_array($aro)) {
|
2012-03-11 01:57:18 +00:00
|
|
|
$aro = Hash::get($aro, $this->userPath);
|
2012-01-29 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($aclConfig[$aro]['deny'])) {
|
|
|
|
$userDenies = $this->arrayTrim(explode(",", $aclConfig[$aro]['deny']));
|
|
|
|
|
|
|
|
if (array_search($aco, $userDenies)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($aclConfig[$aro]['allow'])) {
|
|
|
|
$userAllows = $this->arrayTrim(explode(",", $aclConfig[$aro]['allow']));
|
|
|
|
|
|
|
|
if (array_search($aco, $userAllows)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($aclConfig[$aro]['groups'])) {
|
|
|
|
$userGroups = $this->arrayTrim(explode(",", $aclConfig[$aro]['groups']));
|
|
|
|
|
|
|
|
foreach ($userGroups as $group) {
|
|
|
|
if (array_key_exists($group, $aclConfig)) {
|
|
|
|
if (isset($aclConfig[$group]['deny'])) {
|
|
|
|
$groupDenies = $this->arrayTrim(explode(",", $aclConfig[$group]['deny']));
|
|
|
|
|
|
|
|
if (array_search($aco, $groupDenies)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($aclConfig[$group]['allow'])) {
|
|
|
|
$groupAllows = $this->arrayTrim(explode(",", $aclConfig[$group]['allow']));
|
|
|
|
|
|
|
|
if (array_search($aco, $groupAllows)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-18 01:55:29 +00:00
|
|
|
* Parses an INI file and returns an array that reflects the
|
2012-03-04 00:27:46 +00:00
|
|
|
* INI file's section structure. Double-quote friendly.
|
2012-01-29 18:54:26 +00:00
|
|
|
*
|
|
|
|
* @param string $filename File
|
|
|
|
* @return array INI section structure
|
|
|
|
*/
|
|
|
|
public function readConfigFile($filename) {
|
|
|
|
App::uses('IniReader', 'Configure');
|
|
|
|
$iniFile = new IniReader(dirname($filename) . DS);
|
|
|
|
return $iniFile->read(basename($filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes trailing spaces on all array elements (to prepare for searching)
|
|
|
|
*
|
|
|
|
* @param array $array Array to trim
|
|
|
|
* @return array Trimmed array
|
|
|
|
*/
|
|
|
|
public function arrayTrim($array) {
|
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
$array[$key] = trim($value);
|
|
|
|
}
|
|
|
|
array_unshift($array, "");
|
|
|
|
return $array;
|
|
|
|
}
|
2012-03-04 00:27:46 +00:00
|
|
|
|
2012-01-29 18:54:26 +00:00
|
|
|
}
|