1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
<?php
/**
* The Auth_composite class provides a wrapper around
* application-provided Horde authentication which fits inside the
* Horde Auth:: API.
*
* Required parameters:<pre>
* None.</pre>
*
*
* $Horde: framework/Auth/Auth/composite.php,v 1.26.10.10 2006/08/14 02:48:48 chuck Exp $
*
* Copyright 2002-2006 Chuck Hagenbuch <chuck@horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @since Horde 3.0
* @package Horde_Auth
*/
class Auth_composite extends Auth {
/**
* Hash containing any instantiated drivers.
*
* @var array
*/
var $_drivers = array();
/**
* Constructs a new Composite authentication object.
*
* @param array $params A hash containing connection parameters.
*/
function Auth_composite($params = array())
{
$this->_setParams($params);
}
/**
* Set connection parameters.
*
* @access private
*
* @param array $params A hash containing connection parameters.
*/
function _setParams($params)
{
if (!is_array($params)) {
Horde::fatal('No configuration information specified for Composite authentication.', __FILE__, __LINE__);
}
$this->_params = $params;
}
/**
* Return the named parameter for the current auth driver.
*
* @param string $param The parameter to fetch.
*
* @return string The parameter's value.
*/
function getParam($param)
{
if (($login_driver = Auth::_getDriverByParam('loginscreen_switch', $this->_params)) &&
$this->_loadDriver($login_driver)) {
return $this->_drivers[$login_driver]->getParam($param);
}
return null;
}
/**
* Find out if a set of login credentials are valid.
*
* @access private
*
* @param string $userId The userId to check.
* @param array $credentials The credentials to use.
*
* @return boolean Whether or not the credentials are valid.
*/
function _authenticate($userId, $credentials)
{
if (($auth_driver = Auth::_getDriverByParam('loginscreen_switch', $this->_params)) &&
$this->_loadDriver($auth_driver)) {
return $this->_drivers[$auth_driver]->authenticate($userId, $credentials);
}
if (($auth_driver = Auth::_getDriverByParam('username_switch', $this->_params, array($userId))) &&
$this->_loadDriver($auth_driver)) {
return $this->_drivers[$auth_driver]->hasCapability('transparent');
}
$this->_setAuthError(AUTH_REASON_FAILED);
return false;
}
/**
* Query the current Auth object to find out if it supports the given
* capability.
*
* @param string $capability The capability to test for.
*
* @return boolean Whether or not the capability is supported.
*/
function hasCapability($capability)
{
switch ($capability) {
case 'add':
case 'update':
case 'remove':
case 'list':
if (!empty($this->_params['admin_driver']) &&
$this->_loadDriver($this->_params['admin_driver'])) {
return $this->_drivers[$this->_params['admin_driver']]->hasCapability($capability);
} else {
return false;
}
break;
case 'transparent':
if (($login_driver = Auth::_getDriverByParam('loginscreen_switch', $this->_params)) &&
$this->_loadDriver($login_driver)) {
return $this->_drivers[$login_driver]->hasCapability('transparent');
}
return false;
break;
default:
return false;
}
}
/**
* Automatic authentication: Find out if the client matches an allowed IP
* block.
*
* @return boolean Whether or not the client is allowed.
*/
function transparent()
{
if (($login_driver = Auth::_getDriverByParam('loginscreen_switch', $this->_params)) &&
$this->_loadDriver($login_driver)) {
return $this->_drivers[$login_driver]->transparent();
}
return false;
}
/**
* Return the URI of the login screen for this authentication object.
*
* @access private
*
* @param string $app The application to use.
* @param string $url The URL to redirect to after login.
*
* @return string The login screen URI.
*/
function _getLoginScreen($app = 'horde', $url = '')
{
if (($login_driver = Auth::_getDriverByParam('loginscreen_switch', $this->_params)) &&
$this->_loadDriver($login_driver)) {
return $this->_drivers[$login_driver]->_getLoginScreen($app, $url);
} else {
return parent::_getLoginScreen($app, $url);
}
}
/**
* Add a set of authentication credentials.
*
* @param string $userId The userId to add.
* @param array $credentials The credentials to use.
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function addUser($userId, $credentials)
{
if (!empty($this->_params['admin_driver']) &&
$this->_loadDriver($this->_params['admin_driver'])) {
return $this->_drivers[$this->_params['admin_driver']]->addUser($userId, $credentials);
} else {
return PEAR::raiseError('Unsupported');
}
}
/**
* Update a set of authentication credentials.
*
* @param string $oldID The old userId.
* @param string $newID The new userId.
* @param array $credentials The new credentials
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function updateUser($oldID, $newID, $credentials)
{
if (!empty($this->_params['admin_driver']) &&
$this->_loadDriver($this->_params['admin_driver'])) {
return $this->_drivers[$this->_params['admin_driver']]->updateUser($oldID, $newID, $credentials);
} else {
return PEAR::raiseError('Unsupported');
}
}
/**
* Delete a set of authentication credentials.
*
* @param string $userId The userId to delete.
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function removeUser($userId)
{
if (!empty($this->_params['admin_driver']) &&
$this->_loadDriver($this->_params['admin_driver'])) {
return $this->_drivers[$this->_params['admin_driver']]->removeUser($userId);
} else {
return PEAR::raiseError('Unsupported');
}
}
/**
* List all users in the system.
*
* @return mixed The array of userIds, or a PEAR_Error object on failure.
*/
function listUsers()
{
if (!empty($this->_params['admin_driver']) &&
$this->_loadDriver($this->_params['admin_driver'])) {
return $this->_drivers[$this->_params['admin_driver']]->listUsers();
} else {
return PEAR::raiseError('Unsupported');
}
}
/**
* Checks if a userId exists in the system.
*
* @param string $userId User ID to check
*
* @return boolean Whether or not the userId already exists.
*/
function exists($userId)
{
if (!empty($this->_params['admin_driver']) &&
$this->_loadDriver($this->_params['admin_driver'])) {
return $this->_drivers[$this->_params['admin_driver']]->exists($userId);
} else {
return PEAR::raiseError('Unsupported');
}
}
/**
* Loads one of the drivers in our configuration array, if it isn't already
* loaded.
*
* @access private
*
* @param string $driver The name of the driver to load.
*
* @return boolean True if driver successfully initializes.
*/
function _loadDriver($driver)
{
if (empty($this->_drivers[$driver])) {
// This is a bit specialized for Horde::getDriverConfig(),
// so localize it here:
global $conf;
if (!empty($this->_params['drivers'][$driver]['params'])) {
$params = $this->_params['drivers'][$driver]['params'];
if (isset($conf[$this->_params['drivers'][$driver]['driver']])) {
$params = array_merge($conf[$this->_params['drivers'][$driver]['driver']], $params);
}
} elseif (!empty($conf[$driver])) {
$params = $conf[$driver];
} else {
$params = null;
}
$this->_drivers[$driver] = &Auth::singleton($this->_params['drivers'][$driver]['driver'], $params);
}
return isset($this->_drivers[$driver]);
}
}
|