From: Michael M Slusarz Date: Tue, 3 Aug 2010 18:38:37 +0000 (-0600) Subject: Bug #9165: Fix creating Horde_Auth_Imap object using IMP config X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=87286a612ce133fd3111222c1881809707022f90;p=horde.git Bug #9165: Fix creating Horde_Auth_Imap object using IMP config --- diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 7c20488b3..a09c7eb3e 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -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 index 000000000..de61c91d7 --- /dev/null +++ b/imp/lib/Injector/Binder/AuthImap.php @@ -0,0 +1,51 @@ + + * @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; + } + +}