01.31
php
saved
the_undefined
Note
SimpleAclComponent.
See http://www.thinkingphp.org/2006/10/03/a-lightweight-approach-to-acl-the-33-lines-of-magic/ for more information.
SimpleAclComponent.
See http://www.thinkingphp.org/2006/10/03/a-lightweight-approach-to-acl-the-33-lines-of-magic/ for more information.
- <?php
- /**
- * Created: Sun Sep 17 10:51:46 CEST 2006
- *
- * DESCRIPTION
- *
- * PHP versions 4 and 5
- *
- * Copyright (c) Felix Geisendörfer <info@fg-webdesign.de>
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright (c) 2006, Felix Geisendörfer.
- * @link http://www.fg-webdesign.de/
- * @link http://www.thinkingphp.org/
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- */
- class SimpleAclComponent extends Object
- {
- var $Controller;
- /**
- * You can set this to false in your AppController's beforeFilter to deactivate this Component
- *
- * @var boolean
- */
- var $enabled = true;
- /**
- * Here you can register a callback in case the User tries to access an action he's not
- * allowed to access.
- *
- * @var mixed
- */
- var $actionDeniedCallback = null;
- /**
- * If $this->activeUser is empty, this component will be accessed to get the activeUser
- * data. The component must support a function getActiveUser();.
- *
- * I would recommend you to use my SimpleAuth component for this job ; ).
- *
- * @var string
- */
- var $authComponent = 'SimpleAuth';
- /**
- * Can contain the current User data
- *
- * @var unknown_type
- */
- var $activeUser = null;
- function startup(&$Controller)
- {
- $this->Controller = &$Controller;
- // If the component got disabled, exit.
- if ($this->enabled===false)
- return;
- // The name of the Controller and action we want to check permission for
- $controller = $this->Controller->name;
- $action = $this->Controller->action;
- $this->activeUser = $this->Controller->{$this->authComponent}->getActiveUser();
- // Check if there is an action and if we are (not) allowed to access it.
- {
- // If there is no actionDeniedCallback defined, invoke a simple default error template (errors/permission_denied.ctp)
- if (!$this->actionDeniedCallback)
- {
- $this->Controller->viewPath = 'errors';
- $this->Controller->render('permission_denied');
- exit;
- }
- else // Call the actionDeniedCallback
- }
- }
- function actionAllowed($controller, $action, $user = null)
- {
- $user = $this->activeUser;
- {
- $groupAllowed = $this->requestAllowed($controller, $action, $user[$this->Controller->{$this->authComponent}->groupModel]['controller_acl']);
- $userAllowed = $this->requestAllowed($controller, $action, $user[$this->Controller->{$this->authComponent}->userModel]['controller_acl'], $groupAllowed);
- }
- else
- $userAllowed = $this->requestAllowed($controller, $action, $user[$this->Controller->{$this->authComponent}->userModel]['controller_acl']);
- return $userAllowed;
- }
- /**
- * This function decides whether a given $objects's $property can be accessed based
- * on a list of $rules. If the list of $rules is empty or doesn't match $object/$property
- * the decision is made based on the $default value.
- *
- * @param string $object
- * @param string $property
- * @param string $rules
- * @param boolean $allowedDefault
- * @return boolean
- */
- function requestAllowed($object, $property, $rules, $default = false)
- {
- // The default value to return if no rule matching $object/$property can be found
- $allowed = $default;
- // This Regex converts a string of rules like "objectA:actionA,objectB:actionB,..." into the array $matches.
- foreach ($matches as $match)
- {
- {
- $negativeCondition = true;
- }
- else
- $negativeCondition = false;
- {
- if ($negativeCondition)
- $allowed = false;
- else
- $allowed = true;
- }
- }
- return $allowed;
- }
- }
- ?>
Parsed in 0.177 seconds, using GeSHi 1.0.7.14