Bug #9165: Fix creating Horde_Auth_Imap object using IMP config
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 3 Aug 2010 18:38:37 +0000 (12:38 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 3 Aug 2010 18:40:03 +0000 (12:40 -0600)
imp/lib/Application.php
imp/lib/Injector/Binder/AuthImap.php [new file with mode: 0644]

index 7c20488..a09c7eb 100644 (file)
@@ -90,6 +90,7 @@ class IMP_Application extends Horde_Registry_Application
     {
         /* Add IMP-specific binders. */
         $binders = array(
+            'IMP_AuthImap' => new IMP_Injector_Binder_AuthImap(),
             'IMP_Compose' => new IMP_Injector_Binder_Compose(),
             'IMP_Contents' => new IMP_Injector_Binder_Contents(),
             'IMP_Crypt_Pgp' => new IMP_Injector_Binder_Pgp(),
@@ -342,21 +343,11 @@ class IMP_Application extends Horde_Registry_Application
      *                            this must contain a password entry.
      *
      * @throws Horde_Exception
+     * @throws IMP_Exception
      */
     public function authAddUser($userId, $credentials)
     {
-        $params = $GLOBALS['registry']->callByPackage('imp', 'server');
-        if (is_null($params)) {
-            return;
-        }
-
-        $params = array_merge($params, $_SESSION['imp']['imap']['admin']['params']);
-        if (isset($params['admin_password'])) {
-            $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
-            $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']);
-        }
-
-        $GLOBALS['injector']->getInstance('Horde_Auth')->getAuth('imap', $params)->addUser($userId, $credentials);
+        $GLOBALS['injector']->getInstance('IMP_AuthImap')->addUser($userId, $credentials);
     }
 
     /**
@@ -365,21 +356,11 @@ class IMP_Application extends Horde_Registry_Application
      * @param string $userId  The userId to delete.
      *
      * @throws Horde_Exception
+     * @throws IMP_Exception
      */
     public function authRemoveUser($userId)
     {
-        $params = $GLOBALS['registry']->callByPackage('imp', 'server');
-        if (is_null($params)) {
-            return;
-        }
-
-        $params = array_merge($params, $_SESSION['imp']['imap']['admin']['params']);
-        if (isset($params['admin_password'])) {
-            $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
-            $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']);
-        }
-
-        $GLOBALS['injector']->getInstance('Horde_Auth')->getAuth('imap', $params)->removeUser($userId);
+        $GLOBALS['injector']->getInstance('IMP_AuthImap')->removeUser($userId);
     }
 
     /**
@@ -387,21 +368,11 @@ class IMP_Application extends Horde_Registry_Application
      *
      * @return array  The array of userIds.
      * @throws Horde_Exception
+     * @throws IMP_Exception
      */
     public function authUserList()
     {
-        $params = $GLOBALS['registry']->callByPackage('imp', 'server');
-        if (is_null($params)) {
-            return;
-        }
-
-        $params = array_merge($params, $_SESSION['imp']['imap']['admin']['params']);
-        if (isset($params['admin_password'])) {
-            $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
-            $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']);
-        }
-
-        return $GLOBALS['injector']->getInstance('Horde_Auth')->getAuth('imap', $params)->listUsers();
+        return $GLOBALS['injector']->getInstance('IMP_AuthImap')->listUsers();
     }
 
     /* Preferences display/handling methods. Code is contained in
diff --git a/imp/lib/Injector/Binder/AuthImap.php b/imp/lib/Injector/Binder/AuthImap.php
new file mode 100644 (file)
index 0000000..de61c91
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Binder for Horde_Auth_Imap:: that uses IMP configuration.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  IMP
+ */
+class IMP_Injector_Binder_AuthImap implements Horde_Injector_Binder
+{
+    /**
+     * @throws IMP_Exception
+     */
+    public function create(Horde_Injector $injector)
+    {
+        $params = $GLOBALS['registry']->callByPackage('imp', 'server');
+        if (is_null($params)) {
+            throw new IMP_Exception('No mail parameters found.');
+        }
+
+        $params = array_merge(
+            $params,
+            $_SESSION['imp']['imap']['admin']['params'],
+            array(
+                'default_user' => $GLOBALS['registry']->getAuth(),
+                'logger' => $injector->getInstance('Horde_Log_Logger')
+            )
+        );
+
+        if (isset($params['admin_password'])) {
+            $secret = $injector->getInstance('Horde_Secret');
+            $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']);
+        }
+
+        return Horde_Auth::factory('imap', $params);
+    }
+
+    /**
+     */
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+
+}