Add Horde_Auth::requireAuth()
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 24 Aug 2009 20:05:32 +0000 (14:05 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 24 Aug 2009 20:05:32 +0000 (14:05 -0600)
framework/Auth/lib/Horde/Auth.php
framework/Core/lib/Horde/Registry.php

index 62dda89..a09cc8e 100644 (file)
@@ -370,6 +370,7 @@ class Horde_Auth
      * </pre>
      *
      * @return boolean  Whether or not the user is authenticated.
+     * @throws Horde_Auth_Exception
      */
     static public function isAuthenticated($options = array())
     {
@@ -394,6 +395,26 @@ class Horde_Auth
     }
 
     /**
+     * Checks if an application requires additional authentication above and
+     * beyond Horde authentication.
+     *
+     * @params string $app  The application to check.
+     *
+     * @return boolean  Whether or not the application required additional
+     *                  authentication.
+     * @throws Horde_Auth_Exception
+     */
+    static public function requireAuth($app)
+    {
+        if ($app == 'horde') {
+            return false;
+        }
+
+        $app_auth = self::singleton('application', array('app' => $app));
+        return $app_auth->requireAuth();
+    }
+
+    /**
      * Check existing auth for triggers that might invalidate it.
      *
      * @return boolean  Is existing auth valid?
index 992a1f8..007105f 100644 (file)
@@ -975,14 +975,12 @@ class Horde_Registry
     public function hasPermission($app, $perms = PERMS_READ)
     {
         /* Always do isAuthenticated() check first. You can be an admin, but
-         * application auth != Horde admin auth. */
-        if (!Horde_Auth::isAuthenticated(array('app' => $app))) {
-            /* There can *never* be non-SHOW access to an application that
-             * requires authentication. */
-            $app_auth = Horde_Auth::singleton('application', array('app' => $app));
-            if ($app_auth->requireAuth() && ($perms != PERMS_SHOW)) {
-                return false;
-            }
+         * application auth != Horde admin auth. And there can *never* be
+         * non-SHOW access to an application that requires authentication. */
+        if (!Horde_Auth::isAuthenticated(array('app' => $app)) &&
+            Horde_Auth::requireAuth($app) &&
+            ($perms != PERMS_SHOW)) {
+            return false;
         }
 
         /* Otherwise, allow access for admins, for apps that do not have any