From 4e28face6548c76619a29e529d55313ac6db0a24 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Wed, 1 Dec 2010 14:56:19 +0100
Subject: [PATCH] Remove the use of Horde_Session and access the session
directly. Simplify the factory.
---
.../Core/lib/Horde/Core/Factory/KolabSession.php | 132 ++++-----------------
.../Kolab_Session/lib/Horde/Kolab/Session.php | 23 ++++
.../Kolab_Session/lib/Horde/Kolab/Session/Base.php | 113 +++++++++++-------
.../lib/Horde/Kolab/Session/Decorator/Base.php | 34 +++++-
.../lib/Horde/Kolab/Session/Decorator/Logged.php | 53 ++++++++-
.../lib/Horde/Kolab/Session/Decorator/Stored.php | 57 ++++++---
.../Session/{Storage/Interface.php => Storage.php} | 12 +-
.../lib/Horde/Kolab/Session/Storage/Mock.php | 12 +-
.../lib/Horde/Kolab/Session/Storage/Session.php | 35 ++----
.../Session/{Valid/Interface.php => Valid.php} | 7 +-
.../lib/Horde/Kolab/Session/Valid/Base.php | 9 +-
.../Horde/Kolab/Session/Valid/Decorator/Logged.php | 27 +++--
framework/Kolab_Session/package.xml | 64 +++++-----
.../test/Horde/Kolab/Session/Autoload.php | 15 +--
.../Kolab/Session/Class/Decorator/StoredTest.php | 62 ----------
.../Kolab/Session/Integration/AnonymousTest.php | 2 +-
.../Kolab/Session/Integration/SessionTest.php | 38 ++++++
.../Horde/Kolab/Session/Integration/ValidTest.php | 14 +--
.../Session/{SessionTestCase.php => TestCase.php} | 7 +-
.../Kolab/Session/{Class => Unit}/BaseTest.php | 21 +---
.../{Class => Unit}/Decorator/AnonymousTest.php | 4 +-
.../Session/{Class => Unit}/Decorator/BaseTest.php | 4 +-
.../{Class => Unit}/Decorator/LoggedTest.php | 6 +-
.../Kolab/Session/Unit/Decorator/StoredTest.php | 102 ++++++++++++++++
.../Session/{Class => Unit}/Storage/MockTest.php | 8 +-
.../{Class => Unit}/Storage/SessionTest.php | 29 ++---
.../Session/{Class => Unit}/Valid/BaseTest.php | 14 +--
.../{Class => Unit}/Valid/Decorator/LoggedTest.php | 30 +++--
28 files changed, 532 insertions(+), 402 deletions(-)
rename framework/Kolab_Session/lib/Horde/Kolab/Session/{Storage/Interface.php => Storage.php} (75%)
rename framework/Kolab_Session/lib/Horde/Kolab/Session/{Valid/Interface.php => Valid.php} (87%)
delete mode 100644 framework/Kolab_Session/test/Horde/Kolab/Session/Class/Decorator/StoredTest.php
create mode 100644 framework/Kolab_Session/test/Horde/Kolab/Session/Integration/SessionTest.php
rename framework/Kolab_Session/test/Horde/Kolab/Session/{SessionTestCase.php => TestCase.php} (89%)
rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/BaseTest.php (96%)
rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Decorator/AnonymousTest.php (96%)
rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Decorator/BaseTest.php (97%)
rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Decorator/LoggedTest.php (95%)
create mode 100644 framework/Kolab_Session/test/Horde/Kolab/Session/Unit/Decorator/StoredTest.php
rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Storage/MockTest.php (83%)
rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Storage/SessionTest.php (56%)
rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Valid/BaseTest.php (89%)
rename framework/Kolab_Session/test/Horde/Kolab/Session/{Class => Unit}/Valid/Decorator/LoggedTest.php (67%)
diff --git a/framework/Core/lib/Horde/Core/Factory/KolabSession.php b/framework/Core/lib/Horde/Core/Factory/KolabSession.php
index 5b58d8a0c..81c338f22 100644
--- a/framework/Core/lib/Horde/Core/Factory/KolabSession.php
+++ b/framework/Core/lib/Horde/Core/Factory/KolabSession.php
@@ -42,74 +42,10 @@ class Horde_Core_Factory_KolabSession
public function __construct(
Horde_Injector $injector
) {
- $this->_injector = $injector;
- $this->_setup();
- }
-
- /**
- * Setup the machinery to create Horde_Kolab_Session objects.
- *
- * @return NULL
- */
- private function _setup()
- {
- $this->_setupConfiguration();
- $this->_setupAuth();
- $this->_setupStorage();
- }
-
- /**
- * Provide configuration settings for Horde_Kolab_Session.
- *
- * @return NULL
- */
- private function _setupConfiguration()
- {
- $configuration = array();
- if (!empty($GLOBALS['conf']['kolab']['session'])) {
- $configuration = $GLOBALS['conf']['kolab']['session'];
- }
- $this->_injector->setInstance(
- 'Horde_Kolab_Session_Configuration', $configuration
- );
- }
-
- /**
- * Setup the machinery to create a Horde_Kolab_Session_Auth handler.
- *
- * @return NULL
- */
- private function _setupAuth()
- {
+ $this->_injector = $injector;
$this->_injector->bindImplementation(
- 'Horde_Kolab_Session_Auth_Interface',
- 'Horde_Kolab_Session_Auth_Horde'
- );
- }
-
- /**
- * Setup the machinery to create a Horde_Kolab_Session_Storage handlers.
- *
- * @return NULL
- */
- private function _setupStorage()
- {
- $this->_injector->bindFactory(
- 'Horde_Kolab_Session_Storage_Interface',
- 'Horde_Core_Factory_KolabSession',
- 'getStorage'
- );
- }
-
- /**
- * Return the session storage driver.
- *
- * @return Horde_Kolab_Session_Storage The driver for storing sessions.
- */
- public function getStorage()
- {
- return new Horde_Kolab_Session_Storage_Session(
- $GLOBALS['session']
+ 'Horde_Kolab_Session_Storage',
+ 'Horde_Kolab_Session_Storage_Session'
);
}
@@ -123,17 +59,15 @@ class Horde_Core_Factory_KolabSession
* @return Horde_Kolab_Session_Valid_Interface The driver for validating
* sessions.
*/
- public function getSessionValidator(
+ public function createSessionValidator(
Horde_Kolab_Session $session,
$auth
) {
- $configuration = $this->_injector->getInstance('Horde_Kolab_Session_Configuration');
-
$validator = new Horde_Kolab_Session_Valid_Base(
$session, $auth
);
- if (isset($configuration['debug']) || isset($configuration['log'])) {
+ if (isset($GLOBALS['conf']['kolab']['session']['debug'])) {
$validator = new Horde_Kolab_Session_Valid_Decorator_Logged(
$validator, $this->_injector->getInstance('Horde_Log_Logger')
);
@@ -143,22 +77,6 @@ class Horde_Core_Factory_KolabSession
}
/**
- * Validate the given session.
- *
- * @param Horde_Kolab_Session $session The session to validate.
- *
- * @return boolean True if the given session is valid.
- */
- public function validate(
- Horde_Kolab_Session $session
- ) {
- return $this->getSessionValidator(
- $session,
- $this->_injector->getInstance('Horde_Registry')->getAuth()
- )->isValid();
- }
-
- /**
* Returns a new session handler.
*
* @return Horde_Kolab_Session The concrete Kolab session reference.
@@ -167,15 +85,20 @@ class Horde_Core_Factory_KolabSession
{
$session = new Horde_Kolab_Session_Base(
$this->_injector->getInstance('Horde_Kolab_Server_Composite'),
- $this->_injector->getInstance('Horde_Kolab_Session_Configuration')
+ $GLOBALS['conf']['kolab']['session']
);
- //@todo: Fix validation
- /** If we created a new session handler it needs to be stored once */
+ if (isset($GLOBALS['conf']['kolab']['session']['debug'])) {
+ $session = new Horde_Kolab_Session_Decorator_Logged(
+ $session, $this->_injector->getInstance('Horde_Log_Logger')
+ );
+ }
+
$session = new Horde_Kolab_Session_Decorator_Stored(
$session,
- $this->_injector->getInstance('Horde_Kolab_Session_Storage_Interface')
+ $this->_injector->getInstance('Horde_Kolab_Session_Storage')
);
+
return $session;
}
@@ -186,29 +109,20 @@ class Horde_Core_Factory_KolabSession
*/
public function create()
{
- $storage = $this->_injector->getInstance('Horde_Kolab_Session_Storage_Interface');
- $session = $storage->load();
-
- if (empty($session) || !$this->validate($session)) {
- $session = $this->createSession();
- }
-
- $configuration = $this->_injector->getInstance('Horde_Kolab_Session_Configuration');
+ $session = $this->createSession();
+ $this->createSessionValidator(
+ $session,
+ $this->_injector->getInstance('Horde_Registry')->getAuth()
+ )->validate();
- if (isset($configuration['debug']) || isset($configuration['log'])) {
- $session = new Horde_Kolab_Session_Decorator_Logged(
- $session, $this->_injector->getInstance('Horde_Log_Logger')
- );
- }
-
- if (isset($configuration['anonymous']['user'])
- && isset($configuration['anonymous']['pass'])
+ if (isset($GLOBALS['conf']['kolab']['session']['anonymous']['user'])
+ && isset($GLOBALS['conf']['kolab']['session']['anonymous']['pass'])
) {
$session = new Horde_Kolab_Session_Decorator_Anonymous(
$session,
- $configuration['anonymous']['user'],
- $configuration['anonymous']['pass']
+ $GLOBALS['conf']['kolab']['session']['anonymous']['user'],
+ $GLOBALS['conf']['kolab']['session']['anonymous']['pass']
);
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session.php b/framework/Kolab_Session/lib/Horde/Kolab/Session.php
index 70c3f9c64..271458ce3 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session.php
@@ -89,4 +89,27 @@ interface Horde_Kolab_Session
* @return string The freebusy host for the current user.
*/
public function getFreebusyServer();
+
+ /**
+ * Import the session data from an array.
+ *
+ * @param array The session data.
+ *
+ * @return NULL
+ */
+ public function import(array $session_data);
+
+ /**
+ * Export the session data as array.
+ *
+ * @return array The session data.
+ */
+ public function export();
+
+ /**
+ * Clear the session data.
+ *
+ * @return NULL
+ */
+ public function purge();
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
index 83b17e69a..85c32a6f8 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
@@ -35,6 +35,13 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
private $_params;
/**
+ * The session data.
+ *
+ * @var array
+ */
+ private $_data;
+
+ /**
* User ID.
*
* @var string
@@ -84,13 +91,6 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
private $_server;
/**
- * Mark the session as connected.
- *
- * @var true
- */
- private $_connected = false;
-
- /**
* Constructor.
*
* @param Horde_Kolab_Server $server The connection to the Kolab user
@@ -118,7 +118,7 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
*/
public function connect($user_id = null, array $credentials = null)
{
- $this->_user_id = $user_id;
+ $this->_data['user']['id'] = $user_id;
if (isset($credentials['password'])) {
$password = $credentials['password'];
} else {
@@ -126,7 +126,7 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
}
try {
- $this->_server->connect($this->_user_id, $password);
+ $this->_server->connect($this->_data['user']['id'], $password);
$user_object = $this->_server->objects->fetch();
} catch (Horde_Kolab_Server_Exception_Bindfailed $e) {
throw new Horde_Kolab_Session_Exception_Badlogin('Invalid credentials!', 0, $e);
@@ -139,8 +139,6 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
$this->_initName($user_object);
$this->_initImapServer($user_object);
$this->_initFreebusyServer($user_object);
-
- $this->_connected = true;
}
/**
@@ -154,9 +152,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
Horde_Kolab_Server_Object_Hash $user
) {
try {
- $this->_user_mail = $user->getSingle('mail');;
+ $this->_data['user']['mail'] = $user->getSingle('mail');;
} catch (Horde_Kolab_Server_Exception_Novalue $e) {
- $this->_user_mail = $this->_user_id;
+ $this->_data['user']['mail'] = $this->_data['user']['id'];
}
}
@@ -171,9 +169,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
Horde_Kolab_Server_Object_Hash $user
) {
try {
- $this->_user_uid = $user->getSingle('uid');
+ $this->_data['user']['uid'] = $user->getSingle('uid');
} catch (Horde_Kolab_Server_Exception_Novalue $e) {
- $this->_user_uid = $this->_user_id;
+ $this->_data['user']['uid'] = $this->_data['user']['id'];
}
}
@@ -188,9 +186,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
Horde_Kolab_Server_Object_Hash $user
) {
try {
- $this->_user_name = $user->getSingle('Firstnamelastname');
+ $this->_data['user']['name'] = $user->getSingle('Firstnamelastname');
} catch (Horde_Kolab_Server_Exception_Novalue $e) {
- $this->_user_name = $this->_user_id;
+ $this->_data['user']['name'] = $this->_data['user']['id'];
}
}
@@ -205,12 +203,12 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
Horde_Kolab_Server_Object_Hash $user
) {
try {
- $this->_imap_server = $user->getSingle('kolabHomeServer');
+ $this->_data['imap']['server'] = $user->getSingle('kolabHomeServer');
} catch (Horde_Kolab_Server_Exception_Novalue $e) {
if (isset($this->_params['imap']['server'])) {
- $this->_imap_server = $this->_params['imap']['server'];
+ $this->_data['imap']['server'] = $this->_params['imap']['server'];
} else {
- $this->_imap_server = 'localhost';
+ $this->_data['imap']['server'] = 'localhost';
}
}
}
@@ -229,10 +227,10 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
$fb_server = $user->getSingle('kolabFreebusyHost');
} catch (Horde_Kolab_Server_Exception_Novalue $e) {
if (isset($this->_params['freebusy']['url'])) {
- $this->_freebusy_server = $this->_params['freebusy']['url'];
+ $this->_data['fb']['server'] = $this->_params['freebusy']['url'];
return;
} else {
- $fb_server = $this->_imap_server;
+ $fb_server = $this->_data['imap']['server'];
}
}
@@ -242,20 +240,7 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
$fb_format = 'http://%s/freebusy';
}
- $this->_freebusy_server = sprintf($fb_format, $fb_server);
- }
-
- /**
- * Returns the properties that need to be serialized.
- *
- * @return array List of serializable properties.
- */
- public function __sleep()
- {
- $properties = get_object_vars($this);
- unset($properties['_server']);
- $properties = array_keys($properties);
- return $properties;
+ $this->_data['fb']['server'] = sprintf($fb_format, $fb_server);
}
/**
@@ -265,7 +250,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
*/
public function getId()
{
- return $this->_user_id;
+ if (isset($this->_data['user']['id'])) {
+ return $this->_data['user']['id'];
+ }
}
/**
@@ -275,7 +262,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
*/
public function getMail()
{
- return $this->_user_mail;
+ if (isset($this->_data['user']['mail'])) {
+ return $this->_data['user']['mail'];
+ }
}
/**
@@ -285,7 +274,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
*/
public function getUid()
{
- return $this->_user_uid;
+ if (isset($this->_data['user']['uid'])) {
+ return $this->_data['user']['uid'];
+ }
}
/**
@@ -295,7 +286,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
*/
public function getName()
{
- return $this->_user_name;
+ if (isset($this->_data['user']['name'])) {
+ return $this->_data['user']['name'];
+ }
}
/**
@@ -305,7 +298,9 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
*/
public function getImapServer()
{
- return $this->_imap_server;
+ if (isset($this->_data['imap']['server'])) {
+ return $this->_data['imap']['server'];
+ }
}
/**
@@ -315,6 +310,40 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
*/
public function getFreebusyServer()
{
- return $this->_freebusy_server;
+ if (isset($this->_data['fb']['server'])) {
+ return $this->_data['fb']['server'];
+ }
+ }
+
+ /**
+ * Import the session data from an array.
+ *
+ * @param array The session data.
+ *
+ * @return NULL
+ */
+ public function import(array $session_data)
+ {
+ $this->_data = $session_data;
+ }
+
+ /**
+ * Export the session data as array.
+ *
+ * @return array The session data.
+ */
+ public function export()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * Clear the session data.
+ *
+ * @return NULL
+ */
+ public function purge()
+ {
+ $this->_data = array();
}
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php
index 4570e33e5..763281643 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Base.php
@@ -46,7 +46,7 @@ implements Horde_Kolab_Session
public function __construct(
Horde_Kolab_Session $session
) {
- $this->_session = $session;
+ $this->_session = $session;
}
/**
@@ -124,4 +124,36 @@ implements Horde_Kolab_Session
{
return $this->_session->getFreebusyServer();
}
+
+ /**
+ * Import the session data from an array.
+ *
+ * @param array The session data.
+ *
+ * @return NULL
+ */
+ public function import(array $session_data)
+ {
+ $this->_session->import($session_data);
+ }
+
+ /**
+ * Export the session data as array.
+ *
+ * @return array The session data.
+ */
+ public function export()
+ {
+ return $this->_session->export();
+ }
+
+ /**
+ * Clear the session data.
+ *
+ * @return NULL
+ */
+ public function purge()
+ {
+ $this->_session->purge();
+ }
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php
index 0ba31d610..1c81d961b 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Logged.php
@@ -77,10 +77,61 @@ extends Horde_Kolab_Session_Decorator_Base
$this->_logger->err(
sprintf(
"Failed to connect Kolab session for \"%s\". Error was: %s",
- $this->_session->getId(), $e->getMessage()
+ $this->_session->getMail(), $e->getMessage()
)
);
throw $e;
}
}
+
+ /**
+ * Export the session data as array.
+ *
+ * @return array The session data.
+ */
+ public function export()
+ {
+ $session_data = $this->_session->export();
+ $this->_logger->info(
+ sprintf(
+ "Exported session data for \"%s\" (%s). [%s]",
+ $this->_session->getMail(), serialize($session_data), new Horde_Support_Backtrace()
+ )
+ );
+ return $session_data;
+ }
+
+ /**
+ * Import the session data from an array.
+ *
+ * @param array The session data.
+ *
+ * @return NULL
+ */
+ public function import(array $session_data)
+ {
+ $this->_session->import($session_data);
+ $this->_logger->info(
+ sprintf(
+ "Imported session data for \"%s\" (%s). [%s]",
+ $this->_session->getMail(), serialize($session_data), new Horde_Support_Backtrace()
+ )
+ );
+ }
+
+ /**
+ * Clear the session data.
+ *
+ * @return NULL
+ */
+ public function purge()
+ {
+ $this->_logger->warn(
+ sprintf(
+ "Purged session data for \"%s\". [%s]",
+ $this->_session->getMail(), new Horde_Support_Backtrace()
+ )
+ );
+ $this->_session->purge();
+ }
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php
index ee6e656e1..be049c5b5 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Decorator/Stored.php
@@ -36,11 +36,11 @@ extends Horde_Kolab_Session_Decorator_Base
private $_storage;
/**
- * Has the storage been connected successfully?
+ * Has the session information changed?
*
* @var boolean
*/
- private $_connected = false;
+ private $_modified = false;
/**
* Constructor.
@@ -50,20 +50,12 @@ extends Horde_Kolab_Session_Decorator_Base
*/
public function __construct(
Horde_Kolab_Session $session,
- Horde_Kolab_Session_Storage_Interface $storage
+ Horde_Kolab_Session_Storage $storage
) {
parent::__construct($session);
$this->_storage = $storage;
- }
-
- /**
- * Destructor.
- *
- * Save the session in the storage on shutdown.
- */
- public function __destruct()
- {
- $this->_storage->save($this->_session);
+ $this->_session->import($this->_storage->load());
+ register_shutdown_function(array($this, 'shutdown'));
}
/**
@@ -74,10 +66,47 @@ extends Horde_Kolab_Session_Decorator_Base
* this must contain a "password" entry.
*
* @return NULL
+ *
+ * @throws Horde_Kolab_Session_Exception If the connection failed.
*/
public function connect($user_id = null, array $credentials = null)
{
$this->_session->connect($user_id, $credentials);
- $this->_connected = true;
+ $this->_modified = $this->_session->export();
+ }
+
+ /**
+ * Import the session data from an array.
+ *
+ * @param array The session data.
+ *
+ * @return NULL
+ */
+ public function import(array $session_data)
+ {
+ throw new Horde_Kolab_Session_Exception('Data import of stored session data is handled via the session.');
+ }
+
+ /**
+ * Clear the session data.
+ *
+ * @return NULL
+ */
+ public function purge()
+ {
+ $this->_session->purge();
+ $this->_modified = array();
+ }
+
+ /**
+ * Write any modified data to the session.
+ *
+ * @return NULL
+ */
+ public function shutdown()
+ {
+ if ($this->_modified !== false) {
+ $this->_storage->save($this->_modified);
+ }
}
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Interface.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php
similarity index 75%
rename from framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Interface.php
rename to framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php
index e27adb092..f7d6098d0 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Interface.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage.php
@@ -25,22 +25,22 @@
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Session
*/
-interface Horde_Kolab_Session_Storage_Interface
+interface Horde_Kolab_Session_Storage
{
/**
* Load the session information.
*
- * @return Horde_Kolab_Session|boolean The session information or false if
- * it could not be loaded.
+ * @return array The session data or an empty array if no information was
+ * found.
*/
public function load();
/**
- * Lave the session information.
+ * Save the session information.
*
- * @param Horde_Kolab_Session $session The session information.
+ * @param array $session_data The session data that should be stored.
*
* @return NULL
*/
- public function save(Horde_Kolab_Session $session);
+ public function save(array $session_data);
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php
index bdaea3f93..a133f6bfc 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Mock.php
@@ -26,7 +26,7 @@
* @link http://pear.horde.org/index.php?package=Kolab_Session
*/
class Horde_Kolab_Session_Storage_Mock
-implements Horde_Kolab_Session_Storage_Interface
+implements Horde_Kolab_Session_Storage
{
/**
* The session information.
@@ -36,8 +36,8 @@ implements Horde_Kolab_Session_Storage_Interface
/**
* Load the session information.
*
- * @return Horde_Kolab_Session|boolean The session information or false if
- * it could not be loaded.
+ * @return array The session data or an empty array if no information was
+ * found.
*/
public function load()
{
@@ -47,12 +47,12 @@ implements Horde_Kolab_Session_Storage_Interface
/**
* Save the session information.
*
- * @param Horde_Kolab_Session $session The session information.
+ * @param array $session_data The session data that should be stored.
*
* @return NULL
*/
- public function save(Horde_Kolab_Session $session)
+ public function save(array $session_data)
{
- $this->session = $session;
+ $this->session = $session_data;
}
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.php
index 1e2be1ddf..997b6d417 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Storage/Session.php
@@ -26,45 +26,32 @@
* @link http://pear.horde.org/index.php?package=Kolab_Session
*/
class Horde_Kolab_Session_Storage_Session
-implements Horde_Kolab_Session_Storage_Interface
+implements Horde_Kolab_Session_Storage
{
/**
- * The handler for session objects.
- *
- * @var array
- */
- private $_session;
-
- /**
- * Constructor
- *
- * @param array $session The session handler.
- */
- public function __construct($session)
- {
- $this->_session = $session;
- }
-
- /**
* Load the session information.
*
- * @return Horde_Kolab_Session|boolean The session information or false if
- * it could not be loaded.
+ * @return array The session data or an empty array if no information was
+ * found.
*/
public function load()
{
- return $this->_session->get('horde', 'kolab_session');
+ if (isset($_SESSION['kolab_session'])) {
+ return $_SESSION['kolab_session'];
+ } else {
+ return array();
+ }
}
/**
* Save the session information.
*
- * @param Horde_Kolab_Session $session The session information.
+ * @param array $session_data The session data that should be stored.
*
* @return NULL
*/
- public function save(Horde_Kolab_Session $session)
+ public function save(array $session_data)
{
- $this->_session->set('horde', 'kolab_session', $session);
+ $_SESSION['kolab_session'] = $session_data;
}
}
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Interface.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php
similarity index 87%
rename from framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Interface.php
rename to framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php
index 8c2d6d7fc..6aef36546 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Interface.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid.php
@@ -25,10 +25,11 @@
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Session
*/
-interface Horde_Kolab_Session_Valid_Interface
+interface Horde_Kolab_Session_Valid
{
/**
- * Does the current session still match the authentication information?
+ * Reset the current session information in case it does not match the
+ * authentication information anymore.
*
* @param string $user The user the session information is being requested
* for. This is usually empty, indicating the current
@@ -36,7 +37,7 @@ interface Horde_Kolab_Session_Valid_Interface
*
* @return boolean True if the session is still valid.
*/
- public function isValid($user = null);
+ public function validate($user = null);
/**
* Return the session this validator checks.
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php
index 10feaa048..20a9fda8e 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Base.php
@@ -26,7 +26,7 @@
* @link http://pear.horde.org/index.php?package=Kolab_Session
*/
class Horde_Kolab_Session_Valid_Base
-implements Horde_Kolab_Session_Valid_Interface
+implements Horde_Kolab_Session_Valid
{
/**
* The session handler this instance provides with anonymous access.
@@ -58,7 +58,8 @@ implements Horde_Kolab_Session_Valid_Interface
}
/**
- * Does the current session still match the authentication information?
+ * Reset the current session information in case it does not match the
+ * authentication information anymore.
*
* @param string $user The user the session information is being requested
* for. This is usually empty, indicating the current
@@ -66,16 +67,18 @@ implements Horde_Kolab_Session_Valid_Interface
*
* @return boolean True if the session is still valid.
*/
- public function isValid($user = null)
+ public function validate($user = null)
{
$mail = $this->_session->getMail();
if ($this->_auth != $mail) {
+ $this->_session->purge();
return false;
}
if (empty($user)) {
return true;
}
if ($user != $mail && $user != $this->_session->getUid()) {
+ $this->_session->purge();
return false;
}
return true;
diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php
index 08a1971af..ea9f620b3 100644
--- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php
+++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Valid/Decorator/Logged.php
@@ -26,7 +26,7 @@
* @link http://pear.horde.org/index.php?package=Kolab_Session
*/
class Horde_Kolab_Session_Valid_Decorator_Logged
-implements Horde_Kolab_Session_Valid_Interface
+implements Horde_Kolab_Session_Valid
{
/**
* The valid handler.
@@ -52,7 +52,7 @@ implements Horde_Kolab_Session_Valid_Interface
* @param mixed $logger The logger instance.
*/
public function __construct(
- Horde_Kolab_Session_Valid_Interface $valid,
+ Horde_Kolab_Session_Valid $valid,
$logger
) {
$this->_valid = $valid;
@@ -60,7 +60,8 @@ implements Horde_Kolab_Session_Valid_Interface
}
/**
- * Does the current session still match the authentication information?
+ * Reset the current session information in case it does not match the
+ * authentication information anymore.
*
* @param string $user The user the session information is being requested
* for. This is usually empty, indicating the current
@@ -68,17 +69,25 @@ implements Horde_Kolab_Session_Valid_Interface
*
* @return boolean True if the session is still valid.
*/
- public function isValid($user = null)
+ public function validate($user = null)
{
- $result = $this->_valid->isValid($user);
+ $this->_logger->info(
+ sprintf(
+ "Validating Kolab session for current user \"%s\", requested"
+ . " user \"%s\", and stored user \"%s\".",
+ $this->_valid->getAuth(),
+ $user,
+ $this->_valid->getSession()->getMail()
+ )
+ );
+ $result = $this->_valid->validate($user);
if ($result === false) {
$this->_logger->info(
sprintf(
- "Invalid Kolab session for current user \"%s\", requested"
- . " user \"%s\" and stored user \"%s\".",
+ "Invalid Kolab session for current user \"%s\" and requested"
+ . " user \"%s\".",
$this->_valid->getAuth(),
- $user,
- $this->_valid->getSession()->getMail()
+ $user
)
);
}
diff --git a/framework/Kolab_Session/package.xml b/framework/Kolab_Session/package.xml
index c02fceb36..e11eb8511 100644
--- a/framework/Kolab_Session/package.xml
+++ b/framework/Kolab_Session/package.xml
@@ -1,5 +1,5 @@
-