Fix transparent auth for several drivers.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 8 Dec 2009 08:37:15 +0000 (01:37 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 8 Dec 2009 08:40:11 +0000 (01:40 -0700)
A driver should never call Horde_Auth::setAuth() itself - setAuth is
automatically called with the proper parameters if _transparent()
returns true.

Addtionally, should return false if transparent login not available, not
an exception.

framework/Auth/lib/Horde/Auth/Base.php
framework/Auth/lib/Horde/Auth/Http.php
framework/Auth/lib/Horde/Auth/Ipbasic.php
framework/Auth/lib/Horde/Auth/Shibboleth.php

index e53dbd3..df7e52d 100644 (file)
@@ -236,10 +236,7 @@ abstract class Horde_Auth_Base
      * to set the credentials in the session.
      *
      * Transparent authentication should normally never throw an error - false
-     * should normally be returned. However, it is also possible that a
-     * transparent authentication is the only available auth method; if so,
-     * attempting to login via a login page may cause an endless loop. In this
-     * case, an Exception should be thrown which will act as a fatal error.
+     * should be returned.
      *
      * @return boolean  Whether transparent login is supported.
      * @throws Horde_Auth_Exception
index 62dbe7f..f08f092 100644 (file)
@@ -106,16 +106,20 @@ class Horde_Auth_Http extends Horde_Auth_Base
      * authentication info present.
      *
      * @return boolean  Whether or not the client is allowed.
-     * @throws Horde_Auth_Exception
      */
     protected function _transparent()
     {
-        if (!empty($_SERVER['PHP_AUTH_USER']) &&
-            !empty($_SERVER['PHP_AUTH_PW'])) {
-            return Horde_Auth::setAuth(Horde_Util::dispelMagicQuotes($_SERVER['PHP_AUTH_USER']), array('password' => Horde_Util::dispelMagicQuotes($_SERVER['PHP_AUTH_PW']), 'transparent' => 1));
+        if (empty($_SERVER['PHP_AUTH_USER']) ||
+            empty($_SERVER['PHP_AUTH_PW'])) {
+            return false;
         }
 
-        throw new Horde_Auth_Exception(_("HTTP Authentication not found."));
+        $this->_credentials['userId'] = $_SERVER['PHP_AUTH_USER'];
+        $this->_credentials['credentials'] = array(
+            'password' => Horde_Util::dispelMagicQuotes($_SERVER['PHP_AUTH_PW'])
+        );
+
+        return true;
     }
 
 }
index db3ba81..f58c92e 100644 (file)
@@ -51,22 +51,21 @@ class Horde_Auth_Ipbasic extends Horde_Auth_Base
      * block.
      *
      * @return boolean  Whether or not the client is allowed.
-     * @throws Horde_Auth_Exception
      */
     protected function _transparent()
     {
         if (!isset($_SERVER['REMOTE_ADDR'])) {
-            throw new Horde_Auth_Exception(_("IP address not available."));
+            return false;
         }
 
-        $client = $_SERVER['REMOTE_ADDR'];
         foreach ($this->_params['blocks'] as $cidr) {
-            if ($this->_addressWithinCIDR($client, $cidr)) {
-                return Horde_Auth::setAuth($cidr, array('transparent' => 1));
+            if ($this->_addressWithinCIDR($_SERVER['REMOTE_ADDR'], $cidr)) {
+                $this->_credentials['userId'] = $cidr;
+                return true;
             }
         }
 
-        throw new Horde_Auth_Exception(_("IP address not within allowed CIDR block."));
+        return false;
     }
 
     /**
index 106494f..e2cfea2 100644 (file)
@@ -76,16 +76,15 @@ class Horde_Auth_Shibboleth extends Horde_Auth_Base
     }
 
     /**
-     * Automatic authentication: Check if the username is set in the
+     * Automatic authentication: check if the username is set in the
      * configured header.
      *
      * @return boolean  Whether or not the client is allowed.
-     * @throws Horde_Auth_Exception
      */
     protected function _transparent()
     {
         if (empty($_SERVER[$this->_params['username_header']])) {
-            throw new Horde_Auth_Exception(_("Shibboleth authentication not available."));
+            return false;
         }
 
         $username = $_SERVER[$this->_params['username_header']];
@@ -96,15 +95,20 @@ class Horde_Auth_Shibboleth extends Horde_Auth_Base
             $username = substr($username, 0, $pos);
         }
 
-        if (!Horde_Auth::setAuth($username, array('transparent' => 1))) {
-            return false;
-        }
+        $this->_credentials['userId'] = $username;
 
         // Set password for hordeauth login.
-        if ($this->_params['password_holder'] == 'header') {
-            Horde_Auth::setCredential('password', $_SERVER[$this->_params['password_header']]);
-        } elseif ($this->_params['password_holder'] == 'preferences') {
-            Horde_Auth::setCredential('password', $GLOBALS['prefs']->getValue($this->_params['password_preference']));
+        switch ($this->_params['password_holder']) {
+        case 'header':
+            $this->_credentials['credentials'] = array(
+                'password' => $_SERVER[$this->_params['password_header']]
+            );
+            break;
+
+        case 'preferences':
+            $this->_credentials['credentials'] = array(
+                'password' => $_SERVER[$this->_params['password_preference']]
+            );
         }
 
         return true;