From 3adefc69a4d90721f92a9d85a2e63ac56c660a12 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 15 Oct 2009 04:12:38 -0600 Subject: [PATCH] Pass info to preauth hook to indicate the current auth method --- framework/Auth/lib/Horde/Auth.php | 12 +++++++++++- framework/Auth/lib/Horde/Auth/Base.php | 4 ++-- framework/Auth/lib/Horde/Auth/Ldap.php | 8 ++++---- framework/Auth/lib/Horde/Auth/Msad.php | 6 +++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/framework/Auth/lib/Horde/Auth.php b/framework/Auth/lib/Horde/Auth.php index def64d68a..ab387f472 100644 --- a/framework/Auth/lib/Horde/Auth.php +++ b/framework/Auth/lib/Horde/Auth.php @@ -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); diff --git a/framework/Auth/lib/Horde/Auth/Base.php b/framework/Auth/lib/Horde/Auth/Base.php index 9e8a547b5..db40fc74b 100644 --- a/framework/Auth/lib/Horde/Auth/Base.php +++ b/framework/Auth/lib/Horde/Auth/Base.php @@ -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()) { diff --git a/framework/Auth/lib/Horde/Auth/Ldap.php b/framework/Auth/lib/Horde/Auth/Ldap.php index c7b9567ef..f6a23fe5b 100644 --- a/framework/Auth/lib/Horde/Auth/Ldap.php +++ b/framework/Auth/lib/Horde/Auth/Ldap.php @@ -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 { diff --git a/framework/Auth/lib/Horde/Auth/Msad.php b/framework/Auth/lib/Horde/Auth/Msad.php index 47a278266..095b60688 100644 --- a/framework/Auth/lib/Horde/Auth/Msad.php +++ b/framework/Auth/lib/Horde/Auth/Msad.php @@ -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 { -- 2.11.0