[ Index ]
 

Code source de CakePHP 1.1.13.4450

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/cake/libs/controller/components/dbacl/ -> db_acl.php (source)

   1  <?php
   2  /* SVN FILE: $Id: db_acl.php 4409 2007-02-02 13:20:59Z phpnut $ */
   3  /**
   4   * This is core configuration file.
   5   *
   6   * Use it to configure core behaviour ofCake.
   7   *
   8   * PHP versions 4 and 5
   9   *
  10   * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
  11   * Copyright 2005-2007, Cake Software Foundation, Inc.
  12   *                                1785 E. Sahara Avenue, Suite 490-204
  13   *                                Las Vegas, Nevada 89104
  14   *
  15   * Licensed under The MIT License
  16   * Redistributions of files must retain the above copyright notice.
  17   *
  18   * @filesource
  19   * @copyright        Copyright 2005-2007, Cake Software Foundation, Inc.
  20   * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  21   * @package            cake
  22   * @subpackage        cake.cake.libs.controller.componenets.dbacl
  23   * @since            CakePHP(tm) v 0.2.9
  24   * @version            $Revision: 4409 $
  25   * @modifiedby        $LastChangedBy: phpnut $
  26   * @lastmodified    $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
  27   * @license            http://www.opensource.org/licenses/mit-license.php The MIT License
  28   */
  29  if (!defined('ACL_DATABASE')) {
  30      define('ACL_DATABASE', 'default');
  31  }
  32  uses('controller' . DS . 'components' . DS . 'acl_base');
  33  uses('controller' . DS . 'components' . DS . 'dbacl' . DS . 'models' . DS . 'aclnode');
  34  uses('controller' . DS . 'components' . DS . 'dbacl' . DS . 'models' . DS . 'aco');
  35  uses('controller' . DS . 'components' . DS . 'dbacl' . DS . 'models' . DS . 'acoaction');
  36  uses('controller' . DS . 'components' . DS . 'dbacl' . DS . 'models' . DS . 'aro');
  37  uses('controller' . DS . 'components' . DS . 'dbacl' . DS . 'models' . DS . 'aros_aco');
  38  /**
  39   * In this file you can extend the AclBase.
  40   *
  41   * @package        cake
  42   * @subpackage    cake.cake.libs.controller.components.dbacl
  43   */
  44  class DB_ACL extends AclBase {
  45  /**
  46   * Enter description here...
  47   *
  48   */
  49  	function __construct() {
  50      }
  51  /**
  52   * Enter description here...
  53   *
  54   * @param string $aro
  55   * @param string $aco
  56   * @param string $action
  57   * @return boolean
  58   * @access public
  59   */
  60  	function check($aro, $aco, $action = "*") {
  61          $Perms = new ArosAco();
  62          $Aro = new Aro();
  63          $Aco = new Aco();
  64  
  65          if ($aro == null || $aco == null) {
  66              return false;
  67          }
  68  
  69          $permKeys = $this->_getAcoKeys($Perms->loadInfo());
  70          $aroPath = $Aro->getPath($aro);
  71          $tmpAcoPath = $Aco->getPath($aco);
  72  
  73          if ($tmpAcoPath === null) {
  74              return false;
  75          }
  76          $tmpAcoPath = array_reverse($tmpAcoPath);
  77          $acoPath = array();
  78  
  79          if ($action != '*' && !in_array('_' . $action, $permKeys)) {
  80              trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()', E_USER_NOTICE);
  81              return false;
  82          }
  83  
  84          foreach($tmpAcoPath as $a) {
  85              $acoPath[] = $a['Aco']['id'];
  86          }
  87  
  88          for($i = count($aroPath) - 1; $i >= 0; $i--) {
  89              $perms = $Perms->findAll(array('ArosAco.aro_id' => $aroPath[$i]['Aro']['id'],
  90                                                          'ArosAco.aco_id' => $acoPath), null,
  91                                                          'Aco.lft desc');
  92              if ($perms == null || count($perms) == 0) {
  93                  continue;
  94              } else {
  95                  foreach($perms as $perm) {
  96                      if ($action == '*') {
  97                          // ARO must be cleared for ALL ACO actions
  98                          foreach($permKeys as $key) {
  99                              if (isset($perm['ArosAco'])) {
 100                                  if ($perm['ArosAco'][$key] != 1) {
 101                                          return false;
 102                                  }
 103                              }
 104                          }
 105                          return true;
 106  
 107                      } else {
 108                          switch($perm['ArosAco']['_' . $action]) {
 109                              case -1:
 110                                  return false;
 111                              case 0:
 112                                  continue;
 113                              break;
 114                              case 1:
 115                                  return true;
 116                              break;
 117                          }
 118                      }
 119                  }
 120              }
 121          }
 122          return false;
 123      }
 124  /**
 125   * Enter description here...
 126   *
 127   * @param string $aro
 128   * @param string $aco
 129   * @param string $action
 130   * @param integer $value
 131   * @return boolean
 132   * @access public
 133   */
 134  	function allow($aro, $aco, $action = "*", $value = 1) {
 135          $Perms = new ArosAco();
 136          $perms = $this->getAclLink($aro, $aco);
 137          $permKeys = $this->_getAcoKeys($Perms->loadInfo());
 138          $save = array();
 139  
 140          if ($perms == false) {
 141              trigger_error('DB_ACL::allow() - Invalid node', E_USER_WARNING);
 142              return false;
 143          }
 144  
 145          if (isset($perms[0])) {
 146              $save = $perms[0]['ArosAco'];
 147          }
 148  
 149          if ($action == "*") {
 150              $permKeys = $this->_getAcoKeys($Perms->loadInfo());
 151  
 152              foreach($permKeys as $key) {
 153                  $save[$key] = $value;
 154              }
 155          } else {
 156              if (in_array('_' . $action, $permKeys)) {
 157                  $save['_' . $action] = $value;
 158              } else {
 159                  trigger_error('DB_ACL::allow() - Invalid ACO action', E_USER_WARNING);
 160                  return false;
 161              }
 162          }
 163  
 164          $save['aro_id'] = $perms['aro'];
 165          $save['aco_id'] = $perms['aco'];
 166  
 167          if ($perms['link'] != null && count($perms['link']) > 0) {
 168              $save['id'] = $perms['link'][0]['ArosAco']['id'];
 169          }
 170          return $Perms->save(array('ArosAco' => $save));
 171      }
 172  /**
 173   * Enter description here...
 174   *
 175   * @param string $aro
 176   * @param string $aco
 177   * @param string $action
 178   * @return boolean
 179   * @access public
 180   */
 181  	function deny($aro, $aco, $action = "*") {
 182          return $this->allow($aro, $aco, $action, -1);
 183      }
 184  /**
 185   * Enter description here...
 186   *
 187   * @param string $aro
 188   * @param string $aco
 189   * @param string $action
 190   * @return boolean
 191   * @access public
 192   */
 193  	function inherit($aro, $aco, $action = "*") {
 194          return $this->allow($aro, $aco, $action, 0);
 195      }
 196  /**
 197   * Enter description here...
 198   *
 199   * @param string $aro
 200   * @param string $aco
 201   * @param string $action
 202   * @return boolean
 203   * @access public
 204   */
 205  	function grant($aro, $aco, $action = "*") {
 206          return $this->allow($aro, $aco, $action);
 207      }
 208  /**
 209   * Enter description here...
 210   *
 211   * @param string $aro
 212   * @param string $aco
 213   * @param string $action
 214   * @return boolean
 215   * @access public
 216   */
 217  	function revoke($aro, $aco, $action = "*") {
 218          return $this->deny($aro, $aco, $action);
 219      }
 220  /**
 221   * Get an ARO object from the given id or alias
 222   *
 223   * @param mixed $id
 224   * @return object Aro
 225   * @access public
 226   */
 227  	function getAro($id = null) {
 228          return $this->__getObject($id, 'Aro');
 229      }
 230  /**
 231   * Get an ACO object from the given id or alias
 232   *
 233   * @param mixed $id
 234   * @return object Aco
 235   * @access public
 236   */
 237  	function getAco($id = null) {
 238          return $this->__getObject($id, 'Aco');
 239      }
 240  	function __getObject($id = null, $object) {
 241          if ($id == null) {
 242              trigger_error('Null id provided in DB_ACL::get' . $object, E_USER_WARNING);
 243              return null;
 244          }
 245  
 246          $obj = new $object;
 247  
 248          if (is_numeric($id)) {
 249              $key = 'foreign_key';
 250              if ($object == 'Aco') {
 251                  $key = 'object_id';
 252              }
 253  
 254              $conditions = array($object . '.' . $key => $id);
 255          } else {
 256              $conditions = array($object . '.alias' => $id);
 257          }
 258  
 259          $tmp = $obj->find($conditions);
 260          $obj->id = $tmp[$object]['id'];
 261          return $obj;
 262      }
 263  /**
 264   * Get an array of access-control links between the given Aro and Aco
 265   *
 266   * @param mixed $aro
 267   * @param mixed $aco
 268   * @return array
 269   * @access public
 270   */
 271  	function getAclLink($aro, $aco) {
 272          $Aro = new Aro();
 273          $Aco = new Aco();
 274          $Link = new ArosAco();
 275  
 276          $obj = array();
 277          $obj['Aro'] = $Aro->find($Aro->_resolveID($aro));
 278          $obj['Aco'] = $Aco->find($Aco->_resolveID($aco));
 279          $obj['Aro'] = $obj['Aro']['Aro'];
 280          $obj['Aco'] = $obj['Aco']['Aco'];
 281  
 282          if ($obj['Aro'] == null || count($obj['Aro']) == 0 || $obj['Aco'] == null || count($obj['Aco']) == 0) {
 283              return false;
 284          }
 285          return array('aro' => $obj['Aro']['id'],
 286                              'aco'  => $obj['Aco']['id'],
 287                              'link' => $Link->findAll(array(
 288                              'ArosAco.aro_id' => $obj['Aro']['id'],
 289                              'ArosAco.aco_id' => $obj['Aco']['id'])));
 290      }
 291  /**
 292   * Enter description here...
 293   *
 294   * @param object $keys
 295   * @return array
 296   * @access protected
 297   */
 298  	function _getAcoKeys($keys) {
 299          $newKeys = array();
 300          $keys = $keys->value;
 301  
 302          foreach($keys as $key) {
 303              if ($key['name'] != 'id' && $key['name'] != 'aro_id' && $key['name'] != 'aco_id') {
 304                  $newKeys[] = $key['name'];
 305              }
 306          }
 307          return $newKeys;
 308      }
 309  }
 310  ?>


Généré le : Sun Feb 25 19:27:47 2007 par Balluche grâce à PHPXref 0.7