diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php
index defcf78f5ce6cd811175ccfa679e3e2a4c19537f..97c1db23c90ccc03975cdb57a1cffb775805ff52 100644
--- a/lib/SimpleSAML/Session.php
+++ b/lib/SimpleSAML/Session.php
@@ -152,7 +152,7 @@ class SimpleSAML_Session implements Serializable
         }
 
         if ($transient) { // transient session
-            $sh = SimpleSAML_SessionHandler::getSessionHandler();
+            $sh = \SimpleSAML\SessionHandler::getSessionHandler();
             $this->trackid = 'TR'.bin2hex(openssl_random_pseudo_bytes(4));
             SimpleSAML\Logger::setTrackId($this->trackid);
             $this->transient = true;
@@ -166,7 +166,7 @@ class SimpleSAML_Session implements Serializable
                 $this->sessionId = $sh->newSessionId();
             }
         } else { // regular session
-            $sh = SimpleSAML_SessionHandler::getSessionHandler();
+            $sh = \SimpleSAML\SessionHandler::getSessionHandler();
             $this->sessionId = $sh->newSessionId();
             $sh->setCookie($sh->getSessionCookieName(), $this->sessionId, $sh->getCookieParams());
 
@@ -318,7 +318,7 @@ class SimpleSAML_Session implements Serializable
     {
         assert('is_string($sessionId) || is_null($sessionId)');
 
-        $sh = SimpleSAML_SessionHandler::getSessionHandler();
+        $sh = \SimpleSAML\SessionHandler::getSessionHandler();
 
         if ($sessionId === null) {
             $checkToken = true;
@@ -439,7 +439,7 @@ class SimpleSAML_Session implements Serializable
         $this->dirty = false;
         $this->callback_registered = false;
 
-        $sh = SimpleSAML_SessionHandler::getSessionHandler();
+        $sh = \SimpleSAML\SessionHandler::getSessionHandler();
 
         try {
             $sh->saveSession($this);
@@ -462,8 +462,8 @@ class SimpleSAML_Session implements Serializable
     public function cleanup()
     {
         $this->save();
-        $sh = SimpleSAML_SessionHandler::getSessionHandler();
-        if ($sh instanceof SimpleSAML_SessionHandlerPHP) {
+        $sh = \SimpleSAML\SessionHandler::getSessionHandler();
+        if ($sh instanceof \SimpleSAML\SessionHandlerPHP) {
             $sh->restorePrevious();
         }
     }
@@ -633,7 +633,7 @@ class SimpleSAML_Session implements Serializable
         $this->authData[$authority] = $data;
 
         $this->authToken = SimpleSAML\Utils\Random::generateID();
-        $sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
+        $sessionHandler = \SimpleSAML\SessionHandler::getSessionHandler();
 
         if (!$this->transient && (!empty($data['RememberMe']) || $this->rememberMeExpire) &&
             $globalConfig->getBoolean('session.rememberme.enable', false)
@@ -760,7 +760,7 @@ class SimpleSAML_Session implements Serializable
      */
     public function updateSessionCookies($params = null)
     {
-        $sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
+        $sessionHandler = \SimpleSAML\SessionHandler::getSessionHandler();
 
         if ($this->sessionId !== null) {
             $sessionHandler->setCookie($sessionHandler->getSessionCookieName(), $this->sessionId, $params);
@@ -1040,7 +1040,7 @@ class SimpleSAML_Session implements Serializable
      */
     public function hasSessionCookie()
     {
-        $sh = SimpleSAML_SessionHandler::getSessionHandler();
+        $sh = \SimpleSAML\SessionHandler::getSessionHandler();
         return $sh->hasSessionCookie();
     }
 
diff --git a/lib/SimpleSAML/SessionHandler.php b/lib/SimpleSAML/SessionHandler.php
index f6c4300c3ee7ac3daad53b4e574594bf7195fada..0a336e891b7e9b97e450652d1258e6efa9e4a33e 100644
--- a/lib/SimpleSAML/SessionHandler.php
+++ b/lib/SimpleSAML/SessionHandler.php
@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * This file is part of SimpleSAMLphp. See the file COPYING in the
  * root of the distribution for licence information.
@@ -12,7 +11,10 @@
  * @author Olav Morken, UNINETT AS. <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-abstract class SimpleSAML_SessionHandler
+
+namespace SimpleSAML;
+
+abstract class SessionHandler
 {
 
 
@@ -21,7 +23,7 @@ abstract class SimpleSAML_SessionHandler
      * instance of the session handler. This variable will be NULL if
      * we haven't instantiated a session handler yet.
      *
-     * @var SimpleSAML_SessionHandler
+     * @var \SimpleSAML\SessionHandler
      */
     protected static $sessionHandler = null;
 
@@ -31,7 +33,7 @@ abstract class SimpleSAML_SessionHandler
      * The session handler will be instantiated if this is the first call
      * to this function.
      *
-     * @return SimpleSAML_SessionHandler The current session handler.
+     * @return \SimpleSAML\SessionHandler The current session handler.
      */
     public static function getSessionHandler()
     {
@@ -80,17 +82,17 @@ abstract class SimpleSAML_SessionHandler
     /**
      * Save the session.
      *
-     * @param SimpleSAML_Session $session The session object we should save.
+     * @param \SimpleSAML_Session $session The session object we should save.
      */
-    abstract public function saveSession(SimpleSAML_Session $session);
+    abstract public function saveSession(\SimpleSAML_Session $session);
 
 
     /**
      * Load the session.
      *
-     * @param string|NULL $sessionId The ID of the session we should load, or null to use the default.
+     * @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.
+     * @return \SimpleSAML_Session|null The session object, or null if it doesn't exist.
      */
     abstract public function loadSession($sessionId = null);
 
@@ -117,13 +119,12 @@ abstract class SimpleSAML_SessionHandler
      */
     private static function createSessionHandler()
     {
-
         $store = \SimpleSAML\Store::getInstance();
         if ($store === false) {
-            self::$sessionHandler = new SimpleSAML_SessionHandlerPHP();
+            self::$sessionHandler = new SessionHandlerPHP();
         } else {
             /** @var \SimpleSAML\Store $store At this point, $store can only be an object */
-            self::$sessionHandler = new SimpleSAML_SessionHandlerStore($store);
+            self::$sessionHandler = new SessionHandlerStore($store);
         }
     }
 
@@ -149,7 +150,7 @@ abstract class SimpleSAML_SessionHandler
      */
     public function getCookieParams()
     {
-        $config = SimpleSAML_Configuration::getInstance();
+        $config = \SimpleSAML_Configuration::getInstance();
 
         return array(
             'lifetime' => $config->getInteger('session.cookie.lifetime', 0),
diff --git a/lib/SimpleSAML/SessionHandlerCookie.php b/lib/SimpleSAML/SessionHandlerCookie.php
index e5c02bff6b9b671cedc800342da26f3fde2c0903..5f82e76b382b9362d0c0c6e980159f349a625e44 100644
--- a/lib/SimpleSAML/SessionHandlerCookie.php
+++ b/lib/SimpleSAML/SessionHandlerCookie.php
@@ -11,7 +11,12 @@
  * @package SimpleSAMLphp
  * @abstract
  */
-abstract class SimpleSAML_SessionHandlerCookie extends SimpleSAML_SessionHandler
+
+namespace SimpleSAML;
+
+use SimpleSAML\Utils\HTTP;
+
+abstract class SessionHandlerCookie extends SessionHandler
 {
 
     /**
@@ -39,7 +44,7 @@ abstract class SimpleSAML_SessionHandlerCookie extends SimpleSAML_SessionHandler
         // call the constructor in the base class in case it should become necessary in the future
         parent::__construct();
 
-        $config = SimpleSAML_Configuration::getInstance();
+        $config = \SimpleSAML_Configuration::getInstance();
         $this->cookie_name = $config->getString('session.cookie.name', 'SimpleSAMLSessionID');
     }
 
@@ -52,7 +57,7 @@ abstract class SimpleSAML_SessionHandlerCookie extends SimpleSAML_SessionHandler
     public function newSessionId()
     {
         $this->session_id = self::createSessionID();
-        SimpleSAML_Session::createSession($this->session_id);
+        \SimpleSAML_Session::createSession($this->session_id);
 
         return $this->session_id;
     }
@@ -163,6 +168,6 @@ abstract class SimpleSAML_SessionHandlerCookie extends SimpleSAML_SessionHandler
             $params = $this->getCookieParams();
         }
 
-        \SimpleSAML\Utils\HTTP::setCookie($sessionName, $sessionID, $params, true);
+        HTTP::setCookie($sessionName, $sessionID, $params, true);
     }
 }
diff --git a/lib/SimpleSAML/SessionHandlerPHP.php b/lib/SimpleSAML/SessionHandlerPHP.php
index 7964af748f2d6d1dda8dd2dab8b15747701674e5..0cf8d074eb3363033058490918a4121bf5f9a4d8 100644
--- a/lib/SimpleSAML/SessionHandlerPHP.php
+++ b/lib/SimpleSAML/SessionHandlerPHP.php
@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * This file is part of SimpleSAMLphp. See the file COPYING in the root of the distribution for licence information.
  *
@@ -9,7 +8,13 @@
  * @author Olav Morken, UNINETT AS. <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
+
+namespace SimpleSAML;
+
+use SimpleSAML\Error\CannotSetCookie;
+use SimpleSAML\Utils\HTTP;
+
+class SessionHandlerPHP extends SessionHandler
 {
 
     /**
@@ -34,14 +39,14 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
 
     /**
      * Initialize the PHP session handling. This constructor is protected because it should only be called from
-     * SimpleSAML_SessionHandler::createSessionHandler(...).
+     * \SimpleSAML\SessionHandler::createSessionHandler(...).
      */
     protected function __construct()
     {
         // call the parent constructor in case it should become necessary in the future
         parent::__construct();
 
-        $config = SimpleSAML_Configuration::getInstance();
+        $config = \SimpleSAML_Configuration::getInstance();
         $this->cookie_name = $config->getString('session.phpsession.cookiename', null);
 
         if (function_exists('session_status') && defined('PHP_SESSION_ACTIVE')) { // PHP >= 5.4
@@ -52,7 +57,7 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
 
         if ($previous_session) {
             if (session_name() === $this->cookie_name || $this->cookie_name === null) {
-                SimpleSAML\Logger::warning(
+                Logger::warning(
                     'There is already a PHP session with the same name as SimpleSAMLphp\'s session, or the '.
                     "'session.phpsession.cookiename' configuration option is not set. Make sure to set ".
                     "SimpleSAMLphp's cookie name with a value not used by any other applications."
@@ -167,7 +172,7 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
     {
         // generate new (secure) session id
         $sessionId = bin2hex(openssl_random_pseudo_bytes(16));
-        SimpleSAML_Session::createSession($sessionId);
+        \SimpleSAML_Session::createSession($sessionId);
 
         return $sessionId;
     }
@@ -178,7 +183,7 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
      *
      * @return string|null The session id saved in the cookie or null if no session cookie was set.
      *
-     * @throws SimpleSAML_Error_Exception If the cookie is marked as secure but we are not using HTTPS.
+     * @throws \SimpleSAML_Error_Exception If the cookie is marked as secure but we are not using HTTPS.
      */
     public function getCookieSessionId()
     {
@@ -191,8 +196,8 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
 
         $session_cookie_params = session_get_cookie_params();
 
-        if ($session_cookie_params['secure'] && !\SimpleSAML\Utils\HTTP::isHTTPS()) {
-            throw new SimpleSAML_Error_Exception('Session start with secure cookie not allowed on http.');
+        if ($session_cookie_params['secure'] && !HTTP::isHTTPS()) {
+            throw new \SimpleSAML_Error_Exception('Session start with secure cookie not allowed on http.');
         }
 
         $this->sessionStart();
@@ -214,9 +219,9 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
     /**
      * Save the current session to the PHP session array.
      *
-     * @param SimpleSAML_Session $session The session object we should save.
+     * @param \SimpleSAML_Session $session The session object we should save.
      */
-    public function saveSession(SimpleSAML_Session $session)
+    public function saveSession(\SimpleSAML_Session $session)
     {
         $_SESSION['SimpleSAMLphp_SESSION'] = serialize($session);
     }
@@ -227,9 +232,9 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
      *
      * @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.
+     * @return \SimpleSAML_Session|null The session object, or null if it doesn't exist.
      *
-     * @throws SimpleSAML_Error_Exception If it wasn't possible to disable session cookies or we are trying to load a
+     * @throws \SimpleSAML_Error_Exception If it wasn't possible to disable session cookies or we are trying to load a
      * PHP session with a specific identifier and it doesn't match with the current session identifier.
      */
     public function loadSession($sessionId = null)
@@ -241,13 +246,13 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
                 // session not initiated with getCookieSessionId(), start session without setting cookie
                 $ret = ini_set('session.use_cookies', '0');
                 if ($ret === false) {
-                    throw new SimpleSAML_Error_Exception('Disabling PHP option session.use_cookies failed.');
+                    throw new \SimpleSAML_Error_Exception('Disabling PHP option session.use_cookies failed.');
                 }
 
                 session_id($sessionId);
                 $this->sessionStart();
             } elseif ($sessionId !== session_id()) {
-                throw new SimpleSAML_Error_Exception('Cannot load PHP session with a specific ID.');
+                throw new \SimpleSAML_Error_Exception('Cannot load PHP session with a specific ID.');
             }
         } elseif (session_id() === '') {
             self::getCookieSessionId();
@@ -288,17 +293,17 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
      * @return array The cookie parameters for our sessions.
      * @link http://www.php.net/manual/en/function.session-get-cookie-params.php
      *
-     * @throws SimpleSAML_Error_Exception If both 'session.phpsession.limitedpath' and 'session.cookie.path' options
+     * @throws \SimpleSAML_Error_Exception If both 'session.phpsession.limitedpath' and 'session.cookie.path' options
      * are set at the same time in the configuration.
      */
     public function getCookieParams()
     {
-        $config = SimpleSAML_Configuration::getInstance();
+        $config = \SimpleSAML_Configuration::getInstance();
 
         $ret = parent::getCookieParams();
 
         if ($config->hasValue('session.phpsession.limitedpath') && $config->hasValue('session.cookie.path')) {
-            throw new SimpleSAML_Error_Exception(
+            throw new \SimpleSAML_Error_Exception(
                 'You cannot set both the session.phpsession.limitedpath and session.cookie.path options.'
             );
         } elseif ($config->hasValue('session.phpsession.limitedpath')) {
@@ -329,17 +334,17 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler
             $cookieParams = session_get_cookie_params();
         }
 
-        if ($cookieParams['secure'] && !\SimpleSAML\Utils\HTTP::isHTTPS()) {
-            throw new \SimpleSAML\Error\CannotSetCookie(
+        if ($cookieParams['secure'] && !HTTP::isHTTPS()) {
+            throw new CannotSetCookie(
                 'Setting secure cookie on plain HTTP is not allowed.',
-                \SimpleSAML\Error\CannotSetCookie::SECURE_COOKIE
+                CannotSetCookie::SECURE_COOKIE
             );
         }
 
         if (headers_sent()) {
-            throw new \SimpleSAML\Error\CannotSetCookie(
+            throw new CannotSetCookie(
                 'Headers already sent.',
-                \SimpleSAML\Error\CannotSetCookie::HEADERS_SENT
+                CannotSetCookie::HEADERS_SENT
             );
         }
 
diff --git a/lib/SimpleSAML/SessionHandlerStore.php b/lib/SimpleSAML/SessionHandlerStore.php
index 002e7ffc189648d2a53fb3454fc7b601a3536eae..fc40bf04bc22ac73c4fe6db610a7426cbea51241 100644
--- a/lib/SimpleSAML/SessionHandlerStore.php
+++ b/lib/SimpleSAML/SessionHandlerStore.php
@@ -6,7 +6,10 @@
  *
  * @package SimpleSAMLphp
  */
-class SimpleSAML_SessionHandlerStore extends SimpleSAML_SessionHandlerCookie
+
+namespace SimpleSAML;
+
+class SessionHandlerStore extends SessionHandlerCookie
 {
 
     /**
@@ -22,7 +25,7 @@ class SimpleSAML_SessionHandlerStore extends SimpleSAML_SessionHandlerCookie
      *
      * @param \SimpleSAML\Store $store The store to use.
      */
-    protected function __construct(\SimpleSAML\Store $store)
+    protected function __construct(Store $store)
     {
         parent::__construct();
 
@@ -35,7 +38,7 @@ class SimpleSAML_SessionHandlerStore extends SimpleSAML_SessionHandlerCookie
      *
      * @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.
+     * @return \SimpleSAML_Session|null The session object, or null if it doesn't exist.
      */
     public function loadSession($sessionId = null)
     {
@@ -62,18 +65,16 @@ class SimpleSAML_SessionHandlerStore extends SimpleSAML_SessionHandlerCookie
     /**
      * Save a session to the data store.
      *
-     * @param SimpleSAML_Session $session The session object we should save.
+     * @param \SimpleSAML_Session $session The session object we should save.
      */
-    public function saveSession(SimpleSAML_Session $session)
+    public function saveSession(\SimpleSAML_Session $session)
     {
-
         $sessionId = $session->getSessionId();
 
-        $config = SimpleSAML_Configuration::getInstance();
+        $config = \SimpleSAML_Configuration::getInstance();
         $sessionDuration = $config->getInteger('session.duration', 8 * 60 * 60);
         $expire = time() + $sessionDuration;
 
         $this->store->set('session', $sessionId, $session, $expire);
     }
-
 }
diff --git a/modules/core/lib/Auth/Process/ExtendIdPSession.php b/modules/core/lib/Auth/Process/ExtendIdPSession.php
index 3945741189f1c4157403857b7a432cf28e4edb14..b8382d30c3b79e5a0b24a84b39613905d589fc86 100644
--- a/modules/core/lib/Auth/Process/ExtendIdPSession.php
+++ b/modules/core/lib/Auth/Process/ExtendIdPSession.php
@@ -37,7 +37,7 @@ class sspmod_core_Auth_Process_ExtendIdPSession extends SimpleSAML_Auth_Processi
 		}
 
 		/* Or if session lifetime is more than zero */
-		$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
+		$sessionHandler = \SimpleSAML\SessionHandler::getSessionHandler();
 		$cookieParams = $sessionHandler->getCookieParams();
 		if ($cookieParams['lifetime'] > 0) {
 			$session->updateSessionCookies();
diff --git a/modules/core/www/loginuserpass.php b/modules/core/www/loginuserpass.php
index 1ccf6b58b46df854104340541493cf6f4bca20de..78ba32a0a384f38983bbb6bc25c495794f2fbe08 100644
--- a/modules/core/www/loginuserpass.php
+++ b/modules/core/www/loginuserpass.php
@@ -49,7 +49,7 @@ if (!empty($_REQUEST['username']) || !empty($password)) {
 	}
 
 	if ($source->getRememberUsernameEnabled()) {
-		$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
+		$sessionHandler = \SimpleSAML\SessionHandler::getSessionHandler();
 		$params = $sessionHandler->getCookieParams();
 		$params['expire'] = time();
 		$params['expire'] += (isset($_REQUEST['remember_username']) && $_REQUEST['remember_username'] == 'Yes' ? 31536000 : -300);
diff --git a/modules/core/www/loginuserpassorg.php b/modules/core/www/loginuserpassorg.php
index 4f33b36f186b1b790e8e6fa8777b592a9cbe9399..61ba28354f836db1695f8cf89ff09f4804fdc8b8 100644
--- a/modules/core/www/loginuserpassorg.php
+++ b/modules/core/www/loginuserpassorg.php
@@ -53,7 +53,7 @@ if ($organizations === NULL || !empty($organization)) {
 	if (!empty($username) && !empty($password)) {
 
 		if ($source->getRememberUsernameEnabled()) {
-			$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
+			$sessionHandler = \SimpleSAML\SessionHandler::getSessionHandler();
 			$params = $sessionHandler->getCookieParams();
 			$params['expire'] = time();
 			$params['expire'] += (isset($_REQUEST['remember_username']) && $_REQUEST['remember_username'] == 'Yes' ? 31536000 : -300);
diff --git a/modules/saml/lib/SP/LogoutStore.php b/modules/saml/lib/SP/LogoutStore.php
index 020c6259770441b9d90c622e7e0a7d75de8a1bc8..346db25bc68120a5e6ff7355d93ec9be5ffa645e 100644
--- a/modules/saml/lib/SP/LogoutStore.php
+++ b/modules/saml/lib/SP/LogoutStore.php
@@ -255,7 +255,7 @@ class sspmod_saml_SP_LogoutStore {
 			$sessionIndexes = array_keys($sessions);
 		}
 
-		$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
+		$sessionHandler = \SimpleSAML\SessionHandler::getSessionHandler();
 
 		$numLoggedOut = 0;
 		foreach ($sessionIndexes as $sessionIndex) {