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