diff --git a/lib/SimpleSAML/SessionHandler.php b/lib/SimpleSAML/SessionHandler.php index c16d50618fc5bf272ede883bbb901a56d4818d49..363ce209899e64a59fb23f457e11e7e2d63fd279 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 f2009bdf9b710f024bcfdf171a5475bdb30bd97d..c6c029ef06a057741a3f3d52a9dc8aec20f870e7 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 725e719437a577b1ad80f73783f262df407e22a4..81be78ddcf5e86a1d4e48dcae5590c3cfd16a76c 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;