This should properly set the userId for Kolab auth
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 23 Jul 2009 04:35:36 +0000 (22:35 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 23 Jul 2009 16:55:59 +0000 (10:55 -0600)
Do class check once in constructor.
Correctly identify that this driver does authentication.

framework/Auth/lib/Horde/Auth/Kolab.php

index fc91059..1df3545 100644 (file)
@@ -22,12 +22,28 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
      *
      * @var array
      */
-    protected $capabilities = array(
+    protected $_capabilities = array(
         'add' => true,
+        'authenticate' => true,
         'list' => true
     );
 
     /**
+     * Constructor.
+     *
+     * @param array $params  A hash containing parameters.
+     * @throws Horde_Auth_Exception
+     */
+    public function __construct($params = array())
+    {
+        if (!class_exists('Horde_Kolab_Session')) {
+            throw new Horde_Auth_Exception('The Horde_Kolab_Session class is not available.');
+        }
+
+        parent::__construct($params);
+    }
+
+    /**
      * Find out if a set of login credentials are valid.
      *
      * For Kolab this requires to identify the IMAP server the user should
@@ -47,19 +63,17 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
 
         $params = array();
 
-        if (class_exists('Horde_Kolab_Session')) {
-            try {
-                $session = Horde_Kolab_Session::singleton($userId, $credentials, true);
-            } catch (Horde_Kolab_Server_MissingObjectException $e) {
-                throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
-            } catch (Exception $e) {
-                Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
-                throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
-            }
-        } else {
-            throw new Horde_Auth_Exception('The class Horde_Kolab_Session is required for the Kolab auth driver but it is missing!', Horde_Auth::REASON_MESSAGE);
+        try {
+            $session = Horde_Kolab_Session::singleton($userId, $credentials, true);
+        } catch (Horde_Kolab_Server_MissingObjectException $e) {
+            throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
+        } catch (Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
         }
 
+        $this->_credentials['userId'] = $session->user_mail;
+
         if (!isset($conf['auth']['params']) ||
             $conf['auth']['params']['login_block'] != 1) {
             // Return if feature is disabled.
@@ -124,31 +138,6 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
     }
 
     /**
-     * Sets a variable in the session saying that authorization has succeeded,
-     * note which userId was authorized, and note when the login took place.
-     *
-     * The kolab driver rewrites UIDs into the correct mail addresses that
-     * need to be used to log into the IMAP server.
-     *
-     * @param string $userId            The userId who has been authorized.
-     * @param array $credentials        The credentials of the user.
-     * @param boolean $change           Whether to request that the user change
-     *                                  their password.
-     */
-    function setAuth($userId, $credentials, $change = false)
-    {
-        // TODO - setAuth doesn't exist in Horde_Auth_Base
-        //        This should probably use _username_hook_frombackend.
-
-        if (class_exists('Horde_Kolab_Session')) {
-            $session = Horde_Kolab_Session::singleton($userId);
-            $userId = $session->user_mail;
-        }
-
-        return parent::setAuth($userId, $credentials, $change);
-    }
-
-    /**
      * List Users
      *
      * @return array  List of Users
@@ -156,10 +145,6 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
      */
     public function listUsers()
     {
-        if (!class_exists('Horde_Kolab_Session')) {
-            throw new Horde_Auth_Exception('The Horde_Kolab_Session class is not available.');
-        }
-
         $session = Horde_Kolab_Session::singleton();
         $server = $session->getServer();
         if ($server instanceof PEAR_Error) {
@@ -170,6 +155,7 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
         foreach ($users as $user) {
             $mails[] = $user->get(KOLAB_ATTR_MAIL);
         }
+
         return $mails;
     }
 
@@ -183,10 +169,6 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
      */
     public function addUser($userId, $credentials)
     {
-        if (!class_exists('Horde_Kolab_Session')) {
-            throw new Horde_Auth_Exception('The Horde_Kolab_Session class is not available.');
-        }
-
         $session = Horde_Kolab_Session::singleton();
         $server = $session->getServer();
         if ($server instanceof PEAR_Error) {
@@ -199,9 +181,9 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
             return true;
         } else if ($result instanceof PEAR_Error) {
             return $result;
-        } else {
-            throw new Horde_Auth_Exception(sprintf('The new Kolab object is a %s rather than a ' . KOLAB_OBJECT_USER, get_class($result)));
         }
+
+        throw new Horde_Auth_Exception(sprintf('The new Kolab object is a %s rather than a ' . KOLAB_OBJECT_USER, get_class($result)));
     }
 
 }