{
$userId = self::addHook(trim($userId));
- if (!empty($GLOBALS['conf']['hooks']['postauthenticate']) &&
- !Horde::callHook('_horde_hook_postauthenticate', array($userId, $credentials, $realm), 'horde', false)) {
- if (self::getAuthError() != self::REASON_MESSAGE) {
- self::setAuthError(self::REASON_FAILED);
- }
- return false;
+ if (!empty($GLOBALS['conf']['hooks']['postauthenticate'])) {
+ try {
+ if (!Horde::callHook('_horde_hook_postauthenticate', array($userId, $credentials, $realm), 'horde')) {
+ if (self::getAuthError() != self::REASON_MESSAGE) {
+ self::setAuthError(self::REASON_FAILED);
+ }
+ return false;
+ }
+ } catch (Horde_Exception $e) {}
}
/* If we're already set with this userId, don't continue. */
* @param string $userId The authentication backend's user name.
*
* @return string The internal Horde user name.
+ * @throws Horde_Exception
*/
static public function addHook($userId)
{
- if (!empty($GLOBALS['conf']['hooks']['username'])) {
- $newId = Horde::callHook('_username_hook_frombackend', array($userId));
- if (!is_a($newId, 'PEAR_Error')) {
- return $newId;
- }
- }
-
- return $userId;
+ return empty($GLOBALS['conf']['hooks']['username'])
+ ? $userId
+ : Horde::callHook('_username_hook_frombackend', array($userId));
}
/**
* @param string $userId The internal Horde user name.
*
* @return string The authentication backend's user name.
+ * @throws Horde_Exception
*/
static public function removeHook($userId)
{
- if (!empty($GLOBALS['conf']['hooks']['username'])) {
- $newId = Horde::callHook('_username_hook_tobackend', array($userId));
- if (!is_a($newId, 'PEAR_Error')) {
- return $newId;
- }
- }
-
- return $userId;
+ return empty($GLOBALS['conf']['hooks']['username'])
+ ? $userId
+ : Horde::callHook('_username_hook_tobackend', array($userId));
}
/**
$userId = trim($userId);
if (!empty($GLOBALS['conf']['hooks']['preauthenticate'])) {
- if (!Horde::callHook('_horde_hook_preauthenticate', array($userId, $credentials, $realm), 'horde', false)) {
- if (Horde_Auth::getAuthError() != Horde_Auth::REASON_MESSAGE) {
- Horde_Auth::setAuthError(Horde_Auth::REASON_FAILED);
+ try {
+ if (!Horde::callHook('_horde_hook_preauthenticate', array($userId, $credentials, $realm), 'horde')) {
+ if (Horde_Auth::getAuthError() != Horde_Auth::REASON_MESSAGE) {
+ Horde_Auth::setAuthError(Horde_Auth::REASON_FAILED);
+ }
+ return false;
}
- return false;
- }
+ } catch (Horde_Exception $e) {}
}
/* Store the credentials being checked so that subclasses can modify
global $conf;
if (!empty($conf['hooks']['authldap'])) {
$entry = Horde::callHook('_horde_hook_authldap', array($userId, $credentials));
- if ($entry instanceof PEAR_Error) {
- throw new Horde_Exception($entry);
- }
$dn = $entry['dn'];
/* Remove the dn entry from the array. */
unset($entry['dn']);
if (!empty($GLOBALS['conf']['hooks']['authldap'])) {
$entry = Horde::callHook('_horde_hook_authldap', array($userId));
- if ($entry instanceof PEAR_Error) {
- throw new Horde_Exception($entry);
- }
$dn = $entry['dn'];
} else {
/* Search for the user's full DN. */
if (!empty($GLOBLS['conf']['hooks']['authldap'])) {
$entry = Horde::callHook('_horde_hook_authldap', array($oldID, $credentials));
- if ($entry instanceof PEAR_Error) {
- throw new Horde_Exception($entry);
- }
$olddn = $entry['dn'];
$entry = Horde::callHook('_horde_hook_authldap', array($newID, $credentials));
$newdn = $entry['dn'];
/* Connect to the MSAD server. */
$this->_connect();
- $entry = Horde::callHook('_horde_hook_authmsad', array($accountName, $credentials), 'horde', null);
+ try {
+ $entry = Horde::callHook('_horde_hook_authmsad', array($accountName, $credentials), 'horde');
+ } catch (Horde_Exception $e) {}
+
if (!is_null($entry)) {
$dn = $entry['dn'];
unset($entry['dn']);
/* Connect to the MSAD server. */
$this->_connect();
- $entry = Horde::callHook('_horde_hook_authmsad', array($accountName), 'horde', null);
- if (!is_null($entry)) {
- $dn = $entry['dn'];
- } else {
+ try {
+ $entry = Horde::callHook('_horde_hook_authmsad', array($accountName), 'horde');
+ } catch (Horde_Exception $e) {}
+
+ $dn = is_null($entry)
/* Search for the user's full DN. */
- $dn = $this->_findDN($accountName);
- }
+ ? $this->_findDN($accountName)
+ : $entry['dn'];
if (!@ldap_delete($this->_ds, $dn)) {
throw new Horde_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', null);
+ try {
+ $entry = Horde::callHook('_horde_hook_authmsad', array($oldId, $credentials), 'horde');
+ } catch (Horde_Exception $e) {}
+
if (!is_null($entry)) {
$olddn = $entry['dn'];
unset($entry['dn']);
// Perform any preprocessing if requested.
if ($conf['signup']['preprocess']) {
$info = Horde::callHook('_horde_hook_signup_preprocess', array($info));
- if (is_a($info, 'PEAR_Error')) {
- return $info;
- }
}
// Check to see if the username already exists.
}
$result = true;
+
// Attempt to add/update any extra data handed in.
if (!empty($info['extra'])) {
- $result = false;
- $result = Horde::callHook('_horde_hook_signup_addextra',
- array($info['user_name'], $info['extra']));
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_EMERG);
- return $result;
+ 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());
}
}
// Perform any preprocessing if requested.
if ($conf['signup']['preprocess']) {
- $info = Horde::callHook('_horde_hook_signup_preprocess',
- array($info));
- if (is_a($info, 'PEAR_Error')) {
- return $info;
- }
+ try {
+ $info = Horde::callHook('_horde_hook_signup_preprocess', array($info));
+ } catch (Horde_Exception $e) {}
}
// Check to see if the username already exists.
}
if ($conf['signup']['queue']) {
- $result = Horde::callHook('_horde_hook_signup_queued',
- array($info['user_name'], $info));
+ try {
+ $result = Horde::callHook('_horde_hook_signup_queued', array($info['user_name'], $info));
+ } catch (Horde_Exception $e) {}
}
if (!empty($conf['signup']['email'])) {
$this->addHidden('', 'url', 'text', false);
/* Use hooks get any extra fields required in signing up. */
- $extra = Horde::callHook('_horde_hook_signup_getextra');
- if (!is_a($extra, 'PEAR_Error') && !empty($extra)) {
+ try {
+ $extra = Horde::callHook('_horde_hook_signup_getextra');
+ } catch (Horde_Exception $e) {}
+
+ if (!empty($extra)) {
if (!isset($extra['user_name'])) {
$this->addVariable(_("Choose a username"), 'user_name', 'text', true);
}
* function.
* @param string $app If specified look for hooks in the config directory
* of this app.
- * @param mixed $error What to return if $app/config/hooks.php or $hook
- * does not exist. If this is the string 'PEAR_Error'
- * a PEAR error object is returned instead, detailing
- * the failure.
*
- * @return mixed Either the results of the hook or PEAR error on failure.
- * @todo Throw Horde_Exception
+ * @return mixed The results of the hook.
*/
- static public function callHook($hook, $args = array(), $app = 'horde',
- $error = 'PEAR_Error')
+ static public function callHook($hook, $args = array(), $app = 'horde')
{
if (!isset(self::$_hooksLoaded[$app])) {
try {
}
}
- if (function_exists($hook)) {
- $result = call_user_func_array($hook, $args);
- if ($result instanceof PEAR_Error) {
- self::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- }
- return $result;
- }
+ if (!function_exists($hook)) {
+ throw new Horde_Exception(sprintf('Hook %s in application %s not called.', $hook, $app));
- if (is_string($error) && strcmp($error, 'PEAR_Error') == 0) {
- $error = PEAR::raiseError(sprintf('Hook %s in application %s not called.', $hook, $app));
- self::logMessage($error, __FILE__, __LINE__, PEAR_LOG_DEBUG);
}
- return $error;
+ try {
+ return call_user_func_array($hook, $args);
+ } catch (Horde_Exception $e) {
+ self::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+ }
}
/**
$this->_appStack[] = $app;
/* Call post-push hook. */
- Horde::callHook('_horde_hook_post_pushapp', array($app), 'horde', null);
+ try {
+ Horde::callHook('_horde_hook_post_pushapp', array($app), 'horde');
+ } catch (Horde_Exception $e) {}
return true;
}