Pass info to preauth hook to indicate the current auth method
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 15 Oct 2009 10:12:38 +0000 (04:12 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 15 Oct 2009 10:12:38 +0000 (04:12 -0600)
framework/Auth/lib/Horde/Auth.php
framework/Auth/lib/Horde/Auth/Base.php
framework/Auth/lib/Horde/Auth/Ldap.php
framework/Auth/lib/Horde/Auth/Msad.php

index def64d6..ab387f4 100644 (file)
@@ -870,14 +870,22 @@ class Horde_Auth
      * @param string $app         The app currently being authenticated.
      * @param string $type        Either 'preauthenticate' or
      *                            'postauthenticate'.
+     * @param string $method      The triggering method (preauthenticate only).
+     *                            Either 'authenticate', 'transparent', or
+     *                            'admin'
      *
      * @return array  Two element array, $userId and $credentials.
      * @throws Horde_Auth_Exception
      */
-    static public function runHook($userId, $credentials, $app, $type)
+    static public function runHook($userId, $credentials, $app, $type,
+                                   $method = null)
     {
         $ret_array = array($userId, $credentials);
 
+        if ($type == 'preauthenticate') {
+            $credentials['authMethod'] = $method;
+        }
+
         try {
             $result = Horde::callHook($type, array($userId, $credentials), $app);
         } catch (Horde_Exception $e) {
@@ -886,6 +894,8 @@ class Horde_Auth
             return $ret_array;
         }
 
+        unset($credentials['authMethod']);
+
         if ($result === false) {
             if (self::getAuthError() != self::REASON_MESSAGE) {
                 self::setAuthError(self::REASON_FAILED);
index 9e8a547..db40fc7 100644 (file)
@@ -84,7 +84,7 @@ abstract class Horde_Auth_Base
         $userId = trim($userId);
 
         try {
-            list($userId, $credentials) = Horde_Auth::runHook($userId, $credentials, $this->_app, 'preauthenticate');
+            list($userId, $credentials) = Horde_Auth::runHook($userId, $credentials, $this->_app, 'preauthenticate', 'authenticate');
          } catch (Horde_Auth_Exception $e) {
             return false;
         }
@@ -214,7 +214,7 @@ abstract class Horde_Auth_Base
             ? Horde_Auth::getCredential()
             : $this->_credentials['credentials'];
 
-        list($this->_credentials['userId'], $this->_credentials['credentials']) = Horde_Auth::runHook($userId, $credentials, $this->_app, 'preauthenticate');
+        list($this->_credentials['userId'], $this->_credentials['credentials']) = Horde_Auth::runHook($userId, $credentials, $this->_app, 'preauthenticate', 'transparent');
         $this->_credentials['params']['app'] = $this->_app;
 
         if ($this->_transparent()) {
index c7b9567..f6a23fe 100644 (file)
@@ -325,7 +325,7 @@ class Horde_Auth_Ldap extends Horde_Auth_Base
         /* Connect to the LDAP server. */
         $this->_connect();
 
-        list($userId, $credentials) = Horde_Auth::runHook($userId, $credentials, $this->_app, 'preauthenticate');
+        list($userId, $credentials) = Horde_Auth::runHook($userId, $credentials, $this->_app, 'preauthenticate', 'admin');
         if (isset($credentials['ldap'])) {
             $entry = $credentials['ldap'];
             $dn = $entry['dn'];
@@ -380,7 +380,7 @@ class Horde_Auth_Ldap extends Horde_Auth_Base
         /* Connect to the LDAP server. */
         $this->_connect();
 
-        list($userId, $credentials) = Horde_Auth::runHook($userId, array(), $this->_app, 'preauthenticate');
+        list($userId, $credentials) = Horde_Auth::runHook($userId, array(), $this->_app, 'preauthenticate', 'admin');
         if (isset($credentials['ldap'])) {
             $dn = $credentials['ldap']['dn'];
         } else {
@@ -416,10 +416,10 @@ class Horde_Auth_Ldap extends Horde_Auth_Base
         /* Connect to the LDAP server. */
         $this->_connect();
 
-        list($oldID, $old_credentials) = Horde_Auth::runHook($oldID, $credentials, $this->_app, 'preauthenticate');
+        list($oldID, $old_credentials) = Horde_Auth::runHook($oldID, $credentials, $this->_app, 'preauthenticate', 'admin');
         if (isset($old_credentials['ldap'])) {
             $olddn = $old_credentials['ldap']['dn'];
-            list($newID, $new_credentials) = Horde_Auth::runHook($newID, $credentials, $this->_app, 'preauthenticate');
+            list($newID, $new_credentials) = Horde_Auth::runHook($newID, $credentials, $this->_app, 'preauthenticate', 'admin');
             $newdn = $new_credentials['ldap']['dn'];
             unset($new_credentials['ldap']['dn']);
         } else {
index 47a2782..095b606 100644 (file)
@@ -76,7 +76,7 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap
         /* Connect to the MSAD server. */
         $this->_connect();
 
-        list($accountName, $credentials) = Horde_Auth::runHook($accountName, $credentials, $this->_app, 'preauthenticate');
+        list($accountName, $credentials) = Horde_Auth::runHook($accountName, $credentials, $this->_app, 'preauthenticate', 'admin');
         if (isset($credentials['ldap'])) {
             $dn = $credentials['ldap']['dn'];
         } else {
@@ -132,7 +132,7 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap
         /* Connect to the MSAD server. */
         $this->_connect();
 
-        list($accountName, $credentials) = Horde_Auth::runHook($accountName, $credentials, $this->_app, 'preauthenticate');
+        list($accountName, $credentials) = Horde_Auth::runHook($accountName, $credentials, $this->_app, 'preauthenticate', 'admin');
         if (isset($credentials['ldap'])) {
             $dn = $credentials['ldap']['dn'];
         } else {
@@ -163,7 +163,7 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap
         /* Connect to the MSAD server. */
         $this->_connect();
 
-        list($oldId, $credentials) = Horde_Auth::runHook($oldId, $credentials, $this->_app, 'preauthenticate');
+        list($oldId, $credentials) = Horde_Auth::runHook($oldId, $credentials, $this->_app, 'preauthenticate', 'admin');
         if (isset($credentials['ldap'])) {
             $olddn = $credentials['ldap']['dn'];
         } else {