[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Auth_application class provides a wrapper around 4 * application-provided Horde authentication which fits inside the 5 * Horde Auth:: API. 6 * 7 * Required parameters:<pre> 8 * 'app' The application which is providing authentication.</pre> 9 * 10 * 11 * $Horde: framework/Auth/Auth/application.php,v 1.27.10.12 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_application extends Auth { 23 24 /** 25 * An array of capabilities, so that the driver can report which 26 * operations it supports and which it doesn't. 27 * 28 * @var array 29 */ 30 var $capabilities = array('add' => false, 31 'update' => false, 32 'resetpassword' => false, 33 'remove' => false, 34 'list' => false, 35 'transparent' => false); 36 37 /** 38 * Constructs a new Application authentication object. 39 * 40 * @param array $params A hash containing connection parameters. 41 */ 42 function Auth_application($params = array()) 43 { 44 $this->_setParams($params); 45 } 46 47 /** 48 * Queries the current Auth object to find out if it supports the given 49 * capability. 50 * 51 * @param string $capability The capability to test for. 52 * 53 * @return boolean Whether or not the capability is supported. 54 */ 55 function hasCapability($capability) 56 { 57 static $loaded = array(); 58 59 $methods = array('list' => 'userList', 60 'add' => 'addUser', 61 'update' => 'updateUser', 62 'remove' => 'removeUser'); 63 64 if (empty($loaded[$capability]) && isset($methods[$capability])) { 65 $this->capabilities[$capability] = $GLOBALS['registry']->hasMethod($methods[$capability], $this->_params['app']); 66 $loaded[$capability] = true; 67 } 68 69 return !empty($this->capabilities[$capability]); 70 } 71 72 /** 73 * Set connection parameters. 74 * 75 * @access private 76 * 77 * @param array $params A hash containing connection parameters. 78 */ 79 function _setParams($params) 80 { 81 Horde::assertDriverConfig($params, 'auth', 82 array('app'), 83 'authentication application'); 84 85 if (empty($GLOBALS['registry']->applications[$params['app']])) { 86 Horde::fatal($params['app'] . ' is not configured in the Horde Registry.', __FILE__, __LINE__); 87 } 88 89 $this->_params = $params; 90 } 91 92 /** 93 * Find out if a set of login credentials are valid. 94 * 95 * @access private 96 * 97 * @param string $userId The userId to check. 98 * @param array $credentials The credentials to use. 99 * 100 * @return boolean Whether or not the credentials are valid. 101 */ 102 function _authenticate($userId, $credentials) 103 { 104 if (!$GLOBALS['registry']->hasMethod('authenticate', $this->_params['app'])) { 105 Horde::fatal($this->_params['app'] . ' does not provide an authenticate() method.', __FILE__, __LINE__); 106 } 107 return $GLOBALS['registry']->callByPackage($this->_params['app'], 'authenticate', 108 array('userId' => $userId, 109 'credentials' => $credentials, 110 'params' => $this->_params)); 111 } 112 113 /** 114 * Return the URI of the login screen for this authentication method. 115 * 116 * @access private 117 * 118 * @param string $app The application to use. 119 * @param string $url The URL to redirect to after login. 120 * 121 * @return string The login screen URI. 122 */ 123 function _getLoginScreen($app = 'horde', $url = '') 124 { 125 return parent::_getLoginScreen($this->_params['app'], $url); 126 } 127 128 /** 129 * List all users in the system. 130 * 131 * @return mixed The array of userIds, or a PEAR_Error object on failure. 132 */ 133 function listUsers() 134 { 135 if ($this->hasCapability('list')) { 136 return $GLOBALS['registry']->callByPackage($this->_params['app'], 'userList'); 137 } else { 138 return PEAR::raiseError('unsupported'); 139 } 140 } 141 142 /** 143 * Add a set of authentication credentials. 144 * 145 * @param string $userId The userId to add. 146 * @param array $credentials The credentials to use. 147 * 148 * @return mixed True on success or a PEAR_Error object on failure. 149 */ 150 function addUser($userId, $credentials) 151 { 152 if ($this->hasCapability('add')) { 153 return $GLOBALS['registry']->callByPackage($this->_params['app'], 'addUser', array($userId, $credentials)); 154 } else { 155 return PEAR::raiseError('unsupported'); 156 } 157 } 158 159 /** 160 * Update a set of authentication credentials. 161 * 162 * @param string $oldID The old userId. 163 * @param string $newID The new userId. 164 * @param array $credentials The new credentials 165 * 166 * @return mixed True on success or a PEAR_Error object on failure. 167 */ 168 function updateUser($oldID, $newID, $credentials) 169 { 170 if ($this->hasCapability('update')) { 171 return $GLOBALS['registry']->callByPackage($this->_params['app'], 'updateUser', array($oldID, $newID, $credentials)); 172 } else { 173 return PEAR::raiseError('unsupported'); 174 } 175 } 176 177 /** 178 * Delete a set of authentication credentials. 179 * 180 * @param string $userId The userId to delete. 181 * 182 * @return mixed True on success or a PEAR_Error object on failure. 183 */ 184 function removeUser($userId) 185 { 186 if ($this->hasCapability('remove')) { 187 $result = $GLOBALS['registry']->callByPackage($this->_params['app'], 'removeUser', array($userId)); 188 } else { 189 return PEAR::raiseError('unsupported'); 190 } 191 if (is_a($result, 'PEAR_Error')) { 192 return $result; 193 } 194 195 return $this->removeUserData($userId); 196 } 197 198 }
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 |