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

Session: Support loading session with a specific id.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2498 44740490-163a-0410-bde0-09ae8108e29a
parent 9834b4b9
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,16 @@ class SimpleSAML_Session {
const DATA_TIMEOUT_LOGOUT = 'logoutTimeout';
/**
* The list of loaded session objects.
*
* This is an associative array indexed with the session id.
*
* @var array
*/
private static $sessions = array();
/**
* This variable holds the instance of the session - Singleton approach.
*/
......@@ -171,7 +181,7 @@ class SimpleSAML_Session {
* handler.
*/
try {
self::$instance = self::loadSession();
self::$instance = self::getSession();
} catch (Exception $e) {
if ($e instanceof SimpleSAML_Error_Exception) {
SimpleSAML_Logger::error('Error loading session:');
......@@ -764,13 +774,27 @@ class SimpleSAML_Session {
/**
* Load a session from the session handler.
*
* @param string|NULL $sessionId The session we should load, or NULL to load the current session.
* @return The session which is stored in the session handler, or NULL if the session wasn't found.
*/
private static function loadSession() {
public static function getSession($sessionId = NULL) {
assert('is_string($sessionId) || is_null($sessionId)');
$sh = SimpleSAML_SessionHandler::getSessionHandler();
$session = $sh->loadSession();
if ($sessionId === NULL) {
$checkToken = TRUE;
$sessionId = $sh->getCookieSessionId();
} else {
$checkToken = FALSE;
}
if (isset(self::$sessions[$sessionId])) {
return self::$sessions[$sessionId];
}
$session = $sh->loadSession($sessionId);
if($session === NULL) {
return NULL;
}
......@@ -782,7 +806,7 @@ class SimpleSAML_Session {
$session->sessionId = $sh->getCookieSessionId();
}
if ($session->authToken !== NULL) {
if ($checkToken && $session->authToken !== NULL) {
if (!isset($_COOKIE['SimpleSAMLAuthToken'])) {
SimpleSAML_Logger::warning('Missing AuthToken cookie.');
return NULL;
......@@ -793,6 +817,8 @@ class SimpleSAML_Session {
}
}
self::$sessions[$sessionId] = $session;
return $session;
}
......
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