IMP transparent auth improvements.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 15 Oct 2009 11:50:10 +0000 (05:50 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 15 Oct 2009 11:53:32 +0000 (05:53 -0600)
Document what credentials IMP uses internally for auth.
Provide ability to override default transparent authentication (via
hordeauth) with userId/credentials values returned from
preauthenticate().

imp/config/hooks.php.dist
imp/lib/Auth.php

index d5089f9..4e2c86c 100644 (file)
 class IMP_Hooks
 {
     /**
+     * AUTHENTICATION HOOK: pre-authentication actions.
+     *
+     * See horde/config/hooks.php.dist for more information.
+     *
+     * IMP uses the following credentials:
+     *   'password' - (string) The password for mail server authentication.
+     *   'server' - (string) [optional] Use this server key (see
+     *              config/servers.php).
+     *   'transparent' - (boolean) If $credentials['authMethod'] is
+     *                   'transparent', and you would like IMP to use
+     *                   the userId/credentials generated in the
+     *                   preauthentication hook, this must be true. If false,
+     *                   IMP will try to authenticate using hordeauth.
+     */
+//     function preauthenticate($userId, $credentials)
+//     {
+//         return true;
+//     }
+
+
+    /**
+     * AUTHENTICATION HOOK: post-authentication actions.
+     *
+     * See horde/config/hooks.php.dist for more information.
+     */
+     function postauthenticate($userId, $credentials)
+//     {
+//         return true;
+//     }
+
+
+    /**
      * PREFERENCE HOOK: Dynamically set the signature preference.
      *
      * @param string $username  The username.
index bef0036..7a07fed 100644 (file)
@@ -87,11 +87,25 @@ class IMP_Auth
     /**
      * Perform transparent authentication.
      *
+     * @param Horde_Auth_Application $auth_ob  The authentication object.
+     *
      * @return boolean  Whether transparent login is supported.
      * @throws Horde_Auth_Exception
      */
-    static public function transparent()
+    static public function transparent($auth_ob)
     {
+        /* It is possible that preauthenticate() set the credentials.
+         * If so, use that information instead of hordeauth. */
+        if ($auth_ob->getCredential('transparent')) {
+            $credentials = $auth_ob->getCredential();
+            if (!isset($credentials['server'])) {
+                $credentials['server'] = self::getAutoLoginServer();
+            }
+            self::_createSession($auth_ob->getCredential());
+            return true;
+        }
+
+        /* Attempt hordeauth authentication. */
         $credentials = self::_canAutoLogin();
         if ($credentials === false) {
             return false;