3
* The Auth_application class provides a wrapper around
4
* application-provided Horde authentication which fits inside the
9
* 'app' -- The application which is providing authentication.
12
* $Horde: framework/Auth/Auth/application.php,v 1.27.10.5 2005/01/19 15:05:03 jan Exp $
14
* Copyright 2002-2005 Chuck Hagenbuch <chuck@horde.org>
16
* See the enclosed file COPYING for license information (LGPL). If you
17
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
19
* @author Chuck Hagenbuch <chuck@horde.org>
23
class Auth_application extends Auth {
26
* An array of capabilities, so that the driver can report which
27
* operations it supports and which it doesn't.
29
* @var array $capabilities
31
var $capabilities = array('add' => false,
33
'resetpassword' => false,
36
'transparent' => false);
39
* Constructs a new Application authentication object.
43
* @param optional array $params A hash containing connection parameters.
45
function Auth_application($params = array())
47
$this->_setParams($params);
51
* Queries the current Auth object to find out if it supports the given
56
* @param string $capability The capability to test for.
58
* @return boolean Whether or not the capability is supported.
60
function hasCapability($capability)
62
static $loaded = array();
64
$methods = array('list' => 'userList',
66
'update' => 'updateUser',
67
'remove' => 'removeUser');
69
if (empty($loaded[$capability]) && isset($methods[$capability])) {
70
$this->capabilities[$capability] = $GLOBALS['registry']->hasMethod($methods[$capability], $this->_params['app']);
71
$loaded[$capability] = true;
74
return !empty($this->capabilities[$capability]);
78
* Set connection parameters.
82
* @param array $params A hash containing connection parameters.
84
function _setParams($params)
86
Horde::assertDriverConfig($params, 'auth',
88
'authentication application');
90
if (empty($GLOBALS['registry']->applications[$params['app']])) {
91
Horde::fatal($params['app'] . ' is not configured in the Horde Registry.', __FILE__, __LINE__);
94
$this->_params = $params;
98
* Find out if a set of login credentials are valid.
102
* @param string $userId The userId to check.
103
* @param array $credentials The credentials to use.
105
* @return boolean Whether or not the credentials are valid.
107
function _authenticate($userId, $credentials)
109
if (!$GLOBALS['registry']->hasMethod('authenticate', $this->_params['app'])) {
110
Horde::fatal($this->_params['app'] . ' does not provide an authenticate() method.', __FILE__, __LINE__);
112
return $GLOBALS['registry']->callByPackage($this->_params['app'], 'authenticate',
113
array('userId' => $userId,
114
'credentials' => $credentials,
115
'params' => $this->_params));
119
* Return the URI of the login screen for this authentication
124
* @param optional string $app The application to use.
125
* @param optional string $url The URL to redirect to after login.
127
* @return string The login screen URI.
129
function _getLoginScreen($app = 'horde', $url = '')
131
return parent::_getLoginScreen($this->_params['app'], $url);
135
* List all users in the system.
139
* @return mixed The array of userIds, or a PEAR_Error object on failure.
143
if ($this->hasCapability('list')) {
144
return $GLOBALS['registry']->callByPackage($this->_params['app'], 'userList');
146
return PEAR::raiseError('unsupported');
151
* Add a set of authentication credentials.
155
* @param string $userId The userId to add.
156
* @param array $credentials The credentials to use.
158
* @return mixed True on success or a PEAR_Error object on failure.
160
function addUser($userId, $credentials)
162
if ($this->hasCapability('add')) {
163
return $GLOBALS['registry']->callByPackage($this->_params['app'], 'addUser', array($userId, $credentials));
165
return PEAR::raiseError('unsupported');
170
* Update a set of authentication credentials.
174
* @param string $oldID The old userId.
175
* @param string $newID The new userId.
176
* @param array $credentials The new credentials
178
* @return mixed True on success or a PEAR_Error object on failure.
180
function updateUser($oldID, $newID, $credentials)
182
if ($this->hasCapability('update')) {
183
return $GLOBALS['registry']->callByPackage($this->_params['app'], 'updateUser', array($oldID, $newID, $credentials));
185
return PEAR::raiseError('unsupported');
190
* Delete a set of authentication credentials.
194
* @param string $userId The userId to delete.
196
* @return mixed True on success or a PEAR_Error object on failure.
198
function removeUser($userId)
200
if ($this->hasCapability('remove')) {
201
$result = $GLOBALS['registry']->callByPackage($this->_params['app'], 'removeUser', array($userId));
203
return PEAR::raiseError('unsupported');
205
if (is_a($result, 'PEAR_Error')) {
209
return $this->removeUserData($userId);