From 9834b4b94cfdcef0435ac166a631c68a7c2be1b1 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Mon, 9 Aug 2010 08:52:00 +0000 Subject: [PATCH] SessionHandler: Support loading a specific session. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2497 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/SessionHandler.php | 3 ++- lib/SimpleSAML/SessionHandlerPHP.php | 8 +++++++- lib/SimpleSAML/SessionHandlerStore.php | 10 ++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/SimpleSAML/SessionHandler.php b/lib/SimpleSAML/SessionHandler.php index c16d50618..363ce2098 100644 --- a/lib/SimpleSAML/SessionHandler.php +++ b/lib/SimpleSAML/SessionHandler.php @@ -66,9 +66,10 @@ abstract class SimpleSAML_SessionHandler { /** * Load the session. * + * @param string|NULL $sessionId The ID of the session we should load, or NULL to use the default. * @return SimpleSAML_Session|NULL The session object, or NULL if it doesn't exist. */ - abstract public function loadSession(); + abstract public function loadSession($sessionId = NULL); /** diff --git a/lib/SimpleSAML/SessionHandlerPHP.php b/lib/SimpleSAML/SessionHandlerPHP.php index f2009bdf9..c6c029ef0 100644 --- a/lib/SimpleSAML/SessionHandlerPHP.php +++ b/lib/SimpleSAML/SessionHandlerPHP.php @@ -89,9 +89,15 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler { /** * Load the session from the PHP session array. * + * @param string|NULL $sessionId The ID of the session we should load, or NULL to use the default. * @return SimpleSAML_Session|NULL The session object, or NULL if it doesn't exist. */ - public function loadSession() { + public function loadSession($sessionId = NULL) { + assert('is_string($sessionId) || is_null($sessionId)'); + + if ($sessionId !== NULL && $sessionId !== session_id()) { + throw new SimpleSAML_Error_Exception('Cannot load PHP session with a specific ID.'); + } if (!isset($_SESSION['SimpleSAMLphp_SESSION'])) { return NULL; diff --git a/lib/SimpleSAML/SessionHandlerStore.php b/lib/SimpleSAML/SessionHandlerStore.php index 725e71943..81be78ddc 100644 --- a/lib/SimpleSAML/SessionHandlerStore.php +++ b/lib/SimpleSAML/SessionHandlerStore.php @@ -26,11 +26,17 @@ class SimpleSAML_SessionHandlerStore extends SimpleSAML_SessionHandlerCookie { /** * Load the session from the datastore. * + * @param string|NULL $sessionId The ID of the session we should load, or NULL to use the default. * @return SimpleSAML_Session|NULL The session object, or NULL if it doesn't exist. */ - public function loadSession() { + public function loadSession($sessionId = NULL) { + assert('is_string($sessionId) || is_null($sessionId)'); - $session = $this->store->get('session', $this->session_id); + if ($sessionId === NULL) { + $sessionId = $this->session_id; + } + + $session = $this->store->get('session', $sessionId); if ($session !== NULL) { assert('$session instanceof SimpleSAML_Session'); return $session; -- GitLab