acl.php

来自「Cake Framwork , Excellent」· PHP 代码 · 共 628 行 · 第 1/2 页

PHP
628
字号
<?php/* SVN FILE: $Id: acl.php 7118 2008-06-04 20:49:29Z gwoo $ *//** * Access Control List factory class. * * Permissions system. * * PHP versions 4 and 5 * * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/> * Copyright 2005-2008, Cake Software Foundation, Inc. *								1785 E. Sahara Avenue, Suite 490-204 *								Las Vegas, Nevada 89104 * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright		Copyright 2005-2008, Cake Software Foundation, Inc. * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @package			cake * @subpackage		cake.cake.libs.controller.components * @since			CakePHP(tm) v 0.10.0.1076 * @version			$Revision: 7118 $ * @modifiedby		$LastChangedBy: gwoo $ * @lastmodified	$Date: 2008-06-04 13:49:29 -0700 (Wed, 04 Jun 2008) $ * @license			http://www.opensource.org/licenses/mit-license.php The MIT License *//** * Access Control List factory class. * * Looks for ACL implementation class in core config, and returns an instance of that class. * * @package		cake * @subpackage	cake.cake.libs.controller.components */class AclComponent extends Object {/** * Instance of an ACL class * * @var object * @access protected */	var $_Instance = null;/** * Constructor. Will return an instance of the correct ACL class. * */	function __construct() {		$name = Inflector::camelize(strtolower(Configure::read('Acl.classname')));		if (!class_exists($name)) {			if (App::import('Component', $name)) {				if (strpos($name, '.') !== false) {					list($plugin, $name) = explode('.', $name);				}				$name .= 'Component';			} else {				trigger_error(sprintf(__('Could not find %s.', true), $name), E_USER_WARNING);			}		}		$this->_Instance =& new $name();		$this->_Instance->initialize($this);	}/** * Startup is not used * * @param object $controller Controller using this component * @return boolean Proceed with component usage (true), or fail (false) * @access public */	function startup(&$controller) {		return true;	}/** * Empty class defintion, to be overridden in subclasses. * * @access protected */	function _initACL() {	}/** * Pass-thru function for ACL check instance. * * @param string $aro ARO * @param string $aco ACO * @param string $action Action (defaults to *) * @return boolean Success * @access public */	function check($aro, $aco, $action = "*") {		return $this->_Instance->check($aro, $aco, $action);	}/** * Pass-thru function for ACL allow instance. * * @param string $aro ARO * @param string $aco ACO * @param string $action Action (defaults to *) * @return boolean Success * @access public */	function allow($aro, $aco, $action = "*") {		return $this->_Instance->allow($aro, $aco, $action);	}/** * Pass-thru function for ACL deny instance. * * @param string $aro ARO * @param string $aco ACO * @param string $action Action (defaults to *) * @return boolean Success * @access public */	function deny($aro, $aco, $action = "*") {		return $this->_Instance->deny($aro, $aco, $action);	}/** * Pass-thru function for ACL inherit instance. * * @param string $aro ARO * @param string $aco ACO * @param string $action Action (defaults to *) * @return boolean Success * @access public */	function inherit($aro, $aco, $action = "*") {		return $this->_Instance->inherit($aro, $aco, $action);	}/** * Pass-thru function for ACL grant instance. * * @param string $aro ARO * @param string $aco ACO * @param string $action Action (defaults to *) * @return boolean Success * @access public */	function grant($aro, $aco, $action = "*") {		return $this->_Instance->grant($aro, $aco, $action);	}/** * Pass-thru function for ACL grant instance. * * @param string $aro ARO * @param string $aco ACO * @param string $action Action (defaults to *) * @return boolean Success * @access public */	function revoke($aro, $aco, $action = "*") {		return $this->_Instance->revoke($aro, $aco, $action);	}/** * Sets the current ARO instance to object from getAro * * @param string $id ID of ARO * @return boolean Success * @access public */	function setAro($id) {		return $this->Aro = $this->_Instance->getAro($id);	}/*** Sets the current ACO instance to object from getAco * * @param string $id ID of ACO * @return boolean Success * @access public */	function setAco($id) {		return $this->Aco = $this->_Instance->getAco($id);	}/** * Pass-thru function for ACL getAro instance * that gets an ARO object from the given id or alias * * @param string $id ARO id * @return object ARO * @access public */	function getAro($id) {		return $this->_Instance->getAro($id);	}/** * Pass-thru function for ACL getAco instance. * that gets an ACO object from the given id or alias * * @param string $id ACO id * @return object ACO * @access public */	function getAco($id) {		return $this->_Instance->getAco($id);	}}/** * Access Control List abstract class. Not to be instantiated. * Subclasses of this class are used by AclComponent to perform ACL checks in Cake. * * @package 	cake * @subpackage	cake.cake.libs.controller.components * @abstract */class AclBase extends Object {/** * This class should never be instantiated, just subclassed. * */	function __construct() {		if (strcasecmp(get_class($this), "AclBase") == 0 || !is_subclass_of($this, "AclBase")) {			trigger_error(__("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration.", true), E_USER_ERROR);			return NULL;		}	}/** * Empty method to be overridden in subclasses * * @param string $aro ARO * @param string $aco ACO * @param string $action Action (defaults to *) * @access public */	function check($aro, $aco, $action = "*") {	}/** * Empty method to be overridden in subclasses * * @param object $component Component * @access public */	function initialize(&$component) {	}}/** * In this file you can extend the AclBase. * * @package		cake * @subpackage	cake.cake.libs.model */class DbAcl extends AclBase {/** * Constructor * */	function __construct() {		parent::__construct();		uses('model' . DS . 'db_acl');		$this->Aro =& ClassRegistry::init(array('class' => 'Aro', 'alias' => 'Aro'));		$this->Aco =& ClassRegistry::init(array('class' => 'Aco', 'alias' => 'Aco'));	}/** * Enter description here... * * @param object $component * @access public */	function initialize(&$component) {		$component->Aro = $this->Aro;		$component->Aco = $this->Aco;	}/** * Checks if the given $aro has access to action $action in $aco * * @param string $aro ARO * @param string $aco ACO * @param string $action Action (defaults to *) * @return boolean Success (true if ARO has access to action in ACO, false otherwise) * @access public */	function check($aro, $aco, $action = "*") {		if ($aro == null || $aco == null) {			return false;		}		$permKeys = $this->_getAcoKeys($this->Aro->Permission->schema());		$aroPath = $this->Aro->node($aro);		$acoPath = new Set($this->Aco->node($aco));		if (empty($aroPath) ||  empty($acoPath)) {			trigger_error("DbAcl::check() - Failed ARO/ACO node lookup in permissions check.  Node references:\nAro: " . print_r($aro, true) . "\nAco: " . print_r($aco, true), E_USER_WARNING);			return false;		}		if ($acoPath->get() == null || $acoPath->get() == array()) {			trigger_error("DbAcl::check() - Failed ACO node lookup in permissions check.  Node references:\nAro: " . print_r($aro, true) . "\nAco: " . print_r($aco, true), E_USER_WARNING);			return false;		}		$aroNode = $aroPath[0];		$acoNode = $acoPath->get();		$acoNode = $acoNode[0];		if ($action != '*' && !in_array('_' . $action, $permKeys)) {			trigger_error(sprintf(__("ACO permissions key %s does not exist in DbAcl::check()", true), $action), E_USER_NOTICE);			return false;		}		$inherited = array();		$acoIDs = $acoPath->extract('{n}.' . $this->Aco->alias . '.id');		for ($i = 0 ; $i < count($aroPath); $i++) {			$permAlias = $this->Aro->Permission->alias;			$perms = $this->Aro->Permission->find('all', array(				'conditions' => array(					"{$permAlias}.aro_id" => $aroPath[$i][$this->Aro->alias]['id'],					"{$permAlias}.aco_id" => $acoIDs				),				'order' => array($this->Aco->alias . '.lft' => 'desc'),				'recursive' => 0			));			if (empty($perms)) {				continue;			} else {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?