From acb441b6682110da94926025e660abd6bbc1abb2 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 31 May 2010 23:50:53 -0600 Subject: [PATCH] Move readSessionData() to horde/Core from horde/Auth --- framework/Auth/lib/Horde/Auth.php | 43 ---------------------- .../Core/lib/Horde/Core/Binder/SessionHandler.php | 42 +++++++++++++++++++++ .../lib/Horde/SessionHandler/Driver.php | 21 ++++++++--- framework/SessionHandler/package.xml | 4 -- 4 files changed, 58 insertions(+), 52 deletions(-) diff --git a/framework/Auth/lib/Horde/Auth.php b/framework/Auth/lib/Horde/Auth.php index 5e522d788..19a041622 100644 --- a/framework/Auth/lib/Horde/Auth.php +++ b/framework/Auth/lib/Horde/Auth.php @@ -897,49 +897,6 @@ class Horde_Auth } /** - * Reads session data to determine if it contains Horde authentication - * credentials. - * - * @param string $session_data The session data. - * @param boolean $info Return session information. The following - * information is returned: userid, - * timestamp, remoteAddr, browser. - * - * @return array An array of the user's sesion information if - * authenticated or false. The following information is - * returned: userid, timestamp, remoteAddr, browser, apps. - */ - static public function readSessionData($session_data) - { - if (empty($session_data) || - (($pos = strpos($session_data, 'horde_auth|')) === false)) { - return false; - } - - $pos += 11; - $endpos = $pos + 1; - - while ($endpos !== false) { - $endpos = strpos($session_data, '|', $endpos); - $data = @unserialize(substr($session_data, $pos, $endpos)); - if (is_array($data)) { - return empty($data) - ? false - : array( - 'apps' => empty($data['app']) ? array('horde') : array_keys($data['app']), - 'browser' => $data['browser'], - 'remoteAddr' => $data['remoteAddr'], - 'timestamp' => $data['timestamp'], - 'userid' => $data['userId'] - ); - } - ++$endpos; - } - - return false; - } - - /** * Sets the error message for an invalid authentication. * * @param string $type The type of error (self::REASON_* constant). diff --git a/framework/Core/lib/Horde/Core/Binder/SessionHandler.php b/framework/Core/lib/Horde/Core/Binder/SessionHandler.php index d3dbf6d79..0e017f0aa 100644 --- a/framework/Core/lib/Horde/Core/Binder/SessionHandler.php +++ b/framework/Core/lib/Horde/Core/Binder/SessionHandler.php @@ -53,6 +53,7 @@ class Horde_Core_Binder_SessionHandler implements Horde_Injector_Binder } $params['logger'] = $logger; + $params['parse'] = array($this, 'readSessionData'); return Horde_SessionHandler::factory($driver, $params); } @@ -61,4 +62,45 @@ class Horde_Core_Binder_SessionHandler implements Horde_Injector_Binder { return false; } + + /** + * Reads session data to determine if it contains Horde authentication + * credentials. + * + * @param string $session_data The session data. + * + * @return array An array of the user's sesion information if + * authenticated or false. The following information is + * returned: userid, timestamp, remoteAddr, browser, apps. + */ + public function readSessionData($session_data) + { + if (empty($session_data) || + (($pos = strpos($session_data, 'horde_auth|')) === false)) { + return false; + } + + $pos += 11; + $endpos = $pos + 1; + + while ($endpos !== false) { + $endpos = strpos($session_data, '|', $endpos); + $data = @unserialize(substr($session_data, $pos, $endpos)); + if (is_array($data)) { + return empty($data) + ? false + : array( + 'apps' => empty($data['app']) ? array('horde') : array_keys($data['app']), + 'browser' => $data['browser'], + 'remoteAddr' => $data['remoteAddr'], + 'timestamp' => $data['timestamp'], + 'userid' => $data['userId'] + ); + } + ++$endpos; + } + + return false; + } + } diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Driver.php b/framework/SessionHandler/lib/Horde/SessionHandler/Driver.php index fa78adc0b..04bb04189 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Driver.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Driver.php @@ -65,6 +65,11 @@ abstract class Horde_SessionHandler_Driver * DEFAULT: No logging * 'noset' - (boolean) If true, don't set the save handler. * DEFAULT: false + * 'parse' - (callback) A callback function that parses session + * information into an array. Is passed the raw session data + * as the only argument; expects either false or an array of + * session data as a return. + * DEFAULT: No * */ public function __construct(array $params = array()) @@ -293,23 +298,29 @@ abstract class Horde_SessionHandler_Driver * Returns a list of authenticated users and data about their session. * * @return array For authenticated users, the sessionid as a key and the - * information returned from Horde_Auth::readSessionData() - * as values. + * session information as value. If no parsing function + * was provided, will always return an empty array. * @throws Horde_SessionHandler_Exception */ public function getSessionsInfo() { - $sessions = $this->getSessionIDs(); - $info = array(); + if (empty($this->_params['parse']) || + !is_callable($this->_params['parse'])) { + return $info; + } + + $sessions = $this->getSessionIDs(); + foreach ($sessions as $id) { try { $data = $this->_readOnly($id); } catch (Horde_SessionHandler_Exception $e) { continue; } - $data = Horde_Auth::readSessionData($data, true); + + $data = call_user_func($this->_params['parse'], $data); if ($data !== false) { $info[$id] = $data; } diff --git a/framework/SessionHandler/package.xml b/framework/SessionHandler/package.xml index 2e5d5e135..2caac1bab 100644 --- a/framework/SessionHandler/package.xml +++ b/framework/SessionHandler/package.xml @@ -78,10 +78,6 @@ - Auth - pear.horde.org - - Db pear.horde.org -- 2.11.0