From b9e02004f2d14b4b11355db3cf94fbf770f4fd3a Mon Sep 17 00:00:00 2001
From: Jaime Perez <jaime.perez@uninett.no>
Date: Tue, 8 Jul 2014 15:02:11 +0200
Subject: [PATCH] Rename SimpleSAML_Session::getInstance() to
 SimpleSAML_Session::getSessionFromRequest(), and leave the former as
 deprecated.

---
 bin/pack.php                                       |  2 +-
 docs/simplesamlphp-sp-migration.txt                |  2 +-
 lib/SimpleSAML/Auth/BWC.php                        |  4 ++--
 lib/SimpleSAML/Auth/Default.php                    |  8 ++++----
 lib/SimpleSAML/Auth/Simple.php                     | 12 ++++++------
 lib/SimpleSAML/Auth/Source.php                     |  6 +++---
 lib/SimpleSAML/Auth/State.php                      |  6 +++---
 lib/SimpleSAML/Error/Error.php                     |  4 ++--
 lib/SimpleSAML/IdP.php                             | 10 +++++-----
 lib/SimpleSAML/Logger.php                          |  2 +-
 lib/SimpleSAML/Session.php                         | 13 +++++++++++--
 lib/SimpleSAML/Utilities.php                       |  8 ++++----
 lib/SimpleSAML/XHTML/IdPDisco.php                  |  2 +-
 modules/InfoCard/www/getcardform.php               |  2 +-
 modules/InfoCard/www/login-infocard.php            |  2 +-
 modules/core/lib/Auth/Process/ExtendIdPSession.php |  2 +-
 modules/core/www/bwc_resumeauth.php                |  2 +-
 modules/core/www/frontpage_auth.php                |  2 +-
 modules/core/www/frontpage_config.php              |  2 +-
 modules/core/www/frontpage_federation.php          |  2 +-
 modules/core/www/frontpage_welcome.php             |  2 +-
 modules/core/www/idp/resumeauth.php                |  2 +-
 modules/core/www/postredirect.php                  |  2 +-
 modules/core/www/show_metadata.php                 |  2 +-
 modules/cron/www/croninfo.php                      |  2 +-
 modules/logpeek/www/index.php                      |  2 +-
 modules/metaedit/www/xmlimport.php                 |  2 +-
 modules/multiauth/lib/Auth/Source/MultiAuth.php    |  4 ++--
 modules/negotiate/lib/Auth/Source/Negotiate.php    |  4 ++--
 modules/negotiate/www/disable.php                  |  2 +-
 modules/negotiate/www/enable.php                   |  2 +-
 modules/negotiate/www/retry.php                    |  2 +-
 modules/oauth/bin/demo.php                         |  2 +-
 modules/oauth/www/authorize.php                    |  2 +-
 modules/oauth/www/registry.edit.php                |  2 +-
 modules/oauth/www/registry.php                     |  2 +-
 modules/openid/lib/SessionStore.php                |  6 +++---
 modules/saml/lib/Auth/Source/SP.php                |  4 ++--
 modules/saml/lib/IdP/SAML2.php                     |  2 +-
 modules/saml/lib/SP/LogoutStore.php                |  2 +-
 modules/saml/www/sp/saml2-acs.php                  |  2 +-
 modules/statistics/www/showstats.php               |  2 +-
 www/auth/login-admin.php                           |  2 +-
 www/auth/login-cas-ldap.php                        |  2 +-
 www/auth/login-ldapmulti.php                       |  2 +-
 www/auth/login-radius.php                          |  2 +-
 www/auth/login-tlsclient.php                       |  2 +-
 www/auth/login-wayf-ldap.php                       |  2 +-
 www/auth/login.php                                 |  2 +-
 www/authmemcookie.php                              |  2 +-
 www/errorreport.php                                |  2 +-
 www/example-simple/attributequery.php              |  2 +-
 www/example-simple/hostnames.php                   |  2 +-
 www/example-simple/saml2-example.php               |  2 +-
 www/example-simple/shib13-example.php              |  2 +-
 www/example-simple/wsfed-example.php               |  2 +-
 www/saml2/sp/AssertionConsumerService.php          |  2 +-
 www/saml2/sp/SingleLogoutService.php               |  2 +-
 www/saml2/sp/initSLO.php                           |  2 +-
 www/saml2/sp/initSSO.php                           |  2 +-
 www/shib13/sp/AssertionConsumerService.php         |  2 +-
 www/shib13/sp/initSSO.php                          |  2 +-
 www/wsfed/sp/initSLO.php                           |  2 +-
 www/wsfed/sp/prp.php                               |  2 +-
 64 files changed, 100 insertions(+), 91 deletions(-)

diff --git a/bin/pack.php b/bin/pack.php
index f69cafbdf..3328cf20d 100755
--- a/bin/pack.php
+++ b/bin/pack.php
@@ -12,7 +12,7 @@ if (count($argv) < 1) {
 }
 
 // Needed in order to make session_start to be called before output is printed.
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $config = SimpleSAML_Configuration::getConfig('config.php');
 
 
diff --git a/docs/simplesamlphp-sp-migration.txt b/docs/simplesamlphp-sp-migration.txt
index 7b425e0e0..0e4481b96 100644
--- a/docs/simplesamlphp-sp-migration.txt
+++ b/docs/simplesamlphp-sp-migration.txt
@@ -155,7 +155,7 @@ This is a quick overview of the API:
 Generally, if you have:
 
     $config = SimpleSAML_Configuration::getInstance();
-    $session = SimpleSAML_Session::getInstance();
+    $session = SimpleSAML_Session::getSessionFromRequest();
 
 you should replace it with this single line:
 
