Skip to content
Snippets Groups Projects
Commit 0f6687a9 authored by Olav Morken's avatar Olav Morken
Browse files

Session: Serialize and save session manually.

This should fix the problem with session_start() requiring the
SimpleSAML_Session class to be loaded.


git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@571 44740490-163a-0410-bde0-09ae8108e29a
parent fa514b8a
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSA ...@@ -4,7 +4,6 @@ require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSA
require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Utilities.php'); require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Utilities.php');
require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/SessionHandler.php'); require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/SessionHandler.php');
require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Logger.php'); require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Logger.php');
require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/ModifiedInfo.php');
/** /**
* The Session class holds information about a user session, and everything attached to it. * The Session class holds information about a user session, and everything attached to it.
...@@ -18,7 +17,7 @@ require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSA ...@@ -18,7 +17,7 @@ require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSA
* @package simpleSAMLphp * @package simpleSAMLphp
* @version $Id$ * @version $Id$
*/ */
class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { class SimpleSAML_Session {
const STATE_ONLINE = 1; const STATE_ONLINE = 1;
const STATE_LOGOUTINPROGRESS = 2; const STATE_LOGOUTINPROGRESS = 2;
...@@ -91,6 +90,7 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { ...@@ -91,6 +90,7 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo {
$this->trackid = SimpleSAML_Utilities::generateTrackID(); $this->trackid = SimpleSAML_Utilities::generateTrackID();
$this->dirty = TRUE; $this->dirty = TRUE;
$this->addShutdownFunction();
} }
...@@ -98,7 +98,7 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { ...@@ -98,7 +98,7 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo {
* This function is called after this class has been deserialized. * This function is called after this class has been deserialized.
*/ */
public function __wakeup() { public function __wakeup() {
$this->addShutdownFunction();
} }
...@@ -118,10 +118,8 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { ...@@ -118,10 +118,8 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo {
/* Check if we have stored a session stored with the session /* Check if we have stored a session stored with the session
* handler. * handler.
*/ */
$sh = SimpleSAML_SessionHandler::getSessionHandler(); self::$instance = self::loadSession();
if($sh->get('SimpleSAMLphp_SESSION') !== NULL) { if(self::$instance !== NULL) {
self::$instance = $sh->get('SimpleSAMLphp_SESSION');
self::$instance->dirty = false;
return self::$instance; return self::$instance;
} }
...@@ -484,13 +482,6 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { ...@@ -484,13 +482,6 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo {
$this->sp_at_idpsessions = array(); $this->sp_at_idpsessions = array();
} }
/**
* Is this session modified since loaded?
*/
public function isModified() {
return $this->dirty;
}
/** /**
* Calculates the size of the session object after serialization * Calculates the size of the session object after serialization
* *
...@@ -635,6 +626,62 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { ...@@ -635,6 +626,62 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo {
return $dataInfo['data']; return $dataInfo['data'];
} }
/**
* Load a session from the session handler.
*
* @return The session which is stored in the session handler, or NULL if the session wasn't found.
*/
private static function loadSession() {
$sh = SimpleSAML_SessionHandler::getSessionHandler();
$sessionData = $sh->get('SimpleSAMLphp_SESSION');
if($sessionData == NULL) {
return NULL;
}
if(!is_string($sessionData)) {
return NULL;
}
$sessionData = unserialize($sessionData);
if(!($sessionData instanceof self)) {
SimpleSAML_Logger::warning('Retrieved and deserialized session data was not a session.');
return NULL;
}
return $sessionData;
}
/**
* Save the session to the session handler.
*
* This function will check the dirty-flag to check if the session has changed.
*/
public function saveSession() {
if(!$this->dirty) {
/* Session hasn't changed - don't bother saving it. */
return;
}
$this->dirty = FALSE;
$sessionData = serialize($this);
$sh = SimpleSAML_SessionHandler::getSessionHandler();
$sh->set('SimpleSAMLphp_SESSION', $sessionData);
}
/**
* Add a shutdown function for saving this session object on exit.
*/
private function addShutdownFunction() {
register_shutdown_function(array($this, 'saveSession'));
}
} }
?> ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment