Source for file Complex.php
Documentation is available at Complex.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* A framework for authentication and authorization in PHP applications
* LiveUser is an authentication/permission framework designed
* to be flexible and easily extendable.
* Since it is impossible to have a
* "one size fits all" it takes a container
* approach which should enable it to
* be versatile enough to meet most needs.
* LICENSE: This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* @category authentication
* @author Markus Wolff <wolff@21st.de>
* @author Helgi Þormar Þorbjörnsson <dufuz@php.net>
* @author Lukas Smith <smith@pooteeweet.org>
* @author Arnaud Limbourg <arnaud@php.net>
* @author Pierre-Alain Joye <pajoye@php.net>
* @author Bjoern Kraus <krausbn@php.net>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version CVS: $Id: Complex.php,v 1.27 2006/04/10 14:41:44 lsmith Exp $
* @link http://pear.php.net/LiveUser
* Require parent class definition.
require_once 'LiveUser/Perm/Medium.php';
* Complex container for permission handling
* Complex permission complexity driver for LiveUser.
* @category authentication
* @author Lukas Smith <smith@pooteeweet.org>
* @author Bjoern Kraus <krausbn@php.net>
* @version $Id: Complex.php,v 1.27 2006/04/10 14:41:44 lsmith Exp $
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version Release: @package_version@
* @link http://pear.php.net/LiveUser
* Reads all individual implied rights of current user into
* an array of this format:
* @return array with rightIds as key and level as value
function _readImpliedRights ($rightIds, $table)
$result = $this->_storage->readImplyingRights ($rightIds, $table);
$currentRights = reset($queue);
$currentLevel = key($queue);
unset ($queue[$currentLevel]);
$result = $this->_storage->readImpliedRights ($currentRights, $currentLevel);
foreach ($result as $val) {
// only store the implied right if the right wasn't stored before
// or if the level is higher
|| $rightIds[$val['right_id']] < $val['right_level']
$rightIds[$val['right_id']] = $val['right_level'];
if ($val['has_implied']) {
$queue[$val['right_level']][] = $val['right_id'];
* Reads all individual rights of current user into
* an array of this format:
* @param int perm user id
* @return array requested data or false on failure
function readUserRights ($perm_user_id)
$result = parent ::readUserRights ($perm_user_id);
if (is_array($this->area_admin_areas)) {
* Reads all the group ids in that the user is also a member of
* (all groups that are subgroups of these are also added recursively)
* @param int perm user id
* @return array requested data or false on failure
function readGroups ($perm_user_id)
$result = parent ::readGroups ($perm_user_id);
// get all subgroups recursively
$result = $this->readSubGroups ($this->group_ids, $result);
* Read the sub groups of the groups where the user is a member in
* @param array new group ids
* @return array requested data or false on failure
function readSubGroups ($group_ids, $newGroupIds)
$result = $this->_storage->readSubGroups ($group_ids, $newGroupIds);
* Reads all individual rights of current user into
* a two-dimensional array of this format:
* "GroupName" => "RightName" -> "Level"
* @param array id's for the groups that rights will be read from
* @return array requested data or false on failure
function readGroupRights ($group_ids)
$group_right_ids = parent ::readGroupRights ($group_ids);
$this->group_right_ids = $this->_readImpliedRights ($group_right_ids, 'group');
* Checks if the current user has a certain right in a
* given area at the necessary level.
* Level 1: requires that owner_user_id matches $this->perm_user_id
* Level 2: requires that the $owner_group_id matches the id one of
* the (sub)groups that $this->perm_user_id is a member of
* or requires that the $owner_user_id matches a perm_user_id of
* a member of one of $this->perm_user_id's (sub)groups
* Level 3: no requirements
* Every ressource MAY be owned by a user and/or by a group.
* Therefore, $owner_user_id and/or $owner_group_id can
* either be an integer or null.
* @param int Level value as returned by checkRight().
* @param int|arrayId or array of Ids of the owner of the
ressource for which the right is requested.
* @param int|arrayId or array of Ids of the group of the
* ressource for which the right is requested.
* @return bool level if the level is sufficient to grant access else false.
function checkLevel($level, $owner_user_id, $owner_group_id)
// highest level (that is level 3) or no owner id's passed
// check if the ressource is owned by a (sub)group
// that the user is part of
* Read all the areas in which the user is an area admin
* @param int perm user id
* @return array requested data or false on failure
function readAreaAdminAreas ($perm_user_id)
$result = $this->_storage->readAreaAdminAreas ($perm_user_id);
$this->area_admin_areas = $result;
return $this->area_admin_areas;
Documentation generated on Mon, 28 Jan 2008 03:30:09 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|