diff --git a/lib/SimpleSAML/Auth/BWC.php b/lib/SimpleSAML/Auth/BWC.php
index 3cdddf584..f66203fce 100644
--- a/lib/SimpleSAML/Auth/BWC.php
+++ b/lib/SimpleSAML/Auth/BWC.php
@@ -101,7 +101,7 @@ class SimpleSAML_Auth_BWC extends SimpleSAML_Auth_Simple {
 			$params['ReturnTo'] = SimpleSAML_Utilities::createPostRedirectLink($params['ReturnTo'], $_POST);
 		}
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 
 		$authnRequest = array(
 			'IsPassive' => isset($params['isPassive']) ? $params['isPassive'] : FALSE,
@@ -152,7 +152,7 @@ class SimpleSAML_Auth_BWC extends SimpleSAML_Auth_Simple {
 			$url = SimpleSAML_Utilities::selfURL();
 		}
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		if (!$session->isValid($this->authority)) {
 			/* Not authenticated to this authentication source. */
 			SimpleSAML_Utilities::redirectTrustedURL($url);
diff --git a/lib/SimpleSAML/Auth/Default.php b/lib/SimpleSAML/Auth/Default.php
index ca02e748e..90d3d08c8 100644
--- a/lib/SimpleSAML/Auth/Default.php
+++ b/lib/SimpleSAML/Auth/Default.php
@@ -124,7 +124,7 @@ class SimpleSAML_Auth_Default {
 		$return = $state['SimpleSAML_Auth_Default.Return'];
 
 		/* Save session state. */
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->doLogin($state['SimpleSAML_Auth_Default.id'], self::extractPersistentAuthState($state));
 
 		if (is_string($return)) {
@@ -155,7 +155,7 @@ class SimpleSAML_Auth_Default {
 		assert('is_string($returnURL)');
 		assert('is_string($authority) || is_null($authority)');
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 
 		if ($authority === NULL) {
 			$authority = $session->getAuthority();
@@ -235,7 +235,7 @@ class SimpleSAML_Auth_Default {
 
 		$source = $state['SimpleSAML_Auth_Default.logoutSource'];
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$authId = $session->getAuthority();
 
 		if ($authId !== $source) {
@@ -270,7 +270,7 @@ class SimpleSAML_Auth_Default {
 		assert('is_string($authId)');
 		assert('is_string($redirectTo)');
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->doLogin($authId, self::extractPersistentAuthState($state));
 
 		SimpleSAML_Utilities::redirectUntrustedURL($redirectTo);
diff --git a/lib/SimpleSAML/Auth/Simple.php b/lib/SimpleSAML/Auth/Simple.php
index 804383052..db14112a8 100644
--- a/lib/SimpleSAML/Auth/Simple.php
+++ b/lib/SimpleSAML/Auth/Simple.php
@@ -48,7 +48,7 @@ class SimpleSAML_Auth_Simple {
 	 * @return bool  TRUE if the user is authenticated, FALSE if not.
 	 */
 	public function isAuthenticated() {
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 
 		return $session->isValid($this->authSource);
 	}
@@ -70,7 +70,7 @@ class SimpleSAML_Auth_Simple {
 	 */
 	public function requireAuth(array $params = array()) {
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 
 		if ($session->isValid($this->authSource)) {
 			/* Already authenticated. */
@@ -176,7 +176,7 @@ class SimpleSAML_Auth_Simple {
 			assert('isset($params["ReturnStateParam"]) && isset($params["ReturnStateStage"])');
 		}
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		if ($session->isValid($this->authSource)) {
 			$state = $session->getAuthData($this->authSource, 'LogoutState');
 			if ($state !== NULL) {
@@ -241,7 +241,7 @@ class SimpleSAML_Auth_Simple {
 		}
 
 		/* Authenticated. */
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		return $session->getAuthData($this->authSource, 'Attributes');
 	}
 
@@ -259,7 +259,7 @@ class SimpleSAML_Auth_Simple {
 			return NULL;
 		}
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		return $session->getAuthData($this->authSource, $name);
 	}
 
@@ -275,7 +275,7 @@ class SimpleSAML_Auth_Simple {
 			return NULL;
 		}
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		return $session->getAuthState($this->authSource);
 	}
 
diff --git a/lib/SimpleSAML/Auth/Source.php b/lib/SimpleSAML/Auth/Source.php
index 802035e4e..29effde13 100644
--- a/lib/SimpleSAML/Auth/Source.php
+++ b/lib/SimpleSAML/Auth/Source.php
@@ -111,7 +111,7 @@ abstract class SimpleSAML_Auth_Source {
 		assert('isset($state["ReturnCallback"])');
 
 		/* The default implementation just copies over the previous authentication data. */
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$data = $session->getAuthState($this->authId);
 		foreach ($data as $k => $v) {
 			$state[$k] = $v;
@@ -294,7 +294,7 @@ abstract class SimpleSAML_Auth_Source {
 			);
 
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->setData('SimpleSAML_Auth_Source.LogoutCallbacks', $id, $data,
 			SimpleSAML_Session::DATA_TIMEOUT_LOGOUT);
 	}
@@ -315,7 +315,7 @@ abstract class SimpleSAML_Auth_Source {
 
 		$id = strlen($this->authId) . ':' . $this->authId . $assoc;
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 
 		$data = $session->getData('SimpleSAML_Auth_Source.LogoutCallbacks', $id);
 		if ($data === NULL) {
diff --git a/lib/SimpleSAML/Auth/State.php b/lib/SimpleSAML/Auth/State.php
index ccea15f0e..a8600b1f3 100644
--- a/lib/SimpleSAML/Auth/State.php
+++ b/lib/SimpleSAML/Auth/State.php
@@ -160,7 +160,7 @@ class SimpleSAML_Auth_State {
 
 		/* Save state. */
 		$serializedState = serialize($state);
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->setData('SimpleSAML_Auth_State', $id, $serializedState, self::getStateTimeout());
 
 		SimpleSAML_Logger::debug('Saved state: ' . var_export($return, TRUE));
@@ -213,7 +213,7 @@ class SimpleSAML_Auth_State {
 
 		$sid = SimpleSAML_Utilities::parseStateID($id);
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$state = $session->getData('SimpleSAML_Auth_State', $sid['id']);
 
 		if ($state === NULL) {
@@ -274,7 +274,7 @@ class SimpleSAML_Auth_State {
 
 		SimpleSAML_Logger::debug('Deleting state: ' . var_export($state[self::ID], TRUE));
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->deleteData('SimpleSAML_Auth_State', $state[self::ID]);
 	}
 
diff --git a/lib/SimpleSAML/Error/Error.php b/lib/SimpleSAML/Error/Error.php
index ff1870863..67cf293bc 100644
--- a/lib/SimpleSAML/Error/Error.php
+++ b/lib/SimpleSAML/Error/Error.php
@@ -207,7 +207,7 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
 		SimpleSAML_Logger::error('Error report with id ' . $reportId . ' generated.');
 
 		$config = SimpleSAML_Configuration::getInstance();
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 
 		if (isset($_SERVER['HTTP_REFERER'])) {
 			$referer = $_SERVER['HTTP_REFERER'];
@@ -270,7 +270,7 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
 			$data['errorReportAddress'] = $baseurl . 'errorreport.php';
 		}
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$attributes = $session->getAttributes();
 		if (is_array($attributes) && array_key_exists('mail', $attributes) && count($attributes['mail']) > 0) {
 			$data['email'] = $attributes['mail'][0];
diff --git a/lib/SimpleSAML/IdP.php b/lib/SimpleSAML/IdP.php
index 119231a00..130a6ec5f 100644
--- a/lib/SimpleSAML/IdP.php
+++ b/lib/SimpleSAML/IdP.php
@@ -211,7 +211,7 @@ class SimpleSAML_IdP {
 
 		$association['core:IdP'] = $this->id;
 		
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->addAssociation($this->associationGroup, $association);
 	}
 
@@ -223,7 +223,7 @@ class SimpleSAML_IdP {
 	 */
 	public function getAssociations() {
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		return $session->getAssociations($this->associationGroup);
 	}
 
@@ -236,7 +236,7 @@ class SimpleSAML_IdP {
 	public function terminateAssociation($assocId) {
 		assert('is_string($assocId)');
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->terminateAssociation($this->associationGroup, $assocId);
 	}
 
@@ -260,7 +260,7 @@ class SimpleSAML_IdP {
 		assert('is_callable($state["Responder"])');
 
 		if (isset($state['core:SP'])) {
-			$session = SimpleSAML_Session::getInstance();
+			$session = SimpleSAML_Session::getSessionFromRequest();
 			$session->setData('core:idp-ssotime', $state['core:IdP'] . ';' . $state['core:SP'],
 				time(), SimpleSAML_Session::DATA_TIMEOUT_LOGOUT);
 		}
@@ -292,7 +292,7 @@ class SimpleSAML_IdP {
 		}
 
 		if (isset($state['core:SP'])) {
-			$session = SimpleSAML_Session::getInstance();
+			$session = SimpleSAML_Session::getSessionFromRequest();
 			$previousSSOTime = $session->getData('core:idp-ssotime', $state['core:IdP'] . ';' . $state['core:SP']);
 			if ($previousSSOTime !== NULL) {
 				$state['PreviousSSOTimestamp'] = $previousSSOTime;
diff --git a/lib/SimpleSAML/Logger.php b/lib/SimpleSAML/Logger.php
index 71a175a51..40c798097 100644
--- a/lib/SimpleSAML/Logger.php
+++ b/lib/SimpleSAML/Logger.php
@@ -303,7 +303,7 @@ class SimpleSAML_Logger
             self::$trackid = self::$TRACKID_FETCHING;
 
             // get the current session. This could cause recursion back to the logger class
-            $session = SimpleSAML_Session::getInstance();
+            $session = SimpleSAML_Session::getSessionFromRequest();
 
             // update the track ID
             self::$trackid = $session->getTrackID();
diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php
index 468bddfe4..a20b1a21a 100644
--- a/lib/SimpleSAML/Session.php
+++ b/lib/SimpleSAML/Session.php
@@ -191,14 +191,23 @@ class SimpleSAML_Session {
     }
 
 
-	/**
+    /**
+     * @deprecated
+     * @see SimpleSAML_Session::getSessionFromRequest()
+     */
+    public static function getInstance() {
+        return self::getSessionFromRequest();
+    }
+
+
+    /**
 	 * Retrieves the current session. Will create a new session if there isn't a session.
 	 *
 	 * @return SimpleSAML_Session The current session.
 	 * @throws Exception When session couldn't be initialized and
 	 * the session fallback is disabled by configuration.
 	 */
-	public static function getInstance() {
+	public static function getSessionFromRequest() {
 
 		/* Check if we already have initialized the session. */
 		if (isset(self::$instance)) {
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 18925686a..4ab3dc1dd 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -1622,7 +1622,7 @@ class SimpleSAML_Utilities {
 	 */
 	public static function isAdmin() {
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 
 		return $session->isValid('admin') || $session->isValid('login-admin');
 	}
@@ -1726,7 +1726,7 @@ class SimpleSAML_Utilities {
 				'url' => $destination,
 			);
 
-			$session = SimpleSAML_Session::getInstance();
+			$session = SimpleSAML_Session::getSessionFromRequest();
 			$session->setData('core_postdatalink', $postId, $postData);
 
 			$url = SimpleSAML_Module::getModuleURL('core/postredirect.php', array('RedirId' => $postId));
@@ -1753,7 +1753,7 @@ class SimpleSAML_Utilities {
 			'url' => $destination,
 		);
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->setData('core_postdatalink', $postId, $postData);
 
 		$redirInfo = base64_encode(self::aesEncrypt($session->getSessionId() . ':' . $postId));
@@ -2105,7 +2105,7 @@ class SimpleSAML_Utilities {
 	public static function checkCookie($retryURL = NULL) {
 		assert('is_string($retryURL) || is_null($retryURL)');
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		if ($session->hasSessionCookie()) {
 			return;
 		}
diff --git a/lib/SimpleSAML/XHTML/IdPDisco.php b/lib/SimpleSAML/XHTML/IdPDisco.php
index 7e7eeb938..2e06cddae 100644
--- a/lib/SimpleSAML/XHTML/IdPDisco.php
+++ b/lib/SimpleSAML/XHTML/IdPDisco.php
@@ -98,7 +98,7 @@ class SimpleSAML_XHTML_IdPDisco {
 		/* Initialize standard classes. */
 		$this->config = SimpleSAML_Configuration::getInstance();
 		$this->metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-		$this->session = SimpleSAML_Session::getInstance();
+		$this->session = SimpleSAML_Session::getSessionFromRequest();
 		$this->instance = $instance;
 		$this->metadataSets = $metadataSets;
 
diff --git a/modules/InfoCard/www/getcardform.php b/modules/InfoCard/www/getcardform.php
index c4dd9af68..76f4690c3 100644
--- a/modules/InfoCard/www/getcardform.php
+++ b/modules/InfoCard/www/getcardform.php
@@ -19,7 +19,7 @@ $Infocard =   $autoconfig->getValue('InfoCard');
 
 
 /* Load the session of the current user. */
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 if (!array_key_exists('AuthState', $_REQUEST)) {
 SimpleSAML_Logger::debug('NO AUTH STATE');
diff --git a/modules/InfoCard/www/login-infocard.php b/modules/InfoCard/www/login-infocard.php
index 9d0ae3bf6..97a399b5e 100644
--- a/modules/InfoCard/www/login-infocard.php
+++ b/modules/InfoCard/www/login-infocard.php
@@ -26,7 +26,7 @@ $contact_info_URL = $autoconfig->getValue('contact_info_URL');
 
 
 /* Load the session of the current user. */
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 
 if (!array_key_exists('AuthState', $_REQUEST)) {
diff --git a/modules/core/lib/Auth/Process/ExtendIdPSession.php b/modules/core/lib/Auth/Process/ExtendIdPSession.php
index 84616811d..7a6df5777 100644
--- a/modules/core/lib/Auth/Process/ExtendIdPSession.php
+++ b/modules/core/lib/Auth/Process/ExtendIdPSession.php
@@ -24,7 +24,7 @@ class sspmod_core_Auth_Process_ExtendIdPSession extends SimpleSAML_Auth_Processi
 		}
 
 		/* Update authority expire time */
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->setAuthorityExpire($state['Authority']);
 
 		/* Update session cookies duration */
diff --git a/modules/core/www/bwc_resumeauth.php b/modules/core/www/bwc_resumeauth.php
index df937077d..c704ed2c2 100644
--- a/modules/core/www/bwc_resumeauth.php
+++ b/modules/core/www/bwc_resumeauth.php
@@ -5,7 +5,7 @@ if (!isset($_REQUEST['RequestID'])) {
 }
 
 /* Backwards-compatibility with old authentication pages. */
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $requestcache = $session->getAuthnRequest('saml2', (string)$_REQUEST['RequestID']);
 if (!$requestcache) {
 	throw new Exception('Could not retrieve cached RequestID = ' . $authId);
diff --git a/modules/core/www/frontpage_auth.php b/modules/core/www/frontpage_auth.php
index 6ba33d18e..28d45304d 100644
--- a/modules/core/www/frontpage_auth.php
+++ b/modules/core/www/frontpage_auth.php
@@ -3,7 +3,7 @@
 
 /* Load simpleSAMLphp, configuration */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 /* Check if valid local session exists.. */
 if ($config->getBoolean('admin.protectindexpage', false)) {
diff --git a/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php
index f4bb8f552..c911f904b 100644
--- a/modules/core/www/frontpage_config.php
+++ b/modules/core/www/frontpage_config.php
@@ -4,7 +4,7 @@
 
 /* Load simpleSAMLphp, configuration */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 /* Check if valid local session exists.. */
 if ($config->getBoolean('admin.protectindexpage', false)) {
diff --git a/modules/core/www/frontpage_federation.php b/modules/core/www/frontpage_federation.php
index 072ad6c5e..d502e7bab 100644
--- a/modules/core/www/frontpage_federation.php
+++ b/modules/core/www/frontpage_federation.php
@@ -4,7 +4,7 @@
 
 /* Load simpleSAMLphp, configuration */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 /* Check if valid local session exists.. */
 if ($config->getBoolean('admin.protectindexpage', false)) {
diff --git a/modules/core/www/frontpage_welcome.php b/modules/core/www/frontpage_welcome.php
index fa0847737..281237a9b 100644
--- a/modules/core/www/frontpage_welcome.php
+++ b/modules/core/www/frontpage_welcome.php
@@ -3,7 +3,7 @@
 
 /* Load simpleSAMLphp, configuration */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 /* Check if valid local session exists.. */
 if ($config->getBoolean('admin.protectindexpage', false)) {
diff --git a/modules/core/www/idp/resumeauth.php b/modules/core/www/idp/resumeauth.php
index b9e24fe20..dff0cb337 100644
--- a/modules/core/www/idp/resumeauth.php
+++ b/modules/core/www/idp/resumeauth.php
@@ -7,7 +7,7 @@ if (!isset($_REQUEST['RequestID'])) {
 }
 
 /* Backwards-compatibility with old authentication pages. */
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $requestcache = $session->getAuthnRequest('saml2', (string)$_REQUEST['RequestID']);
 if (!$requestcache) {
 	throw new Exception('Could not retrieve cached RequestID = ' . $authId);
diff --git a/modules/core/www/postredirect.php b/modules/core/www/postredirect.php
index fd9bef458..d414050f2 100644
--- a/modules/core/www/postredirect.php
+++ b/modules/core/www/postredirect.php
@@ -9,7 +9,7 @@
 
 if (array_key_exists('RedirId', $_REQUEST)) {
 	$postId = $_REQUEST['RedirId'];
-	$session = SimpleSAML_Session::getInstance();
+	$session = SimpleSAML_Session::getSessionFromRequest();
 } elseif (array_key_exists('RedirInfo', $_REQUEST)) {
 	$encData = base64_decode($_REQUEST['RedirInfo']);
 
diff --git a/modules/core/www/show_metadata.php b/modules/core/www/show_metadata.php
index e7647d2e4..b2e9d96fb 100644
--- a/modules/core/www/show_metadata.php
+++ b/modules/core/www/show_metadata.php
@@ -4,7 +4,7 @@
 
 /* Load simpleSAMLphp, configuration */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Utilities::requireAdmin();
 
diff --git a/modules/cron/www/croninfo.php b/modules/cron/www/croninfo.php
index 0e5571563..a0ecd68d9 100644
--- a/modules/cron/www/croninfo.php
+++ b/modules/cron/www/croninfo.php
@@ -9,7 +9,7 @@ require_once('_include.php');
 
 /* Load simpleSAMLphp, configuration and metadata */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Utilities::requireAdmin();
 
diff --git a/modules/logpeek/www/index.php b/modules/logpeek/www/index.php
index 2389e31ea..3ae3e7099 100644
--- a/modules/logpeek/www/index.php
+++ b/modules/logpeek/www/index.php
@@ -19,7 +19,7 @@ function logFilter($objFile, $tag, $cut){
 
 
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Utilities::requireAdmin();
 
diff --git a/modules/metaedit/www/xmlimport.php b/modules/metaedit/www/xmlimport.php
index 12f607211..12799af05 100644
--- a/modules/metaedit/www/xmlimport.php
+++ b/modules/metaedit/www/xmlimport.php
@@ -3,7 +3,7 @@
 
 /* Load simpleSAMLphp, configuration and metadata */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 $template = new SimpleSAML_XHTML_Template($config, 'metaedit:xmlimport.tpl.php');
 $template->show();
diff --git a/modules/multiauth/lib/Auth/Source/MultiAuth.php b/modules/multiauth/lib/Auth/Source/MultiAuth.php
index ea74df5a8..1bac37ad2 100644
--- a/modules/multiauth/lib/Auth/Source/MultiAuth.php
+++ b/modules/multiauth/lib/Auth/Source/MultiAuth.php
@@ -149,7 +149,7 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source {
 		}
 
 		/* Save the selected authentication source for the logout process. */
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->setData(self::SESSION_SOURCE, $state[self::AUTHID], $authId);
 
 		try {
@@ -175,7 +175,7 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source {
 		assert('is_array($state)');
 
 		/* Get the source that was used to authenticate */
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$authId = $session->getData(self::SESSION_SOURCE, $this->authId);
 
 		$source = SimpleSAML_Auth_Source::getById($authId);
diff --git a/modules/negotiate/lib/Auth/Source/Negotiate.php b/modules/negotiate/lib/Auth/Source/Negotiate.php
index 173114cf1..7689186c2 100644
--- a/modules/negotiate/lib/Auth/Source/Negotiate.php
+++ b/modules/negotiate/lib/Auth/Source/Negotiate.php
@@ -80,7 +80,7 @@ class sspmod_negotiate_Auth_Source_Negotiate extends SimpleSAML_Auth_Source {
 			$this->fallBack($state);
 		// Go straight to fallback if Negotiate is disabled or if you are
 		// sent back to the IdP directly from the SP after having logged out
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$disabled = $session->getData('negotiate:disable', 'session');
 
 		if ($disabled or
@@ -309,7 +309,7 @@ click <a href="'.htmlspecialchars($url).'">here</a>.
 		SimpleSAML_Logger::debug('Negotiate - logout has the following authId: "'.$authId.'"');
 
 		if ($authId === NULL) {
-			$session = SimpleSAML_Session::getInstance();
+			$session = SimpleSAML_Session::getSessionFromRequest();
 			$session->setData('negotiate:disable', 'session', TRUE, 24*60*60);
 			parent::logout($state);
 		} else {
diff --git a/modules/negotiate/www/disable.php b/modules/negotiate/www/disable.php
index ca8bb8d00..42b09c0f0 100644
--- a/modules/negotiate/www/disable.php
+++ b/modules/negotiate/www/disable.php
@@ -17,7 +17,7 @@ $params = array(
 SimpleSAML_Utilities::setCookie('NEGOTIATE_AUTOLOGIN_DISABLE_PERMANENT', 'True', $params, FALSE);
 
 $globalConfig = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $session->setData('negotiate:disable', 'session', FALSE, 24*60*60);
 $t = new SimpleSAML_XHTML_Template($globalConfig, 'negotiate:disable.php');
 $t->show();
diff --git a/modules/negotiate/www/enable.php b/modules/negotiate/www/enable.php
index e28bde1f9..1bf30f2cf 100644
--- a/modules/negotiate/www/enable.php
+++ b/modules/negotiate/www/enable.php
@@ -16,7 +16,7 @@ $params = array(
 SimpleSAML_Utilities::setCookie('NEGOTIATE_AUTOLOGIN_DISABLE_PERMANENT', NULL, $params, FALSE);
 
 $globalConfig = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $session->setData('negotiate:disable', 'session', FALSE, 24*60*60);
 $t = new SimpleSAML_XHTML_Template($globalConfig, 'negotiate:enable.php');
 $t->show();
diff --git a/modules/negotiate/www/retry.php b/modules/negotiate/www/retry.php
index 1f75c61d6..b36290e44 100644
--- a/modules/negotiate/www/retry.php
+++ b/modules/negotiate/www/retry.php
@@ -28,7 +28,7 @@ if (isset($idpmeta['auth'])) {
 	if ($source === NULL)
 		throw new SimpleSAML_Error_BadRequest('Invalid AuthId "' . $idpmeta['auth'] . '" - not found.');
 
-	$session = SimpleSAML_Session::getInstance();
+	$session = SimpleSAML_Session::getSessionFromRequest();
 	$session->setData('negotiate:disable', 'session', FALSE, 24*60*60);
 	SimpleSAML_Logger::debug('Negotiate(retry) - session enabled, retrying.');
 	$source->authenticate($state);
diff --git a/modules/oauth/bin/demo.php b/modules/oauth/bin/demo.php
index 49ebad860..b1dcf520c 100755
--- a/modules/oauth/bin/demo.php
+++ b/modules/oauth/bin/demo.php
@@ -20,7 +20,7 @@ try {
 	require_once(dirname(dirname(__FILE__)) . '/libextinc/OAuth.php');
 
 	// Needed in order to make session_start to be called before output is printed.
-	$session = SimpleSAML_Session::getInstance();
+	$session = SimpleSAML_Session::getSessionFromRequest();
 
 	//$baseurl = (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'https://foodle.feide.no/simplesaml');
 	$baseurl = (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'http://mars.foodle.local/simplesaml');
diff --git a/modules/oauth/www/authorize.php b/modules/oauth/www/authorize.php
index 583c86efc..ed92f1460 100644
--- a/modules/oauth/www/authorize.php
+++ b/modules/oauth/www/authorize.php
@@ -26,7 +26,7 @@ try {
 
 
 	$config = SimpleSAML_Configuration::getInstance();
-	$session = SimpleSAML_Session::getInstance();
+	$session = SimpleSAML_Session::getSessionFromRequest();
 
 	$as = $oauthconfig->getString('auth');
 	if (!$session->isValid($as)) {
diff --git a/modules/oauth/www/registry.edit.php b/modules/oauth/www/registry.edit.php
index f4a5ea306..972e10461 100644
--- a/modules/oauth/www/registry.edit.php
+++ b/modules/oauth/www/registry.edit.php
@@ -2,7 +2,7 @@
 
 /* Load simpleSAMLphp, configuration and metadata */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $oauthconfig = SimpleSAML_Configuration::getOptionalConfig('module_oauth.php');
 
 $store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
diff --git a/modules/oauth/www/registry.php b/modules/oauth/www/registry.php
index d562bb06b..c7ac52c7f 100644
--- a/modules/oauth/www/registry.php
+++ b/modules/oauth/www/registry.php
@@ -2,7 +2,7 @@
 
 /* Load simpleSAMLphp, configuration and metadata */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $oauthconfig = SimpleSAML_Configuration::getOptionalConfig('module_oauth.php');
 
 $store = new sspmod_core_Storage_SQLPermanentStorage('oauth');
diff --git a/modules/openid/lib/SessionStore.php b/modules/openid/lib/SessionStore.php
index a084d0919..2dc31a57f 100644
--- a/modules/openid/lib/SessionStore.php
+++ b/modules/openid/lib/SessionStore.php
@@ -20,7 +20,7 @@ class sspmod_openid_SessionStore {
 	public function get($key) {
 		assert('is_string($key)');
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		return $session->getData('openid.session', $key);
 	}
 
@@ -34,7 +34,7 @@ class sspmod_openid_SessionStore {
 	public function set($key, $value) {
 		assert('is_string($key)');
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->setData('openid.session', $key, $value);
 	}
 
@@ -47,7 +47,7 @@ class sspmod_openid_SessionStore {
 	public function del($key) {
 		assert('is_string($key)');
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->deleteData('openid.session', $key);
 	}
 
diff --git a/modules/saml/lib/Auth/Source/SP.php b/modules/saml/lib/Auth/Source/SP.php
index a23cb0fe9..565ad6631 100644
--- a/modules/saml/lib/Auth/Source/SP.php
+++ b/modules/saml/lib/Auth/Source/SP.php
@@ -403,7 +403,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source {
 	public function reauthenticate(array &$state) {
 		assert('is_array($state)');
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$data = $session->getAuthState($this->authId);
 		foreach ($data as $k => $v) {
 			$state[$k] = $v;
@@ -438,7 +438,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source {
 		assert('isset($state["ReturnCallback"])');
 
 		// Update session state
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$session->doLogin($state['saml:sp:AuthId'], SimpleSAML_Auth_Default::extractPersistentAuthState($state));
 
 		// resume the login process
diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php
index f7b45d1d1..055729099 100644
--- a/modules/saml/lib/IdP/SAML2.php
+++ b/modules/saml/lib/IdP/SAML2.php
@@ -798,7 +798,7 @@ class sspmod_saml_IdP_SAML2 {
 			$a->setAuthnInstant($state['AuthnInstant']);
 		} else {
 			/* For backwards compatibility. Remove in version 1.8. */
-			$session = SimpleSAML_Session::getInstance();
+			$session = SimpleSAML_Session::getSessionFromRequest();
 			$a->setAuthnInstant($session->getAuthnInstant());
 		}
 
diff --git a/modules/saml/lib/SP/LogoutStore.php b/modules/saml/lib/SP/LogoutStore.php
index 93bef896e..6ad352f53 100644
--- a/modules/saml/lib/SP/LogoutStore.php
+++ b/modules/saml/lib/SP/LogoutStore.php
@@ -187,7 +187,7 @@ class sspmod_saml_SP_LogoutStore {
 			$sessionIndex = sha1($sessionIndex);
 		}
 
-		$session = SimpleSAML_Session::getInstance();
+		$session = SimpleSAML_Session::getSessionFromRequest();
 		$sessionId = $session->getSessionId();
 
 		if ($store instanceof SimpleSAML_Store_SQL) {
diff --git a/modules/saml/www/sp/saml2-acs.php b/modules/saml/www/sp/saml2-acs.php
index dc0375834..1341095cb 100644
--- a/modules/saml/www/sp/saml2-acs.php
+++ b/modules/saml/www/sp/saml2-acs.php
@@ -34,7 +34,7 @@ if ($idp === NULL) {
 	}
 }
 
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $prevAuth = $session->getAuthData($sourceId, 'saml:sp:prevAuth');
 if ($prevAuth !== NULL && $prevAuth['id'] === $response->getId() && $prevAuth['issuer'] === $idp) {
 	/* OK, it looks like this message has the same issuer
diff --git a/modules/statistics/www/showstats.php b/modules/statistics/www/showstats.php
index babdcf2cd..0af0e9d67 100644
--- a/modules/statistics/www/showstats.php
+++ b/modules/statistics/www/showstats.php
@@ -2,7 +2,7 @@
 
 $config = SimpleSAML_Configuration::getInstance();
 $statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 
 sspmod_statistics_AccessCheck::checkAccess($statconfig);
diff --git a/www/auth/login-admin.php b/www/auth/login-admin.php
index 306dda0a2..5a53b8373 100644
--- a/www/auth/login-admin.php
+++ b/www/auth/login-admin.php
@@ -12,7 +12,7 @@ require_once('../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
 $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file auth/login-admin.php is deprecated and will be removed in future versions.');
 
diff --git a/www/auth/login-cas-ldap.php b/www/auth/login-cas-ldap.php
index 7a7325d19..3a6b835f8 100644
--- a/www/auth/login-cas-ldap.php
+++ b/www/auth/login-cas-ldap.php
@@ -22,7 +22,7 @@
 require_once('../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file auth/login-cas-ldap.php is deprecated and will be removed in future versions.');
 
diff --git a/www/auth/login-ldapmulti.php b/www/auth/login-ldapmulti.php
index 4db2fdb74..9364aef42 100644
--- a/www/auth/login-ldapmulti.php
+++ b/www/auth/login-ldapmulti.php
@@ -12,7 +12,7 @@ require_once('../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
 $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file auth/login-ldapmulti.php is deprecated and will be removed in future versions.');
 
diff --git a/www/auth/login-radius.php b/www/auth/login-radius.php
index d8d785b7f..cec122aaf 100644
--- a/www/auth/login-radius.php
+++ b/www/auth/login-radius.php
@@ -12,7 +12,7 @@ require_once('../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
 $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file auth/login-radius.php is deprecated and will be removed in future versions.');
 
diff --git a/www/auth/login-tlsclient.php b/www/auth/login-tlsclient.php
index 71930ef3f..414f4d52f 100644
--- a/www/auth/login-tlsclient.php
+++ b/www/auth/login-tlsclient.php
@@ -12,7 +12,7 @@ require_once('../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
 $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file auth/login-tlsclient.php is deprecated and will be removed in future versions.');
 
diff --git a/www/auth/login-wayf-ldap.php b/www/auth/login-wayf-ldap.php
index c0ad0a9b7..a1539c527 100644
--- a/www/auth/login-wayf-ldap.php
+++ b/www/auth/login-wayf-ldap.php
@@ -22,7 +22,7 @@
 require_once('../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file auth/login-wayf-ldap.php is deprecated and will be removed in future versions.');
 
diff --git a/www/auth/login.php b/www/auth/login.php
index d334fbfa6..d0b0fdda3 100644
--- a/www/auth/login.php
+++ b/www/auth/login.php
@@ -12,7 +12,7 @@ require_once('../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
 $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file auth/login.php is deprecated and will be removed in future versions.');
 
diff --git a/www/authmemcookie.php b/www/authmemcookie.php
index a4e877a7c..b385400c9 100644
--- a/www/authmemcookie.php
+++ b/www/authmemcookie.php
@@ -105,7 +105,7 @@ try {
 	$memcache->set($sessionID, $data, 0, $expirationTime);
 
 	/* Register logout handler. */
-	$session = SimpleSAML_Session::getInstance();
+	$session = SimpleSAML_Session::getSessionFromRequest();
 	$session->registerLogoutHandler('SimpleSAML_AuthMemCookie', 'logoutHandler');
 
 	/* Redirect the user back to this page to signal that the login is completed. */
diff --git a/www/errorreport.php b/www/errorreport.php
index 0abb624c6..3ce5246dc 100644
--- a/www/errorreport.php
+++ b/www/errorreport.php
@@ -18,7 +18,7 @@ $email = (string)$_REQUEST['email'];
 $text = htmlspecialchars((string)$_REQUEST['text']);
 
 try {
-	$session = SimpleSAML_Session::getInstance();
+	$session = SimpleSAML_Session::getSessionFromRequest();
 	$data = $session->getData('core:errorreport', $reportId);
 } catch (Exception $e) {
 	SimpleSAML_Logger::error('Error loading error report data: ' . var_export($e->getMessage(), TRUE));
diff --git a/www/example-simple/attributequery.php b/www/example-simple/attributequery.php
index 890a1e49f..76932baf6 100644
--- a/www/example-simple/attributequery.php
+++ b/www/example-simple/attributequery.php
@@ -10,7 +10,7 @@
 
 require_once('../_include.php');
 
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
 SimpleSAML_Logger::warning('The file example-simple/attributequery.php is deprecated and will be removed in future versions.');
diff --git a/www/example-simple/hostnames.php b/www/example-simple/hostnames.php
index 87e5ca422..e92e26dd6 100644
--- a/www/example-simple/hostnames.php
+++ b/www/example-simple/hostnames.php
@@ -4,7 +4,7 @@ require_once('../_include.php');
 
 /* Load simpleSAMLphp, configuration */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 /* Check if valid local session exists.. */
 SimpleSAML_Utilities::requireAdmin();
diff --git a/www/example-simple/saml2-example.php b/www/example-simple/saml2-example.php
index 7c48d5fae..5fdc83b60 100644
--- a/www/example-simple/saml2-example.php
+++ b/www/example-simple/saml2-example.php
@@ -27,7 +27,7 @@ session_cache_limiter('nocache');
 
 /* Load simpleSAMLphp, configuration and metadata */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file example-simple/saml2-example.php is deprecated and will be removed in future versions.');
 
diff --git a/www/example-simple/shib13-example.php b/www/example-simple/shib13-example.php
index 96d78b3de..4b275ed83 100644
--- a/www/example-simple/shib13-example.php
+++ b/www/example-simple/shib13-example.php
@@ -27,7 +27,7 @@ session_cache_limiter('nocache');
 
 /* Load simpleSAMLphp, configuration and metadata */
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file example-simple/shib13-example.php is deprecated and will be removed in future versions.');
 
diff --git a/www/example-simple/wsfed-example.php b/www/example-simple/wsfed-example.php
index 5335d0d3d..166fc61b3 100644
--- a/www/example-simple/wsfed-example.php
+++ b/www/example-simple/wsfed-example.php
@@ -11,7 +11,7 @@
 require_once('../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file example-simple/wsfed-example.php is deprecated and will be removed in future versions.');
 
diff --git a/www/saml2/sp/AssertionConsumerService.php b/www/saml2/sp/AssertionConsumerService.php
index 88dbc5c3c..5c0a8e173 100644
--- a/www/saml2/sp/AssertionConsumerService.php
+++ b/www/saml2/sp/AssertionConsumerService.php
@@ -27,7 +27,7 @@ SimpleSAML_Logger::warning('The file saml2/sp/AssertionConsumerService.php is de
 /* Get the session object for the user. Create a new session if no session
  * exists for this user.
  */
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 
 /**
diff --git a/www/saml2/sp/SingleLogoutService.php b/www/saml2/sp/SingleLogoutService.php
index e0b6f8a32..e21b65ccb 100644
--- a/www/saml2/sp/SingleLogoutService.php
+++ b/www/saml2/sp/SingleLogoutService.php
@@ -16,7 +16,7 @@ $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 SimpleSAML_Logger::warning('The file saml2/sp/SingleLogoutService.php is deprecated and will be removed in future versions.');
 
 // Get the local session
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 
 SimpleSAML_Logger::info('SAML2.0 - SP.SingleLogoutService: Accessing SAML 2.0 SP endpoint SingleLogoutService');
diff --git a/www/saml2/sp/initSLO.php b/www/saml2/sp/initSLO.php
index de4f3810f..50b2d035f 100644
--- a/www/saml2/sp/initSLO.php
+++ b/www/saml2/sp/initSLO.php
@@ -12,7 +12,7 @@ require_once('../../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
 
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file saml2/sp/initSLO.php is deprecated and will be removed in future versions.');
 
diff --git a/www/saml2/sp/initSSO.php b/www/saml2/sp/initSSO.php
index 55ca0efc0..ef1acc239 100644
--- a/www/saml2/sp/initSSO.php
+++ b/www/saml2/sp/initSSO.php
@@ -12,7 +12,7 @@ require_once('../../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
 $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::warning('The file saml2/sp/initSSO.php is deprecated and will be removed in future versions.');
 
diff --git a/www/shib13/sp/AssertionConsumerService.php b/www/shib13/sp/AssertionConsumerService.php
index 9e59d0ac7..ab1fd6874 100644
--- a/www/shib13/sp/AssertionConsumerService.php
+++ b/www/shib13/sp/AssertionConsumerService.php
@@ -14,7 +14,7 @@ $config = SimpleSAML_Configuration::getInstance();
 
 SimpleSAML_Logger::warning('The file shib13/sp/AssertionConsumerService.php is deprecated and will be removed in future versions.');
 
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 
 /**
diff --git a/www/shib13/sp/initSSO.php b/www/shib13/sp/initSSO.php
index de5f74eca..2cceb210e 100644
--- a/www/shib13/sp/initSSO.php
+++ b/www/shib13/sp/initSSO.php
@@ -15,7 +15,7 @@ $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
 SimpleSAML_Logger::warning('The file shib13/sp/initSSO.php is deprecated and will be removed in future versions.');
 
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 		
 
 /*
diff --git a/www/wsfed/sp/initSLO.php b/www/wsfed/sp/initSLO.php
index 001d8fb74..a30e294c9 100644
--- a/www/wsfed/sp/initSLO.php
+++ b/www/wsfed/sp/initSLO.php
@@ -14,7 +14,7 @@ $config = SimpleSAML_Configuration::getInstance();
 
 SimpleSAML_Logger::warning('The file wsfed/sp/initSLO.php is deprecated and will be removed in future versions.');
 
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 
 SimpleSAML_Logger::info('WS-Fed - SP.initSLO: Accessing WS-Fed SP initSLO script');
 
diff --git a/www/wsfed/sp/prp.php b/www/wsfed/sp/prp.php
index 606222b26..219930d07 100644
--- a/www/wsfed/sp/prp.php
+++ b/www/wsfed/sp/prp.php
@@ -24,7 +24,7 @@
 require_once('../../_include.php');
 
 $config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
+$session = SimpleSAML_Session::getSessionFromRequest();
 $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
 
 SimpleSAML_Logger::warning('The file wsfed/sp/prp.php is deprecated and will be removed in future versions.');
-- 
GitLab