Reduce the functionality of the kolab authentication driver. Some functionality shoul...
authorGunnar Wrobel <p@rdus.de>
Wed, 4 Nov 2009 11:10:47 +0000 (12:10 +0100)
committerGunnar Wrobel <p@rdus.de>
Wed, 4 Nov 2009 11:10:47 +0000 (12:10 +0100)
framework/Auth/lib/Horde/Auth/Kolab.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Exception/Bindfailed.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php
framework/Kolab_Server/package.xml
framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Exception/Badlogin.php [new file with mode: 0644]
framework/Kolab_Session/package.xml

index 1df3545..66b430c 100644 (file)
@@ -23,27 +23,15 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
      * @var array
      */
     protected $_capabilities = array(
-        'add' => true,
-        'authenticate' => true,
-        'list' => true
+        'authenticate'  => true,
+        'list'          => true,
+        /** @todo These would only work if we allow manager login */
+        'add'           => false,
+        'remove'        => false,
+        'update'        => false
     );
 
     /**
-     * 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
@@ -59,131 +47,131 @@ class Horde_Auth_Kolab extends Horde_Auth_Base
      */
     protected function _authenticate($userId, $credentials)
     {
-        global $conf;
-
-        $params = array();
-
         try {
-            $session = Horde_Kolab_Session::singleton($userId, $credentials, true);
-        } catch (Horde_Kolab_Server_MissingObjectException $e) {
+            $session = Horde_Kolab_Session_Singleton::singleton(
+                $userId, $credentials
+            );
+        } catch (Horde_Kolab_Session_Exception_Badlogin $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;
+        $this->_credentials['userId'] = $session->getMail();
 
-        if (!isset($conf['auth']['params']) ||
-            $conf['auth']['params']['login_block'] != 1) {
-            // Return if feature is disabled.
-            return $session->auth;
-        }
+        return true;
 
-        if ($session->auth !== true &&
-            class_exists('Horde_History')) {
-            $history = Horde_History::singleton();
-
-            $history_identifier = "$userId@logins.kolab";
-            $history_log = $history->getHistory($history_identifier);
-            $history_list = array();
-
-            // Extract history list from log.
-            if ($history_log && !($history_log instanceof PEAR_Error)) {
-                $data = $history_log->getData();
-                if (!empty($data)) {
-                    $entry = array_shift($data);
-                    $history_list = $entry['history_list'];
-                }
-            }
-
-            // Calculate the time range.
-            $start_time = (time() - $conf['auth']['params']['login_block_time'] * 60);
-
-            $new_history_list = array();
-            $count = 0;
-
-            // Copy and count all relevant timestamps.
-            foreach ($history_list as $entry) {
-                $timestamp = $entry[ 'timestamp' ];
-
-                if ($timestamp > $start_time) {
-                    $new_history_list[] = $entry;
-                    $count++;
-                }
-            }
-
-            $max_count = $conf['auth']['params']['login_block_count'];
-
-            if ($count > $max_count) {
-                // Add entry for current failed login.
-                $entry = array();
-                $entry[ 'timestamp' ] = time();
-                $new_history_list[] = $entry;
-
-                // Write back history.
-                $history->log($history_identifier,
-                              array('action' => 'add', 'who' => $userId,
-                                    'history_list' => $new_history_list), true);
-
-                if ($count > $max_count) {
-                    throw new Horde_Auth_Exception(_("Too many invalid logins during the last minutes."));
-                }
-
-                throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
-            }
-        }
+/*         if (!isset($conf['auth']['params']) || */
+/*             $conf['auth']['params']['login_block'] != 1) { */
+/*             // Return if feature is disabled. */
+/*             return $session->auth; */
+/*         } */
 
-        return ($session->auth === true);
-    }
+/*         if ($session->auth !== true && */
+/*             class_exists('Horde_History')) { */
+/*             $history = Horde_History::singleton(); */
 
-    /**
-     * List Users
-     *
-     * @return array  List of Users
-     * @throws Horde_Auth_Exception
-     */
-    public function listUsers()
-    {
-        $session = Horde_Kolab_Session::singleton();
-        $server = $session->getServer();
-        if ($server instanceof PEAR_Error) {
-            return $server;
-        }
-        $users = $server->listObjects(KOLAB_OBJECT_USER);
-        $mails = array();
-        foreach ($users as $user) {
-            $mails[] = $user->get(KOLAB_ATTR_MAIL);
-        }
+/*             $history_identifier = "$userId@logins.kolab"; */
+/*             $history_log = $history->getHistory($history_identifier); */
+/*             $history_list = array(); */
 
-        return $mails;
-    }
+/*             // Extract history list from log. */
+/*             if ($history_log && !($history_log instanceof PEAR_Error)) { */
+/*                 $data = $history_log->getData(); */
+/*                 if (!empty($data)) { */
+/*                     $entry = array_shift($data); */
+/*                     $history_list = $entry['history_list']; */
+/*                 } */
+/*             } */
 
-    /**
-     * Add a set of authentication credentials.
-     *
-     * @param string $userId      The userId to add.
-     * @param array $credentials  The credentials to be set.
-     *
-     * @throws Horde_Auth_Exception
-     */
-    public function addUser($userId, $credentials)
-    {
-        $session = Horde_Kolab_Session::singleton();
-        $server = $session->getServer();
-        if ($server instanceof PEAR_Error) {
-            return $server;
-        }
+/*             // Calculate the time range. */
+/*             $start_time = (time() - $conf['auth']['params']['login_block_time'] * 60); */
 
-        $result = $server->store(KOLAB_OBJECT_USER, $userId, $credentials);
+/*             $new_history_list = array(); */
+/*             $count = 0; */
 
-        if (is_a($result, KOLAB_OBJECT_USER)) {
-            return true;
-        } else if ($result instanceof PEAR_Error) {
-            return $result;
-        }
+/*             // Copy and count all relevant timestamps. */
+/*             foreach ($history_list as $entry) { */
+/*                 $timestamp = $entry[ 'timestamp' ]; */
+
+/*                 if ($timestamp > $start_time) { */
+/*                     $new_history_list[] = $entry; */
+/*                     $count++; */
+/*                 } */
+/*             } */
+
+/*             $max_count = $conf['auth']['params']['login_block_count']; */
+
+/*             if ($count > $max_count) { */
+/*                 // Add entry for current failed login. */
+/*                 $entry = array(); */
+/*                 $entry[ 'timestamp' ] = time(); */
+/*                 $new_history_list[] = $entry; */
 
-        throw new Horde_Auth_Exception(sprintf('The new Kolab object is a %s rather than a ' . KOLAB_OBJECT_USER, get_class($result)));
+/*                 // Write back history. */
+/*                 $history->log($history_identifier, */
+/*                               array('action' => 'add', 'who' => $userId, */
+/*                                     'history_list' => $new_history_list), true); */
+
+/*                 if ($count > $max_count) { */
+/*                     throw new Horde_Auth_Exception(_("Too many invalid logins during the last minutes.")); */
+/*                 } */
+
+/*                 throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN); */
+/*             } */
+/*         } */
+
+/*         return ($session->auth === true); */
     }
 
+/*     /\** */
+/*      * List Users */
+/*      * */
+/*      * @return array  List of Users */
+/*      * @throws Horde_Auth_Exception */
+/*      *\/ */
+/*     public function listUsers() */
+/*     { */
+/*         $session = Horde_Kolab_Session_Singleton::singleton(); */
+/*         $server = $session->getServer(); */
+/*         if ($server instanceof PEAR_Error) { */
+/*             return $server; */
+/*         } */
+/*         $users = $server->listObjects(KOLAB_OBJECT_USER); */
+/*         $mails = array(); */
+/*         foreach ($users as $user) { */
+/*             $mails[] = $user->get(KOLAB_ATTR_MAIL); */
+/*         } */
+
+/*         return $mails; */
+/*     } */
+
+/*     /\** */
+/*      * Add a set of authentication credentials. */
+/*      * */
+/*      * @param string $userId      The userId to add. */
+/*      * @param array $credentials  The credentials to be set. */
+/*      * */
+/*      * @throws Horde_Auth_Exception */
+/*      *\/ */
+/*     public function addUser($userId, $credentials) */
+/*     { */
+/*         $session = Horde_Kolab_Session::singleton(); */
+/*         $server = $session->getServer(); */
+/*         if ($server instanceof PEAR_Error) { */
+/*             return $server; */
+/*         } */
+
+/*         $result = $server->store(KOLAB_OBJECT_USER, $userId, $credentials); */
+
+/*         if (is_a($result, KOLAB_OBJECT_USER)) { */
+/*             return true; */
+/*         } else if ($result instanceof PEAR_Error) { */
+/*             return $result; */
+/*         } */
+
+/*         throw new Horde_Auth_Exception(sprintf('The new Kolab object is a %s rather than a ' . KOLAB_OBJECT_USER, get_class($result))); */
+/*     } */
+
 }
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Exception/Bindfailed.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Exception/Bindfailed.php
new file mode 100644 (file)
index 0000000..b293f50
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Indicate that the given bind credentials were invalid.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+/**
+ * Indicate that the given bind credentials were invalid.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+class Horde_Kolab_Server_Exception_Bindfailed extends Horde_Kolab_Server_Exception
+{
+}
index 1adfdd5..a0ada57 100644 (file)
@@ -319,7 +319,12 @@ implements Horde_Kolab_Server_Interface
         $code = Horde_Kolab_Server_Exception::SYSTEM
     ) {
         if ($result instanceOf PEAR_Error) {
-            throw new Horde_Kolab_Server_Exception($result, $code);
+            if ($code == Horde_Kolab_Server_Exception::BIND_FAILED
+                && $result->getCode() == 49) {
+                throw new Horde_Kolab_Server_Exception_Bindfailed($result, $code);
+            } else {
+                throw new Horde_Kolab_Server_Exception($result, $code);
+            }
         }
     }
 
index 861c459..05b936d 100644 (file)
@@ -83,6 +83,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
        </dir> <!-- /lib/Horde/Kolab/Server/Decorator -->
        <file name="Exception.php" role="php" />
        <dir name="Exception">
+        <file name="Bindfailed.php" role="php" />
         <file name="Novalue.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Server/Exception -->
        <dir name="Factory">
@@ -367,6 +368,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Kolab/Server/Decorator/Log.php" as="Horde/Kolab/Server/Decorator/Log.php" />
    <install name="lib/Horde/Kolab/Server/Decorator/Map.php" as="Horde/Kolab/Server/Decorator/Map.php" />
    <install name="lib/Horde/Kolab/Server/Exception.php" as="Horde/Kolab/Server/Exception.php" />
+   <install name="lib/Horde/Kolab/Server/Exception/Bindfailed.php" as="Horde/Kolab/Server/Exception/Bindfailed.php" />
    <install name="lib/Horde/Kolab/Server/Exception/Novalue.php" as="Horde/Kolab/Server/Exception/Novalue.php" />
    <install name="lib/Horde/Kolab/Server/Factory/Base.php" as="Horde/Kolab/Server/Factory/Base.php" />
    <install name="lib/Horde/Kolab/Server/Factory/Configuration.php" as="Horde/Kolab/Server/Factory/Configuration.php" />
index add352c..2234cbb 100644 (file)
@@ -143,6 +143,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         try {
             $this->_server->connect($this->_user_id, $password);
             $user_object     = $this->_server->objects->fetch();
+        } catch (Horde_Kolab_Server_Exception_Bindfailed $e) {
+            throw new Horde_Kolab_Session_Exception_Badlogin($e);
+        }
         } catch (Horde_Kolab_Server_Exception $e) {
             throw new Horde_Kolab_Session_Exception($e);
         }
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Exception/Badlogin.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Exception/Badlogin.php
new file mode 100644 (file)
index 0000000..de0aee1
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Indicate bad login credentials.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Session
+ */
+
+/**
+ * Indicate bad login credentials.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Session
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Session
+ */
+class Horde_Kolab_Session_Exception_Badlogin extends Horde_Kolab_Session_Exception
+{
+}
\ No newline at end of file
index 2049419..5918bfa 100644 (file)
@@ -55,6 +55,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
        </dir> <!-- /lib/Horde/Session/Auth -->
        <file name="Base.php" role="php" />
        <file name="Exception.php" role="php" />
+       <dir name="Exception">
+        <file name="Badlogin.php" role="php" />
+       </dir> <!-- /lib/Horde/Session/Exception -->
        <file name="Factory.php" role="php" />
        <dir name="Factory">
         <file name="Anonymous.php" role="php" />
@@ -174,6 +177,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Kolab/Session/Auth/Mock.php" as="Horde/Kolab/Session/Auth/Mock.php" />
    <install name="lib/Horde/Kolab/Session/Base.php" as="Horde/Kolab/Session/Base.php" />
    <install name="lib/Horde/Kolab/Session/Exception.php" as="Horde/Kolab/Session/Exception.php" />
+   <install name="lib/Horde/Kolab/Session/Exception/Badlogin.php" as="Horde/Kolab/Session/Exception/Badlogin.php" />
    <install name="lib/Horde/Kolab/Session/Factory.php" as="Horde/Kolab/Session/Factory.php" />
    <install name="lib/Horde/Kolab/Session/Factory/Anonymous.php" as="Horde/Kolab/Session/Factory/Anonymous.php" />
    <install name="lib/Horde/Kolab/Session/Factory/Base.php" as="Horde/Kolab/Session/Factory/Base.php" />