}
/**
- * Applies a hook defined by the function _username_hook_frombackend() to
- * the given user name if this function exists and user hooks are enabled.
+ * Applies the username_frombackend hook to the given user name.
*
* This method should be called if a authentication backend's user name
* needs to be converted to a (unique) Horde user name. The backend's user
*/
static public function addHook($userId)
{
- return empty($GLOBALS['conf']['hooks']['username'])
- ? $userId
- : Horde::callHook('_username_hook_frombackend', array($userId));
+ try {
+ return Horde::callHook('username_frombackend', array($userId));
+ } catch (Horde_Exception_HookNotSet $e) {
+ return $userId;
+ }
}
/**
- * Applies a hook defined by the function _username_hook_tobackend() to
- * the given user name if this function exists and user hooks are enabled.
+ * Applies the username_tobackend hook to the given user name.
*
* This method should be called if a Horde user name needs to be converted
* to an authentication backend's user name or displayed to the user. The
*/
static public function removeHook($userId)
{
- return empty($GLOBALS['conf']['hooks']['username'])
- ? $userId
- : Horde::callHook('_username_hook_tobackend', array($userId));
+ try {
+ return Horde::callHook('username_tobackend', array($userId));
+ } catch (Horde_Exception_HookNotSet $e) {
+ return $userId;
+ }
}
/**
{
$ret_array = array($userId, $credentials);
- if (!empty($GLOBALS['conf']['hooks'][$type])) {
- $result = Horde::callHook('_horde_hook_' . $type, array($userId, $credentials, $app), 'horde');
- if ($result === false) {
- if (self::getAuthError() != self::REASON_MESSAGE) {
- self::setAuthError(self::REASON_FAILED);
- }
- throw new Horde_Auth_Exception($type . ' hook failed');
+ try {
+ $result = Horde::callHook($type, array($userId, $credentials), $app);
+ } catch (Horde_Exception $e) {
+ throw new Horde_Auth_Exception($e->getMessage());
+ } catch (Horde_Exception_HookNotSet $e) {
+ return $ret_array;
+ }
+
+ if ($result === false) {
+ if (self::getAuthError() != self::REASON_MESSAGE) {
+ self::setAuthError(self::REASON_FAILED);
}
+ throw new Horde_Auth_Exception($type . ' hook failed');
+ }
- if (is_array($result)) {
- if (isset($result['userId'])) {
- $ret_array[0] = $result['userId'];
- }
+ if (is_array($result)) {
+ if (isset($result['userId'])) {
+ $ret_array[0] = $result['userId'];
+ }
- if (isset($result['credentials'])) {
- $ret_array[1] = $result['credentials'];
- }
+ if (isset($result['credentials'])) {
+ $ret_array[1] = $result['credentials'];
}
}
* DEFAULT: NONE (system default will be used)
* </pre>
*
+ * 'preauthenticate' hook should return LDAP connection information in the
+ * 'ldap' credentials key.
+ *
* Copyright 1999-2009 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you did
/* Connect to the LDAP server. */
$this->_connect();
- global $conf;
- if (!empty($conf['hooks']['authldap'])) {
- $entry = Horde::callHook('_horde_hook_authldap', array($userId, $credentials));
+ list($userId, $credentials) = Horde_Auth::runHook($userId, $credentials, $this->_app, 'preauthenticate');
+ if (isset($credentials['ldap'])) {
+ $entry = $credentials['ldap'];
$dn = $entry['dn'];
+
/* Remove the dn entry from the array. */
unset($entry['dn']);
} else {
$entry['shadowLastChange'] = floor(time() / 86400);
}
}
+
$result = @ldap_add($this->_ds, $dn, $entry);
if (!$result) {
/* Connect to the LDAP server. */
$this->_connect();
- if (!empty($GLOBALS['conf']['hooks']['authldap'])) {
- $entry = Horde::callHook('_horde_hook_authldap', array($userId));
- $dn = $entry['dn'];
+ list($userId, $credentials) = Horde_Auth::runHook($userId, array(), $this->_app, 'preauthenticate');
+ if (isset($credentials['ldap'])) {
+ $dn = $credentials['ldap']['dn'];
} else {
/* Search for the user's full DN. */
$dn = $this->_findDN($userId);
/* Connect to the LDAP server. */
$this->_connect();
- if (!empty($GLOBLS['conf']['hooks']['authldap'])) {
- $entry = Horde::callHook('_horde_hook_authldap', array($oldID, $credentials));
- $olddn = $entry['dn'];
- $entry = Horde::callHook('_horde_hook_authldap', array($newID, $credentials));
- $newdn = $entry['dn'];
- unset($entry['dn']);
+ list($oldID, $old_credentials) = Horde_Auth::runHook($oldID, $credentials, $this->_app, 'preauthenticate');
+ if (isset($old_credentials['ldap'])) {
+ $olddn = $old_credentials['ldap']['dn'];
+ list($newID, $new_credentials) = Horde_Auth::runHook($newID, $credentials, $this->_app, 'preauthenticate');
+ $newdn = $new_credentials['ldap']['dn'];
+ unset($new_credentials['ldap']['dn']);
} else {
/* Search for the user's full DN. */
$dn = $this->_findDN($oldID);
/* Connect to the MSAD server. */
$this->_connect();
- $entry = Horde::callHook('_horde_hook_authmsad', array($accountName, $credentials), 'horde');
- if (!is_null($entry)) {
- $dn = $entry['dn'];
- unset($entry['dn']);
+ list($accountName, $credentials) = Horde_Auth::runHook($accountName, $credentials, $this->_app, 'preauthenticate');
+ if (isset($credentials['ldap'])) {
+ $dn = $credentials['ldap']['dn'];
} else {
- $basedn = (isset($credentials['basedn'])) ?
- $credentials['basedn'] : $this->_params['basedn'];
+ $basedn = isset($credentials['basedn'])
+ ? $credentials['basedn']
+ : $this->_params['basedn'];
/* Set a default CN */
$dn = 'cn=' . $accountName . ',' . $basedn;
$success = @ldap_add($this->_ds, $dn, $entry);
if (!$success) {
- throw new Horde_Auth_Exception(sprintf(_("Auth_msad: Unable to add user \"%s\". This is what the server said: "), $accountName) . ldap_error($this->_ds));
+ throw new Horde_Auth_Exception(sprintf(_("Horde_Auth_Msad: Unable to add user \"%s\". This is what the server said: "), $accountName) . ldap_error($this->_ds));
}
@ldap_close($this->_ds);
/* Connect to the MSAD server. */
$this->_connect();
- $entry = Horde::callHook('_horde_hook_authmsad', array($accountName), 'horde');
- $dn = is_null($entry)
+ list($accountName, $credentials) = Horde_Auth::runHook($accountName, $credentials, $this->_app, 'preauthenticate');
+ if (isset($credentials['ldap'])) {
+ $dn = $credentials['ldap']['dn'];
+ } else {
/* Search for the user's full DN. */
- ? $this->_findDN($accountName)
- : $entry['dn'];
+ $dn = $this->_findDN($accountName);
+ }
if (!@ldap_delete($this->_ds, $dn)) {
throw new Horde_Auth_Exception(sprintf(_("Horde_Auth_Msad: Unable to remove user \"%s\""), $accountName));
/* Connect to the MSAD server. */
$this->_connect();
- $entry = Horde::callHook('_horde_hook_authmsad', array($oldId, $credentials), 'horde');
- if (!is_null($entry)) {
- $olddn = $entry['dn'];
- unset($entry['dn']);
+ list($oldId, $credentials) = Horde_Auth::runHook($oldId, $credentials, $this->_app, 'preauthenticate');
+ if (isset($credentials['ldap'])) {
+ $olddn = $credentials['ldap']['dn'];
} else {
/* Search for the user's full DN. */
$dn = $this->_findDN($oldId);
* been compiled, relying on the hooks.php file.
*
* @params mixed $info Reference to array of parameteres to be passed
- * to hook
+ * to hook.
*
- * @return mixed PEAR_Error if any errors, otherwise true.
+ * @throws Horde_Exception
*/
- public function addSignup(&$info)
+ public function addSignup($info)
{
- global $auth, $conf;
+ global $auth;
// Perform any preprocessing if requested.
- if ($conf['signup']['preprocess']) {
- $info = Horde::callHook('_horde_hook_signup_preprocess', array($info));
- }
+ try {
+ $info = Horde::callHook('signup_preprocess', array($info));
+ } catch (Horde_Exception_HookNotSet $e) {}
// Check to see if the username already exists.
if ($auth->exists($info['user_name']) ||
$this->exists($info['user_name'])) {
- return PEAR::raiseError(sprintf(_("Username \"%s\" already exists."), $info['user_name']));
+ throw new Horde_Exception(sprintf(_("Username \"%s\" already exists."), $info['user_name']));
}
// Attempt to add the user to the system.
- $result = $auth->addUser($info['user_name'], array('password' => $info['password']));
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
-
- $result = true;
+ $auth->addUser($info['user_name'], array('password' => $info['password']));
// Attempt to add/update any extra data handed in.
if (!empty($info['extra'])) {
- try {
- return Horde::callHook('_horde_hook_signup_addextra', array($info['user_name'], $info['extra']));
- } catch (Horde_Exception $e) {
- Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_EMERG);
- return PEAR::raiseError($e->getMessage(), $e->getCode());
- }
- }
-
- return $result;
+ Horde::callHook('signup_addextra', array($info['user_name'], $info['extra']));
+ } catch (Horde_Exception_HookNotSet $e) {}
}
/**
* @params mixed $info Reference to array of parameteres to be passed
* to hook
*
- * @return mixed PEAR_Error if any errors, otherwise true.
- *
+ * @throws Horde_Exception
* @throws Horde_Mime_Exception
*/
public function queueSignup(&$info)
global $auth, $conf;
// Perform any preprocessing if requested.
- if ($conf['signup']['preprocess']) {
- $info = Horde::callHook('_horde_hook_signup_preprocess', array($info));
- }
+ try {
+ $info = Horde::callHook('signup_preprocess', array($info));
+ } catch (Horde_Exception_HookNotSet $e) {}
// Check to see if the username already exists.
if ($auth->exists($info['user_name']) ||
$this->exists($info['user_name'])) {
- return PEAR::raiseError(sprintf(_("Username \"%s\" already exists."), $info['user_name']));
+ throw new Horde_Exception(sprintf(_("Username \"%s\" already exists."), $info['user_name']));
}
// If it's a unique username, go ahead and queue the request.
return $result;
}
- if ($conf['signup']['queue']) {
- $result = Horde::callHook('_horde_hook_signup_queued', array($info['user_name'], $info));
- }
+ try {
+ Horde::callHook('signup_queued', array($info['user_name'], $info));
+ } catch (Horde_Exception_HookNotSet $e) {}
if (!empty($conf['signup']['email'])) {
$link = Horde_Util::addParameter(Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/admin/signup_confirm.php', true, -1),
* @params mixed $info Reference to array of parameteres to be passed
* to hook
*
- * @return mixed PEAR_Error if any errors, otherwise true.
+ * @throws Horde_Exception
*/
- protected function &_queueSignup(&$info)
+ protected function _queueSignup(&$info)
{
- return PEAR::raiseError('Not implemented');
+ throw new Horde_Exception('Not implemented');
}
/**
*
* @param string $username The username to retrieve the queued info for.
*
- * @return object The bject for the requested signup.
+ * @return object The object for the requested signup.
+ * @throws Horde_Exception
*/
public function getQueuedSignup($username)
{
- return PEAR::raiseError('Not implemented');
+ throw new Horde_Exception('Not implemented');
}
/**
* Get the queued information for all pending signups.
*
* @return array An array of objects, one for each signup in the queue.
+ * @throws Horde_Exception
*/
public function getQueuedSignups()
{
- return PEAR::raiseError('Not implemented');
+ throw new Horde_Exception('Not implemented');
}
/**
* Remove a queued signup.
*
* @param string $username The user to remove from the signup queue.
+ * @throws Horde_Exception
*/
public function removeQueuedSignup($username)
{
- return PEAR::raiseError('Not implemented');
+ throw new Horde_Exception('Not implemented');
}
/**
* @param string $name The signups's name.
*
* @return object A new signup object.
+ * @throws Horde_Exception
*/
public function newSignup($name)
{
- return PEAR::raiseError('Not implemented');
+ throw new Horde_Exception('Not implemented');
}
}
$this->addHidden('', 'url', 'text', false);
/* Use hooks get any extra fields required in signing up. */
- $extra = Horde::callHook('_horde_hook_signup_getextra');
+ try {
+ $extra = Horde::callHook('signup_getextra');
+ } catch (Horde_Exception_HookNotSet $e) {}
+
if (!empty($extra)) {
if (!isset($extra['user_name'])) {
$this->addVariable(_("Choose a username"), 'user_name', 'text', true);
const AUTH_FAILURE = 1;
const NOT_ACTIVE = 2;
const PERMISSION_DENIED = 3;
+ const HOOK_FATAL = 4;
/**
* Singleton value.
* Horde_Registry::AUTH_FAILURE
* Horde_Registry::NOT_ACTIVE
* Horde_Registry::PERMISSION_DENIED
+ * Horde_Registry::HOOK_FATAL
*/
public function pushApp($app, $options = array())
{
$this->_appStack[] = $app;
/* Call post-push hook. */
- Horde::callHook('_horde_hook_post_pushapp', array($app), 'horde');
+ try {
+ Horde::callHook('pushapp', array(), $app);
+ } catch (Horde_Exception $e) {
+ $e->setCode(self::HOOK_FATAL);
+ throw $e;
+ } catch (Horde_Exception_HookNotSet $e) {}
/* Do login tasks. */
if (Horde_Auth::getAuth()) {