From: Ben Klang Date: Sun, 3 Oct 2010 18:07:32 +0000 (-0400) Subject: Storing session information in LDAP is a *bad* idea. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1572653273b58673fccbfd4baddbbeab8ea3ad6e;p=horde.git Storing session information in LDAP is a *bad* idea. --- diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Ldap.php b/framework/SessionHandler/lib/Horde/SessionHandler/Ldap.php deleted file mode 100644 index f56563996..000000000 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Ldap.php +++ /dev/null @@ -1,173 +0,0 @@ - - * 'dn' - (string) [REQUIRED] TODO - * 'ldap' - (Horde_Ldap) [REQUIRED] The Horde_Ldap object. - * - * - * @throws InvalidArgumentException - */ - public function __construct(array $params = array()) - { - foreach (array('dn', 'ldap') as $val) { - if (!isset($params[$val])) { - throw new InvalidArgumentException('Missing ' . $val . ' parameter.'); - } - } - - $this->_ldap = $params['ldap']; - unset($params['ldap']); - - parent::__construct($params); - } - - /** - * Open the backend. - * - * @param string $save_path The path to the session object. - * @param string $session_name The name of the session. - * - * @throws Horde_SessionHandler_Exception - */ - protected function _open($save_path = null, $session_name = null) - { - try { - $this->_ldap->bind(); - } catch (Horde_Ldap_Exception $e) { - throw new Horde_SessionHandler_Exception($e); - } - } - - /** - * Close the backend. - */ - protected function _close() - { - $this->_ldap->disconnect(); - } - - /** - * Read the data for a particular session identifier from the backend. - * - * @param string $id The session identifier. - * - * @return string The session data. - */ - protected function _read($id) - { - try { - $result = $this->_ldap->search(null, "(cn=$id)"); - if ($result->count()) { - $entry = reset(); - return $entry['session'][0]; - } - } catch (Horde_Ldap_Exception $e) { - if ($this->_logger) { - $this->_logger->log($e, 'ERR'); - } - } - - return ''; - } - - /** - * Write session data to the backend. - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. - */ - protected function _write($id, $session_data) - { - $update = array( - 'objectClass' => array('phpsession', 'top'), - 'session' => $session_data - ); - $dn = "cn=$id," . $this->_params['dn']; - - $this->_ldap->delete($dn); - - return $this->_ldap->add(Horde_Ldap_Entry::createFresh($dn, $update)); - } - - /** - * Destroy the data for a particular session identifier in the backend. - * - * @param string $id The session identifier. - * - * @return boolean True on success, false otherwise. - */ - public function destroy($id) - { - $dn = "cn=$id," . $this->_params['dn']; - - return $this->_ldap->delete($dn); - } - - /** - * Garbage collect stale sessions from the backend. - * - * @param integer $maxlifetime The maximum age of a session. - * - * @return boolean True on success, false otherwise. - */ - public function gc($maxlifetime = 300) - { - $info = $this->_ldap->search(null, '(objectClass=phpsession)', array('attributes' => array('+', 'cn'))); - - foreach ($info as $val) { - $id = $val['cn'][0]; - $dn = "cn=$id," . $this->_params['dn']; - $ldapstamp = $val['modifytimestamp'][0]; - $year = substr($ldapstamp, 0, 4); - $month = substr($ldapstamp, 4, 2); - $day = substr($ldapstamp, 6, 2); - $hour = substr($ldapstamp, 8, 2); - $minute = substr($ldapstamp, 10, 2); - $modified = gmmktime($hour, $minute, 0, $month, $day, $year); - if (time() - $modified >= $maxlifetime) { - $this->_ldap->delete($dn); - } - } - - return true; - } - - /** - * Get a list of the valid session identifiers. - * - * @throws Horde_SessionHandler_Exception - */ - public function getSessionIDs() - { - throw new Horde_SessionHandler_Exception('Driver does not support listing session IDs.'); - } - -}