cvs: pear /Perm_LiveUser/Perm Simple.php Storage.php /Perm_LiveUser/Perm/Storage Cache.php MDB2.php SQL.php XML.php
/Perm_LiveUser/docs/examples/example2 conf.php
| From: | Lukas Smith | Date: | Mon, 08 Nov 2004 15:57:34 +0000 |
| Subject: | cvs: pear /Perm_LiveUser/Perm Simple.php Storage.php /Perm_LiveUser/Perm/Storage Cache.php MDB2.php SQL.php XML.php /Perm_LiveUser/docs/examples/example2 conf.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-25779@lists.php.net to get a copy of this message | ||
lsmith Mon Nov 8 10:57:34 2004 EDT
Added files:
/pear/Perm_LiveUser/Perm/Storage Cache.php MDB2.php SQL.php XML.php
/pear/Perm_LiveUser/Perm Simple.php Storage.php
Modified files:
/pear/Perm_LiveUser/docs/examples/example2 conf.php
Log:
- refactored client part to the new layout (using storage containers) .. fixed example2 to use the
new config layout
http://cvs.php.net/diff.php/pear/Perm_LiveUser/docs/examples/example2/conf.php?r1=1.7&r2=1.8&ty=u Index: pear/Perm_LiveUser/docs/examples/example2/conf.php diff -u pear/Perm_LiveUser/docs/examples/example2/conf.php:1.7 pear/Perm_LiveUser/docs/examples/example2/conf.php:1.8 --- pear/Perm_LiveUser/docs/examples/example2/conf.php:1.7 Mon Apr 26 20:26:02 2004 +++ pear/Perm_LiveUser/docs/examples/example2/conf.php Mon Nov 8 10:57:34 2004 @@ -33,8 +33,8 @@ 'passwordEncryptionMode' => 'MD5' ) ), - 'permContainer' => array('type' => 'XML_Simple', - 'file' => 'Perm_XML.xml' + 'permContainer' => array('type' => 'Simple', + 'stack' => array('XML' => array('session_name' => 'foo', 'file' => 'Perm_XML.xml')), ), ); // Get LiveUser class definition http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage/Cache.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage/Cache.php +++ pear/Perm_LiveUser/Perm/Storage/Cache.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * Require parent class definition. */ require_once 'LiveUser/Perm/Storage.php'; /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: Cache.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage_Cache extends LiveUser_Perm_Storage { /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage_Cache($conf, $confArray) { if (!count($confArray)) { return; } $this->_storage = LiveUser::storageFactory($confArray); } function mapUser($uid, $containerName) { if (in_cache) { return cache; } $result = $this->_storage->mapUser($uid, $containerName); if (!$result) { return false; } write_into_cache return $result; } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { if (in_cache) { return cache; } $result = $this->_storage->readUserRights($permUserId); if (!$result) { return false; } write_into_cache return $result; } /** * properly disconnect from resources * * @access public */ function disconnect() { $this->_storage->disconnect(); } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage/MDB2.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage/MDB2.php +++ pear/Perm_LiveUser/Perm/Storage/MDB2.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * Require parent class definition. */ require_once 'LiveUser/Perm/Storage/SQL.php'; /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: MDB2.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage_MDB2 extends LiveUser_Perm_Storage_SQL { /** * dsn that was connected to * @var object * @access private */ var $dsn = null; /** * disconnect * @var object * @access private */ var $disconnect = null; /** * PEAR::MDB2 connection object. * * @var object * @access private */ var $dbc = null; /** * Table prefix * Prefix for all db tables the container has. * * @var string * @access public */ var $prefix = 'liveuser_'; /** * Indicates if backend module initialized correctly. If yes, * true, if not false. Backend module won't initialize if the * init value (usually an object or resource handle that * identifies the backend to be used) is not of the required * type. * * @var boolean * @access public */ var $init_ok = false; /** * Columns of the perm table. * Associative array with the names of the perm table columns. * The 'group_id' and 'group_define_name' fields have to be set. * 'group_type', 'is_active', 'owner_user_id' and 'owner_group_id' are optional. * It doesn't make sense to set only one of the time columns without the * other. * * The type attribute is only useful when using MDB or MDB2. * * @access public * @var array */ var $groupTableCols = array( 'required' => array( 'group_id' => array('type' => 'integer', 'name' => 'group_id'), 'group_define_name' => array('type' => 'text', 'name' => 'group_define_name') ), 'optional' => array( 'group_type' => array('type' => 'integer', 'name' => 'group_type'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id') ) ); /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage_MDB2(&$conf) { $this->LiveUser_Perm_Storage_SQL(); if (is_array($conf)) { foreach ($conf as $key => $value) { if (isset($this->$key)) { $this->$key = $value; } } if (isset($conf['connection']) && MDB2::isConnection($conf['connection']) ) { $this->dbc = &$conf['connection']; $this->init_ok = true; } elseif (isset($conf['dsn'])) { $this->dsn = $conf['dsn']; $function = null; if (isset($conf['function'])) { $function = $conf['function']; } $options = null; if (isset($conf['options'])) { $options = $conf['options']; } $options['portability'] = MDB2_PORTABILITY_ALL; if ($function == 'singleton') { $this->dbc =& MDB2::singleton($conf['dsn'], $options); } else { $this->dbc =& MDB2::connect($conf['dsn'], $options); } if (!MDB2::isError($this->dbc)) { $this->init_ok = true; } } } } function mapUser($uid, $containerName) { $query = ' SELECT LU.perm_user_id AS userid, LU.perm_type AS usertype FROM '.$this->prefix.'perm_users LU WHERE auth_user_id='.$this->dbc->quote($uid, 'text').' AND auth_container_name='.$this->dbc->quote($containerName, 'text'); $result = $this->dbc->queryRow($query, array('integer', 'integer'), MDB2_FETCHMODE_ASSOC); if (PEAR::isError($result)) { return false; } return $result; } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { $query = ' SELECT R.right_id AS rightid, '.LIVEUSER_MAX_LEVEL.' FROM '.$this->prefix.'userrights UR INNER JOIN '.$this->prefix.'rights R ON UR.right_id=R.right_id WHERE UR.perm_user_id='.$this->dbc->quote($this->permUserId, 'integer') . ' AND UR.right_level > 0'; $types = array('integer', 'integer'); $result = $this->dbc->queryAll($query, $types, MDB2_FETCHMODE_ORDERED, true); if (PEAR::isError($result)) { return false; } // if return $result; } /** * properly disconnect from resources * * @access public */ function disconnect() { $this->dbc->disconnect(); } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage/SQL.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage/SQL.php +++ pear/Perm_LiveUser/Perm/Storage/SQL.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * Require parent class definition. */ require_once 'LiveUser/Perm/Storage.php'; /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: SQL.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage_SQL extends LiveUser_Perm_Storage { /** * dsn that was connected to * @var object * @access private */ var $dsn = null; /** * disconnect * @var object * @access private */ var $disconnect = null; /** * PEAR::MDB2 connection object. * * @var object * @access private */ var $dbc = null; /** * Table prefix * Prefix for all db tables the container has. * * @var string * @access public */ var $prefix = 'liveuser_'; /** * Indicates if backend module initialized correctly. If yes, * true, if not false. Backend module won't initialize if the * init value (usually an object or resource handle that * identifies the backend to be used) is not of the required * type. * * @var boolean * @access public */ var $init_ok = false; /** * Columns of the perm table. * Associative array with the names of the perm table columns. * The 'group_id' and 'group_define_name' fields have to be set. * 'group_type', 'is_active', 'owner_user_id' and 'owner_group_id' are optional. * It doesn't make sense to set only one of the time columns without the * other. * * The type attribute is only useful when using MDB or MDB2. * * @access public * @var array */ var $groupTableCols = array( 'required' => array( 'group_id' => array('type' => 'integer', 'name' => 'group_id'), 'group_define_name' => array('type' => 'text', 'name' => 'group_define_name') ), 'optional' => array( 'group_type' => array('type' => 'integer', 'name' => 'group_type'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id') ) ); /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage_MDB2(&$conf) { } function mapUser($uid, $containerName) { } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { } /** * properly disconnect from resources * * @access public */ function disconnect() { } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage/XML.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage/XML.php +++ pear/Perm_LiveUser/Perm/Storage/XML.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * Require parent class definition. */ require_once 'LiveUser/Perm/Storage.php'; /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: XML.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage_XML extends LiveUser_Perm_Storage { /** * XML file in which the auth data is stored. * @var string * @access private */ var $file = ''; /** * XML::Tree object. * * @access private * @var XML_Tree */ var $tree = null; /** * XML::Tree object of the user logged in. * * @access private * @var XML_Tree * @see readUserData() */ var $userObj = null; /** * Indicates if backend module initialized correctly. If yes, * true, if not false. Backend module won't initialize if the * init value (usually an object or resource handle that * identifies the backend to be used) is not of the required * type. * * @var boolean * @access public */ var $init_ok = false; /** * Columns of the perm table. * Associative array with the names of the perm table columns. * The 'group_id' and 'group_define_name' fields have to be set. * 'group_type', 'is_active', 'owner_user_id' and 'owner_group_id' are optional. * It doesn't make sense to set only one of the time columns without the * other. * * The type attribute is only useful when using MDB or MDB2. * * @access public * @var array */ var $groupTableCols = array( 'required' => array( 'group_id' => array('type' => 'integer', 'name' => 'group_id'), 'group_define_name' => array('type' => 'text', 'name' => 'group_define_name') ), 'optional' => array( 'group_type' => array('type' => 'integer', 'name' => 'group_type'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id') ) ); /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage_XML(&$conf) { $this->LiveUser_Perm_Storage(&$conf); if (!is_file($this->file)) { if (is_file(getenv('DOCUMENT_ROOT') . $this->file)) { $this->file = getenv('DOCUMENT_ROOT') . $this->file; } else { $this->_stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find xml file."); return false; } } if ($this->file) { if (class_exists('XML_Tree')) { $tree =& new XML_Tree($this->file); $err =& $tree->getTreeFromFile(); if (PEAR::isError($err)) { return false; } else { $this->tree = $tree; $this->init_ok = true; } } else { $this->_stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find XML_Tree class"); return false; } } else { $this->_stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find XML_Tree class"); return false; } } function mapUser($uid, $containerName) { $nodeIndex = 0; $userIndex = 0; $result = false; foreach ($this->tree->root->children as $node) { if ($node->name == 'users') { foreach ($node->children as $user) { if ($user->name != 'user') { continue; } if ($uid == $user->attributes['authUserId'] && $containerName == $user->attributes['authContainerName'] ) { $result['userid'] = $user->attributes['userId']; $result['usertype'] = $user->attributes['type']; $this->userObj =& $this->tree->root->getElement(array($nodeIndex, $userIndex)); break; } $userIndex++; } } $nodeIndex++; } return $result; } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { $result = array(); foreach ($this->userObj->children as $node) { if ($node->name == 'rights') { $tmp = explode(',', $node->content); foreach ($tmp as $value) { $result[$value] = 1; } } } return $result; } /** * properly disconnect from resources * * @access public */ function disconnect() { $this->tree = null; $this->userObj = null; } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Simple.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Simple.php +++ pear/Perm_LiveUser/Perm/Simple.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * Base class for permission handling * * @package LiveUser * @category authentication */ /**#@+ * Usertypes * * @var integer */ /** * lowest user type id */ define('LIVEUSER_ANONYMOUS_TYPE_ID', 0); /** * lowest user type id */ // higest user type id define('LIVEUSER_USER_TYPE_ID', 1); /** * lowest admin type id */ define('LIVEUSER_ADMIN_TYPE_ID', 2); define('LIVEUSER_AREAADMIN_TYPE_ID', 3); define('LIVEUSER_SUPERADMIN_TYPE_ID', 4); /** * higest admin type id */ define('LIVEUSER_MASTERADMIN_TYPE_ID', 5); /**#@-*/ /** * This class provides a set of functions for implementing a user * permission management system on live websites. All authorisation * backends/containers must be extensions of this base class. * * @author Markus Wolff <wolff@21st.de> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: Simple.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Simple { /** * Unique user ID, used to identify users from the auth container. * * @var string */ var $permUserId = ''; /** * One-dimensional array containing current user's rights. * This already includes grouprights and possible overrides by * individual right settings. * * Format: "RightId" => "Level" * * @var mixed */ var $rights = false; /** * One-dimensional array containing only the individual * rights for the actual user. * * Format: "RightId" => "Level" * * @var array */ var $userRights = array(); /** * Two-dimensional array containing all groups that * the user belongs to and the grouprights. * * Format: "GroupId" => "RightId" => "Level" * * @var array * @see $userRights * @see $rights */ var $groupRights = array(); /** * Defines the user type. * * @var integer */ var $userType = LIVEUSER_ANONYMOUS_TYPE_ID; /** * Defines the (sub)groups in which the user is a member * * @var mixed */ var $groupIds = false; /** * Defines if the user rights should be retrieved ondemand. * * @var boolean */ var $ondemand = false; /** * Error stack * * @var PEAR_ErrorStack */ var $_stack = null; /** * Class constructor. Feel free to override in backend subclasses. */ function LiveUser_Perm_Simple($confArray) { $this->_stack = &PEAR_ErrorStack::singleton('LiveUser'); $this->_storage = LiveUser::storageFactory($confArray); } /** * Tries to find the user with the given user ID in the permissions * container. Will read all permission data and return true on success. * * @access public * @param string user identifier * @param string name of the auth container * @return boolean true on success or false on failure */ function init($uid = null, $containerName = null) { $result = $this->_storage->mapUser($uid, $containerName); if (!$result) { return false; } $this->permUserId = $result['userid']; $this->userType = $result['usertype']; $this->readRights(); return true; } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readRights() { $result = $this->_storage->readUserRights($this->permUserId); if (!$result) { return false; } $this->rights = $result; return true; } /** * Checks if the current user has a certain right in a * given area. * If $this->ondemand and $ondemand is true, the rights will be loaded on * the fly. * * @access public * @param integer $right_id Id of the right to check for. * @param boolean $ondemand allow ondemand reading of rights * @return integer Level of the right. */ function checkRight($right_id, $ondemand = true) { if (is_array($this->rights)) { // check if the user is above areaadmin if (!$right_id || $this->userType > LIVEUSER_AREAADMIN_TYPE_ID) { return LIVEUSER_MAX_LEVEL; } else { // If he does, look for the right in question. if (in_array($right_id, array_keys($this->rights))) { // We know the user has the right so the right level will be returned. return $this->rights[$right_id]; } } } elseif ($this->ondemand && $ondemand) { $this->readRights(); return $this->checkRight($right_id, false); } return false; } // end func checkRight /** * Function returns the inquired value if it exists in the class. * * @param string Name of the property to be returned. * @return mixed null, a value or an array. */ function getProperty($what) { $that = null; if (isset($this->$what)) { $that = $this->$what; } return $that; } /** * store all properties in an array * * @access public * @return array containing the property values */ function freeze() { $propertyValues = array( 'permUserId' => $this->permUserId, 'rights' => $this->rights, 'userRights' => $this->userRights, 'groupRights' => $this->groupRights, 'userType' => $this->userType, 'groupIds' => $this->groupIds, ); return $this->_storage->freeze($propertyValues); } // end func freeze /** * Reinitializes properties * * @access public * @param array $propertyValues */ function unfreeze($propertyValues = false) { $propertyValues = $this->_storage->unfreeze(); if ($propertyValues) { foreach ($propertyValues as $key => $value) { $this->{$key} = $value; } } return $this->init(); } // end func unfreeze /** * properly disconnect from resources * * @access public */ function disconnect() { $this->_storage->disconnect(); } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage.php +++ pear/Perm_LiveUser/Perm/Storage.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: Storage.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage { /** * dsn that was connected to * @var object * @access private */ var $dsn = null; /** * disconnect * @var object * @access private */ var $disconnect = null; /** * PEAR::MDB2 connection object. * * @var object * @access private */ var $dbc = null; /** * Table prefix * Prefix for all db tables the container has. * * @var string * @access public */ var $prefix = 'liveuser_'; /** * Indicates if backend module initialized correctly. If yes, * true, if not false. Backend module won't initialize if the * init value (usually an object or resource handle that * identifies the backend to be used) is not of the required * type. * * @var boolean * @access public */ var $init_ok = false; var $session_name; /** * Columns of the perm table. * Associative array with the names of the perm table columns. * The 'group_id' and 'group_define_name' fields have to be set. * 'group_type', 'is_active', 'owner_user_id' and 'owner_group_id' are optional. * It doesn't make sense to set only one of the time columns without the * other. * * The type attribute is only useful when using MDB or MDB2. * * @access public * @var array */ var $groupTableCols = array( 'required' => array( 'group_id' => array('type' => 'integer', 'name' => 'group_id'), 'group_define_name' => array('type' => 'text', 'name' => 'group_define_name') ), 'optional' => array( 'group_type' => array('type' => 'integer', 'name' => 'group_type'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id') ) ); /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage(&$conf) { if (is_array($conf)) { foreach ($conf as $key => $value) { if (isset($this->$key)) { $this->$key = $value; } } } } function mapUser($uid, $containerName) { } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { } /** * store all properties in an array * * @access public * @return array containing the property values */ function freeze($propertyValues) { $_SESSION[$this->session_name]['perm'] = $propertyValues; return $propertyValues; } // end func freeze /** * Reinitializes properties * * @access public * @param array $propertyValues */ function unfreeze($propertyValues = false) { return $_SESSION[$this->session_name]['perm']; } // end func unfreeze /** * properly disconnect from resources * * @access public */ function disconnect() { } } ?>
http://cvs.php.net/diff.php/pear/Perm_LiveUser/docs/examples/example2/conf.php?r1=1.7&r2=1.8&ty=u Index: pear/Perm_LiveUser/docs/examples/example2/conf.php diff -u pear/Perm_LiveUser/docs/examples/example2/conf.php:1.7 pear/Perm_LiveUser/docs/examples/example2/conf.php:1.8 --- pear/Perm_LiveUser/docs/examples/example2/conf.php:1.7 Mon Apr 26 20:26:02 2004 +++ pear/Perm_LiveUser/docs/examples/example2/conf.php Mon Nov 8 10:57:34 2004 @@ -33,8 +33,8 @@ 'passwordEncryptionMode' => 'MD5' ) ), - 'permContainer' => array('type' => 'XML_Simple', - 'file' => 'Perm_XML.xml' + 'permContainer' => array('type' => 'Simple', + 'stack' => array('XML' => array('session_name' => 'foo', 'file' => 'Perm_XML.xml')), ), ); // Get LiveUser class definition http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage/Cache.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage/Cache.php +++ pear/Perm_LiveUser/Perm/Storage/Cache.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * Require parent class definition. */ require_once 'LiveUser/Perm/Storage.php'; /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: Cache.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage_Cache extends LiveUser_Perm_Storage { /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage_Cache($conf, $confArray) { if (!count($confArray)) { return; } $this->_storage = LiveUser::storageFactory($confArray); } function mapUser($uid, $containerName) { if (in_cache) { return cache; } $result = $this->_storage->mapUser($uid, $containerName); if (!$result) { return false; } write_into_cache return $result; } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { if (in_cache) { return cache; } $result = $this->_storage->readUserRights($permUserId); if (!$result) { return false; } write_into_cache return $result; } /** * properly disconnect from resources * * @access public */ function disconnect() { $this->_storage->disconnect(); } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage/MDB2.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage/MDB2.php +++ pear/Perm_LiveUser/Perm/Storage/MDB2.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * Require parent class definition. */ require_once 'LiveUser/Perm/Storage/SQL.php'; /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: MDB2.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage_MDB2 extends LiveUser_Perm_Storage_SQL { /** * dsn that was connected to * @var object * @access private */ var $dsn = null; /** * disconnect * @var object * @access private */ var $disconnect = null; /** * PEAR::MDB2 connection object. * * @var object * @access private */ var $dbc = null; /** * Table prefix * Prefix for all db tables the container has. * * @var string * @access public */ var $prefix = 'liveuser_'; /** * Indicates if backend module initialized correctly. If yes, * true, if not false. Backend module won't initialize if the * init value (usually an object or resource handle that * identifies the backend to be used) is not of the required * type. * * @var boolean * @access public */ var $init_ok = false; /** * Columns of the perm table. * Associative array with the names of the perm table columns. * The 'group_id' and 'group_define_name' fields have to be set. * 'group_type', 'is_active', 'owner_user_id' and 'owner_group_id' are optional. * It doesn't make sense to set only one of the time columns without the * other. * * The type attribute is only useful when using MDB or MDB2. * * @access public * @var array */ var $groupTableCols = array( 'required' => array( 'group_id' => array('type' => 'integer', 'name' => 'group_id'), 'group_define_name' => array('type' => 'text', 'name' => 'group_define_name') ), 'optional' => array( 'group_type' => array('type' => 'integer', 'name' => 'group_type'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id') ) ); /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage_MDB2(&$conf) { $this->LiveUser_Perm_Storage_SQL(); if (is_array($conf)) { foreach ($conf as $key => $value) { if (isset($this->$key)) { $this->$key = $value; } } if (isset($conf['connection']) && MDB2::isConnection($conf['connection']) ) { $this->dbc = &$conf['connection']; $this->init_ok = true; } elseif (isset($conf['dsn'])) { $this->dsn = $conf['dsn']; $function = null; if (isset($conf['function'])) { $function = $conf['function']; } $options = null; if (isset($conf['options'])) { $options = $conf['options']; } $options['portability'] = MDB2_PORTABILITY_ALL; if ($function == 'singleton') { $this->dbc =& MDB2::singleton($conf['dsn'], $options); } else { $this->dbc =& MDB2::connect($conf['dsn'], $options); } if (!MDB2::isError($this->dbc)) { $this->init_ok = true; } } } } function mapUser($uid, $containerName) { $query = ' SELECT LU.perm_user_id AS userid, LU.perm_type AS usertype FROM '.$this->prefix.'perm_users LU WHERE auth_user_id='.$this->dbc->quote($uid, 'text').' AND auth_container_name='.$this->dbc->quote($containerName, 'text'); $result = $this->dbc->queryRow($query, array('integer', 'integer'), MDB2_FETCHMODE_ASSOC); if (PEAR::isError($result)) { return false; } return $result; } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { $query = ' SELECT R.right_id AS rightid, '.LIVEUSER_MAX_LEVEL.' FROM '.$this->prefix.'userrights UR INNER JOIN '.$this->prefix.'rights R ON UR.right_id=R.right_id WHERE UR.perm_user_id='.$this->dbc->quote($this->permUserId, 'integer') . ' AND UR.right_level > 0'; $types = array('integer', 'integer'); $result = $this->dbc->queryAll($query, $types, MDB2_FETCHMODE_ORDERED, true); if (PEAR::isError($result)) { return false; } // if return $result; } /** * properly disconnect from resources * * @access public */ function disconnect() { $this->dbc->disconnect(); } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage/SQL.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage/SQL.php +++ pear/Perm_LiveUser/Perm/Storage/SQL.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * Require parent class definition. */ require_once 'LiveUser/Perm/Storage.php'; /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: SQL.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage_SQL extends LiveUser_Perm_Storage { /** * dsn that was connected to * @var object * @access private */ var $dsn = null; /** * disconnect * @var object * @access private */ var $disconnect = null; /** * PEAR::MDB2 connection object. * * @var object * @access private */ var $dbc = null; /** * Table prefix * Prefix for all db tables the container has. * * @var string * @access public */ var $prefix = 'liveuser_'; /** * Indicates if backend module initialized correctly. If yes, * true, if not false. Backend module won't initialize if the * init value (usually an object or resource handle that * identifies the backend to be used) is not of the required * type. * * @var boolean * @access public */ var $init_ok = false; /** * Columns of the perm table. * Associative array with the names of the perm table columns. * The 'group_id' and 'group_define_name' fields have to be set. * 'group_type', 'is_active', 'owner_user_id' and 'owner_group_id' are optional. * It doesn't make sense to set only one of the time columns without the * other. * * The type attribute is only useful when using MDB or MDB2. * * @access public * @var array */ var $groupTableCols = array( 'required' => array( 'group_id' => array('type' => 'integer', 'name' => 'group_id'), 'group_define_name' => array('type' => 'text', 'name' => 'group_define_name') ), 'optional' => array( 'group_type' => array('type' => 'integer', 'name' => 'group_type'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id') ) ); /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage_MDB2(&$conf) { } function mapUser($uid, $containerName) { } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { } /** * properly disconnect from resources * * @access public */ function disconnect() { } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage/XML.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage/XML.php +++ pear/Perm_LiveUser/Perm/Storage/XML.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * Require parent class definition. */ require_once 'LiveUser/Perm/Storage.php'; /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: XML.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage_XML extends LiveUser_Perm_Storage { /** * XML file in which the auth data is stored. * @var string * @access private */ var $file = ''; /** * XML::Tree object. * * @access private * @var XML_Tree */ var $tree = null; /** * XML::Tree object of the user logged in. * * @access private * @var XML_Tree * @see readUserData() */ var $userObj = null; /** * Indicates if backend module initialized correctly. If yes, * true, if not false. Backend module won't initialize if the * init value (usually an object or resource handle that * identifies the backend to be used) is not of the required * type. * * @var boolean * @access public */ var $init_ok = false; /** * Columns of the perm table. * Associative array with the names of the perm table columns. * The 'group_id' and 'group_define_name' fields have to be set. * 'group_type', 'is_active', 'owner_user_id' and 'owner_group_id' are optional. * It doesn't make sense to set only one of the time columns without the * other. * * The type attribute is only useful when using MDB or MDB2. * * @access public * @var array */ var $groupTableCols = array( 'required' => array( 'group_id' => array('type' => 'integer', 'name' => 'group_id'), 'group_define_name' => array('type' => 'text', 'name' => 'group_define_name') ), 'optional' => array( 'group_type' => array('type' => 'integer', 'name' => 'group_type'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id') ) ); /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage_XML(&$conf) { $this->LiveUser_Perm_Storage(&$conf); if (!is_file($this->file)) { if (is_file(getenv('DOCUMENT_ROOT') . $this->file)) { $this->file = getenv('DOCUMENT_ROOT') . $this->file; } else { $this->_stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find xml file."); return false; } } if ($this->file) { if (class_exists('XML_Tree')) { $tree =& new XML_Tree($this->file); $err =& $tree->getTreeFromFile(); if (PEAR::isError($err)) { return false; } else { $this->tree = $tree; $this->init_ok = true; } } else { $this->_stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find XML_Tree class"); return false; } } else { $this->_stack->push(LIVEUSER_ERROR_MISSING_DEPS, 'exception', array(), "Perm initialisation failed. Can't find XML_Tree class"); return false; } } function mapUser($uid, $containerName) { $nodeIndex = 0; $userIndex = 0; $result = false; foreach ($this->tree->root->children as $node) { if ($node->name == 'users') { foreach ($node->children as $user) { if ($user->name != 'user') { continue; } if ($uid == $user->attributes['authUserId'] && $containerName == $user->attributes['authContainerName'] ) { $result['userid'] = $user->attributes['userId']; $result['usertype'] = $user->attributes['type']; $this->userObj =& $this->tree->root->getElement(array($nodeIndex, $userIndex)); break; } $userIndex++; } } $nodeIndex++; } return $result; } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { $result = array(); foreach ($this->userObj->children as $node) { if ($node->name == 'rights') { $tmp = explode(',', $node->content); foreach ($tmp as $value) { $result[$value] = 1; } } } return $result; } /** * properly disconnect from resources * * @access public */ function disconnect() { $this->tree = null; $this->userObj = null; } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Simple.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Simple.php +++ pear/Perm_LiveUser/Perm/Simple.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * Base class for permission handling * * @package LiveUser * @category authentication */ /**#@+ * Usertypes * * @var integer */ /** * lowest user type id */ define('LIVEUSER_ANONYMOUS_TYPE_ID', 0); /** * lowest user type id */ // higest user type id define('LIVEUSER_USER_TYPE_ID', 1); /** * lowest admin type id */ define('LIVEUSER_ADMIN_TYPE_ID', 2); define('LIVEUSER_AREAADMIN_TYPE_ID', 3); define('LIVEUSER_SUPERADMIN_TYPE_ID', 4); /** * higest admin type id */ define('LIVEUSER_MASTERADMIN_TYPE_ID', 5); /**#@-*/ /** * This class provides a set of functions for implementing a user * permission management system on live websites. All authorisation * backends/containers must be extensions of this base class. * * @author Markus Wolff <wolff@21st.de> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: Simple.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Simple { /** * Unique user ID, used to identify users from the auth container. * * @var string */ var $permUserId = ''; /** * One-dimensional array containing current user's rights. * This already includes grouprights and possible overrides by * individual right settings. * * Format: "RightId" => "Level" * * @var mixed */ var $rights = false; /** * One-dimensional array containing only the individual * rights for the actual user. * * Format: "RightId" => "Level" * * @var array */ var $userRights = array(); /** * Two-dimensional array containing all groups that * the user belongs to and the grouprights. * * Format: "GroupId" => "RightId" => "Level" * * @var array * @see $userRights * @see $rights */ var $groupRights = array(); /** * Defines the user type. * * @var integer */ var $userType = LIVEUSER_ANONYMOUS_TYPE_ID; /** * Defines the (sub)groups in which the user is a member * * @var mixed */ var $groupIds = false; /** * Defines if the user rights should be retrieved ondemand. * * @var boolean */ var $ondemand = false; /** * Error stack * * @var PEAR_ErrorStack */ var $_stack = null; /** * Class constructor. Feel free to override in backend subclasses. */ function LiveUser_Perm_Simple($confArray) { $this->_stack = &PEAR_ErrorStack::singleton('LiveUser'); $this->_storage = LiveUser::storageFactory($confArray); } /** * Tries to find the user with the given user ID in the permissions * container. Will read all permission data and return true on success. * * @access public * @param string user identifier * @param string name of the auth container * @return boolean true on success or false on failure */ function init($uid = null, $containerName = null) { $result = $this->_storage->mapUser($uid, $containerName); if (!$result) { return false; } $this->permUserId = $result['userid']; $this->userType = $result['usertype']; $this->readRights(); return true; } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readRights() { $result = $this->_storage->readUserRights($this->permUserId); if (!$result) { return false; } $this->rights = $result; return true; } /** * Checks if the current user has a certain right in a * given area. * If $this->ondemand and $ondemand is true, the rights will be loaded on * the fly. * * @access public * @param integer $right_id Id of the right to check for. * @param boolean $ondemand allow ondemand reading of rights * @return integer Level of the right. */ function checkRight($right_id, $ondemand = true) { if (is_array($this->rights)) { // check if the user is above areaadmin if (!$right_id || $this->userType > LIVEUSER_AREAADMIN_TYPE_ID) { return LIVEUSER_MAX_LEVEL; } else { // If he does, look for the right in question. if (in_array($right_id, array_keys($this->rights))) { // We know the user has the right so the right level will be returned. return $this->rights[$right_id]; } } } elseif ($this->ondemand && $ondemand) { $this->readRights(); return $this->checkRight($right_id, false); } return false; } // end func checkRight /** * Function returns the inquired value if it exists in the class. * * @param string Name of the property to be returned. * @return mixed null, a value or an array. */ function getProperty($what) { $that = null; if (isset($this->$what)) { $that = $this->$what; } return $that; } /** * store all properties in an array * * @access public * @return array containing the property values */ function freeze() { $propertyValues = array( 'permUserId' => $this->permUserId, 'rights' => $this->rights, 'userRights' => $this->userRights, 'groupRights' => $this->groupRights, 'userType' => $this->userType, 'groupIds' => $this->groupIds, ); return $this->_storage->freeze($propertyValues); } // end func freeze /** * Reinitializes properties * * @access public * @param array $propertyValues */ function unfreeze($propertyValues = false) { $propertyValues = $this->_storage->unfreeze(); if ($propertyValues) { foreach ($propertyValues as $key => $value) { $this->{$key} = $value; } } return $this->init(); } // end func unfreeze /** * properly disconnect from resources * * @access public */ function disconnect() { $this->_storage->disconnect(); } } ?> http://cvs.php.net/co.php/pear/Perm_LiveUser/Perm/Storage.php?r=1.1&p=1 Index: pear/Perm_LiveUser/Perm/Storage.php +++ pear/Perm_LiveUser/Perm/Storage.php <?php // LiveUser: A framework for authentication and authorization in PHP applications // Copyright (C) 2002-2003 Markus Wolff // // 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, MA 02111-1307 USA /** * MDB2_Complex container for permission handling * * @package LiveUser * @category authentication */ /** * This is a PEAR::MDB2 backend driver for the LiveUser class. * A PEAR::MDB2 connection object can be passed to the constructor to reuse an * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: * - File "Liveuser.php" (contains the parent class "LiveUser") * - Array of connection options or a PEAR::MDB2 connection object must be * passed to the constructor. * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR * &$conn (PEAR::MDB2 connection object) * * @author Lukas Smith <smith@backendmedia.com> * @author Bjoern Kraus <krausbn@php.net> * @version $Id: Storage.php,v 1.1 2004/11/08 15:57:34 lsmith Exp $ * @package LiveUser * @category authentication */ class LiveUser_Perm_Storage { /** * dsn that was connected to * @var object * @access private */ var $dsn = null; /** * disconnect * @var object * @access private */ var $disconnect = null; /** * PEAR::MDB2 connection object. * * @var object * @access private */ var $dbc = null; /** * Table prefix * Prefix for all db tables the container has. * * @var string * @access public */ var $prefix = 'liveuser_'; /** * Indicates if backend module initialized correctly. If yes, * true, if not false. Backend module won't initialize if the * init value (usually an object or resource handle that * identifies the backend to be used) is not of the required * type. * * @var boolean * @access public */ var $init_ok = false; var $session_name; /** * Columns of the perm table. * Associative array with the names of the perm table columns. * The 'group_id' and 'group_define_name' fields have to be set. * 'group_type', 'is_active', 'owner_user_id' and 'owner_group_id' are optional. * It doesn't make sense to set only one of the time columns without the * other. * * The type attribute is only useful when using MDB or MDB2. * * @access public * @var array */ var $groupTableCols = array( 'required' => array( 'group_id' => array('type' => 'integer', 'name' => 'group_id'), 'group_define_name' => array('type' => 'text', 'name' => 'group_define_name') ), 'optional' => array( 'group_type' => array('type' => 'integer', 'name' => 'group_type'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id') ) ); /** * Constructor * * @access protected * @param mixed configuration array * @return void */ function LiveUser_Perm_Storage(&$conf) { if (is_array($conf)) { foreach ($conf as $key => $value) { if (isset($this->$key)) { $this->$key = $value; } } } } function mapUser($uid, $containerName) { } /** * Reads all rights of current user into a * two-dimensional associative array, having the * area names as the key of the 1st dimension. * Group rights and invididual rights are being merged * in the process. */ function readUserRights($permUserId) { } /** * store all properties in an array * * @access public * @return array containing the property values */ function freeze($propertyValues) { $_SESSION[$this->session_name]['perm'] = $propertyValues; return $propertyValues; } // end func freeze /** * Reinitializes properties * * @access public * @param array $propertyValues */ function unfreeze($propertyValues = false) { return $_SESSION[$this->session_name]['perm']; } // end func unfreeze /** * properly disconnect from resources * * @access public */ function disconnect() { } } ?>