From c858a2e099195c62d2c24f7c604093c45966cf59 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Wed, 30 May 2018 22:34:57 +0200
Subject: [PATCH] Replace SimpleSAML_Metadata_* with namespaced version

---
 bin/importPdoMetadata.php                     |  4 +-
 bin/initMDSPdo.php                            |  4 +-
 lib/SimpleSAML/Bindings/Shib13/HTTPPost.php   |  6 +-
 lib/SimpleSAML/IdP.php                        |  4 +-
 .../Metadata/MetaDataStorageHandler.php       | 36 +++----
 .../MetaDataStorageHandlerFlatFile.php        |  9 +-
 .../Metadata/MetaDataStorageHandlerPdo.php    | 10 +-
 .../MetaDataStorageHandlerSerialize.php       | 29 +++---
 .../Metadata/MetaDataStorageHandlerXML.php    | 12 ++-
 .../Metadata/MetaDataStorageSource.php        | 32 +++----
 lib/SimpleSAML/Metadata/SAMLBuilder.php       |  2 +-
 lib/SimpleSAML/Metadata/SAMLParser.php        | 96 ++++++++++---------
 lib/SimpleSAML/Metadata/Signer.php            | 30 +++---
 lib/SimpleSAML/Metadata/Sources/MDQ.php       | 12 +--
 lib/SimpleSAML/XHTML/IdPDisco.php             |  4 +-
 lib/SimpleSAML/XML/Shib13/AuthnRequest.php    |  2 +-
 lib/SimpleSAML/XML/Shib13/AuthnResponse.php   |  4 +-
 modules/adfs/lib/IdP/ADFS.php                 |  4 +-
 modules/adfs/www/idp/metadata.php             |  4 +-
 modules/adfs/www/idp/prp.php                  |  6 +-
 modules/consent/lib/Auth/Process/Consent.php  |  2 +-
 modules/consentAdmin/www/consentAdmin.php     |  2 +-
 modules/core/www/frontpage_federation.php     |  2 +-
 modules/core/www/idp/logout-iframe-post.php   |  2 +-
 modules/core/www/idp/logout-iframe.php        |  2 +-
 modules/core/www/show_metadata.php            |  2 +-
 .../www/attributeserver.php                   |  2 +-
 modules/metarefresh/hooks/hook_cron.php       |  2 +-
 modules/metarefresh/lib/MetaLoader.php        |  4 +-
 modules/negotiate/www/retry.php               |  2 +-
 modules/saml/lib/Auth/Source/SP.php           |  6 +-
 modules/saml/lib/IdP/SAML1.php                |  8 +-
 modules/saml/lib/IdP/SAML2.php                | 63 ++++++------
 modules/saml/www/idp/certs.php                |  2 +-
 modules/saml/www/sp/metadata.php              |  2 +-
 modules/saml/www/sp/saml2-logout.php          | 10 +-
 .../Statistics/FieldPresentation/Entity.php   |  2 +-
 .../Metadata/MetaDataStorageSourceTest.php    | 16 ++--
 .../SimpleSAML/Metadata/SAMLParserTest.php    |  7 +-
 www/admin/metadata-converter.php              |  2 +-
 www/saml2/idp/ArtifactResolutionService.php   |  2 +-
 www/saml2/idp/SSOService.php                  |  6 +-
 www/saml2/idp/SingleLogoutService.php         |  6 +-
 www/saml2/idp/initSLO.php                     |  2 +-
 www/saml2/idp/metadata.php                    |  4 +-
 www/shib13/idp/SSOService.php                 |  2 +-
 www/shib13/idp/metadata.php                   |  4 +-
 47 files changed, 247 insertions(+), 229 deletions(-)

diff --git a/bin/importPdoMetadata.php b/bin/importPdoMetadata.php
index 79e4b504a..b930b99f2 100755
--- a/bin/importPdoMetadata.php
+++ b/bin/importPdoMetadata.php
@@ -3,14 +3,14 @@
 $baseDir = dirname(dirname(__FILE__));
 
 require_once $baseDir.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'_autoload.php';
-require_once SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php';
+require_once \SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php';
 
 # Iterate through configured metadata sources and ensure
 # that a PDO source exists.
 foreach ($config['metadata.sources'] as $s) {
     # If pdo is configured, create the new handler and add in the metadata sets.
     if ($s['type'] === "pdo") {
-        $mdshp = new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($s);
+        $mdshp = new \SimpleSAML\Metadata\MetaDataStorageHandlerPdo($s);
         $mdshp->initDatabase();
 
         foreach (glob("metadata/*.php") as $filename) {
diff --git a/bin/initMDSPdo.php b/bin/initMDSPdo.php
index b68a5b22f..403b4d2de 100755
--- a/bin/initMDSPdo.php
+++ b/bin/initMDSPdo.php
@@ -6,7 +6,7 @@ $baseDir = dirname(dirname(__FILE__));
 
 // Add library autoloader and configuration
 require_once $baseDir.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'_autoload.php';
-require_once SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php';
+require_once \SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php';
 
 echo "Initializing Metadata Database...".PHP_EOL;
 
@@ -15,7 +15,7 @@ echo "Initializing Metadata Database...".PHP_EOL;
 foreach ($config['metadata.sources'] as $source) {
     # If pdo is configured, create the new handler and initialize the DB.
     if ($source['type'] === "pdo") {
-        $metadataStorageHandler = new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($source);
+        $metadataStorageHandler = new \SimpleSAML\Metadata\MetaDataStorageHandlerPdo($source);
         $result = $metadataStorageHandler->initDatabase();
 
         if ($result === false) {
diff --git a/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php b/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
index 8612816ca..97d004c71 100644
--- a/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
+++ b/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
@@ -25,7 +25,7 @@ class HTTPPost
     private $configuration = null;
 
     /**
-     * @var \SimpleSAML_Metadata_MetaDataStorageHandler
+     * @var \SimpleSAML\Metadata\MetaDataStorageHandler
      */
     private $metadata = null;
 
@@ -34,11 +34,11 @@ class HTTPPost
      * Constructor for the \SimpleSAML\Bindings\Shib13\HTTPPost class.
      *
      * @param \SimpleSAML\Configuration                   $configuration The configuration to use.
-     * @param \SimpleSAML_Metadata_MetaDataStorageHandler $metadatastore A store where to find metadata.
+     * @param \SimpleSAML\Metadata\MetaDataStorageHandler $metadatastore A store where to find metadata.
      */
     public function __construct(
         \SimpleSAML\Configuration $configuration,
-        \SimpleSAML_Metadata_MetaDataStorageHandler $metadatastore
+        \SimpleSAML\Metadata\MetaDataStorageHandler $metadatastore
     ) {
         $this->configuration = $configuration;
         $this->metadata = $metadatastore;
diff --git a/lib/SimpleSAML/IdP.php b/lib/SimpleSAML/IdP.php
index 633ef83fe..6edfc85bb 100644
--- a/lib/SimpleSAML/IdP.php
+++ b/lib/SimpleSAML/IdP.php
@@ -60,7 +60,7 @@ class SimpleSAML_IdP
 
         $this->id = $id;
 
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $globalConfig = SimpleSAML\Configuration::getInstance();
 
         if (substr($id, 0, 6) === 'saml2:') {
@@ -174,7 +174,7 @@ class SimpleSAML_IdP
 
         $prefix = substr($assocId, 0, 4);
         $spEntityId = substr($assocId, strlen($prefix) + 1);
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
         if ($prefix === 'saml') {
             try {
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
index e1595a8eb..426d3cc63 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
@@ -1,5 +1,7 @@
 <?php
 
+namespace SimpleSAML\Metadata;
+
 /**
  * This file defines a class for metadata handling.
  *
@@ -7,14 +9,14 @@
  * @package SimpleSAMLphp
  */
 
-class SimpleSAML_Metadata_MetaDataStorageHandler
+class MetaDataStorageHandler
 {
     /**
      * This static variable contains a reference to the current
      * instance of the metadata handler. This variable will be null if
      * we haven't instantiated a metadata handler yet.
      *
-     * @var SimpleSAML_Metadata_MetaDataStorageHandler
+     * @var MetaDataStorageHandler
      */
     private static $metadataHandler = null;
 
@@ -23,7 +25,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
      * This is a list of all the metadata sources we have in our metadata
      * chain. When we need metadata, we will look through this chain from start to end.
      *
-     * @var SimpleSAML_Metadata_MetaDataStorageSource[]
+     * @var MetaDataStorageSource[]
      */
     private $sources;
 
@@ -33,12 +35,12 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
      * The metadata handler will be instantiated if this is the first call
      * to this function.
      *
-     * @return SimpleSAML_Metadata_MetaDataStorageHandler The current metadata handler instance.
+     * @return MetaDataStorageHandler The current metadata handler instance.
      */
     public static function getMetadataHandler()
     {
         if (self::$metadataHandler === null) {
-            self::$metadataHandler = new SimpleSAML_Metadata_MetaDataStorageHandler();
+            self::$metadataHandler = new MetaDataStorageHandler();
         }
 
         return self::$metadataHandler;
@@ -62,9 +64,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
         }
 
         try {
-            $this->sources = SimpleSAML_Metadata_MetaDataStorageSource::parseSources($sourcesConfig);
-        } catch (Exception $e) {
-            throw new Exception(
+            $this->sources = MetaDataStorageSource::parseSources($sourcesConfig);
+        } catch (\Exception $e) {
+            throw new \Exception(
                 "Invalid configuration of the 'metadata.sources' configuration option: ".$e->getMessage()
             );
         }
@@ -78,7 +80,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
      * @param string $set The set we the property comes from.
      *
      * @return string The auto-generated metadata property.
-     * @throws Exception If the metadata cannot be generated automatically.
+     * @throws \Exception If the metadata cannot be generated automatically.
      */
     public function getGenerated($property, $set)
     {
@@ -88,7 +90,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
             if (array_key_exists($property, $metadataSet)) {
                 return $metadataSet[$property];
             }
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             // probably metadata wasn't found. In any case we continue by generating the metadata
         }
 
@@ -122,7 +124,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
             }
         }
 
-        throw new Exception('Could not generate metadata property '.$property.' for set '.$set.'.');
+        throw new \Exception('Could not generate metadata property '.$property.' for set '.$set.'.');
     }
 
 
@@ -147,9 +149,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
                 if (array_key_exists('expire', $le)) {
                     if ($le['expire'] < time()) {
                         unset($srcList[$key]);
-                        SimpleSAML\Logger::warning(
+                        \SimpleSAML\Logger::warning(
                             "Dropping metadata entity ".var_export($key, true).", expired ".
-                            SimpleSAML\Utils\Time::generateTimestamp($le['expire'])."."
+                            \SimpleSAML\Utils\Time::generateTimestamp($le['expire'])."."
                         );
                     }
                 }
@@ -187,7 +189,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
      * @param string $type Do you want to return the metaindex or the entityID. [entityid|metaindex]
      *
      * @return string The entity id which is associated with the current hostname/path combination.
-     * @throws Exception If no default metadata can be found in the set for the current host.
+     * @throws \Exception If no default metadata can be found in the set for the current host.
      */
     public function getMetaDataCurrentEntityID($set, $type = 'entityid')
     {
@@ -222,7 +224,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
         }
 
         // we were unable to find the hostname/path in any metadata source
-        throw new Exception(
+        throw new \Exception(
             'Could not find any default metadata entities in set ['.$set.'] for host ['.$currenthost.' : '.
             $currenthostwithpath.']'
         );
@@ -261,7 +263,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
      * @param string $set The set of metadata we are looking up the entity id in.
      *
      * @return array The metadata array describing the specified entity.
-     * @throws Exception If metadata for the specified entity is expired.
+     * @throws \Exception If metadata for the specified entity is expired.
      * @throws \SimpleSAML\Error\MetadataNotFound If no metadata for the entity specified can be found.
      */
     public function getMetaData($index, $set)
@@ -280,7 +282,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
             if ($metadata !== null) {
                 if (array_key_exists('expire', $metadata)) {
                     if ($metadata['expire'] < time()) {
-                        throw new Exception(
+                        throw new \Exception(
                             'Metadata for the entity ['.$index.'] expired '.
                             (time() - $metadata['expire']).' seconds ago.'
                         );
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
index 9183284c0..6901c15a3 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
@@ -1,5 +1,6 @@
 <?php
 
+namespace SimpleSAML\Metadata;
 
 /**
  * This file defines a flat file metadata source.
@@ -9,9 +10,9 @@
  * @author Andreas Ă…kre Solberg, UNINETT AS. <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Metadata_MetaDataStorageHandlerFlatFile extends SimpleSAML_Metadata_MetaDataStorageSource
-{
 
+class MetaDataStorageHandlerFlatFile extends MetaDataStorageSource
+{
     /**
      * This is the directory we will load metadata files from. The path will always end
      * with a '/'.
@@ -82,7 +83,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerFlatFile extends SimpleSAML_Meta
         include($metadatasetfile);
 
         if (!is_array($metadata)) {
-            throw new Exception('Could not load metadata set ['.$set.'] from file: '.$metadatasetfile);
+            throw new \Exception('Could not load metadata set ['.$set.'] from file: '.$metadatasetfile);
         }
 
         return $metadata;
@@ -138,7 +139,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerFlatFile extends SimpleSAML_Meta
         } elseif ($set === 'adfs-idp-hosted') {
             return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost().':idp';
         } else {
-            throw new Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
+            throw new \Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
         }
     }
 }
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
index 7ba227589..ed575c555 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
@@ -1,5 +1,7 @@
 <?php
 
+namespace SimpleSAML\Metadata;
+
 /**
  * Class for handling metadata files stored in a database.
  *
@@ -10,7 +12,7 @@
  * @package SimpleSAMLphp
  */
 
-class SimpleSAML_Metadata_MetaDataStorageHandlerPdo extends SimpleSAML_Metadata_MetaDataStorageSource
+class MetaDataStorageHandlerPdo extends MetaDataStorageSource
 {
     /**
      * The PDO object
@@ -60,7 +62,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerPdo extends SimpleSAML_Metadata_
     {
         assert(is_array($config));
 
-        $this->db = SimpleSAML\Database::getInstance();
+        $this->db = \SimpleSAML\Database::getInstance();
     }
 
 
@@ -103,7 +105,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerPdo extends SimpleSAML_Metadata_
 
             return $metadata;
         } else {
-            throw new Exception('PDO metadata handler: Database error: '.var_export($this->db->getLastError(), true));
+            throw new \Exception('PDO metadata handler: Database error: '.var_export($this->db->getLastError(), true));
         }
     }
 
@@ -204,7 +206,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerPdo extends SimpleSAML_Metadata_
         } elseif ($set === 'adfs-idp-hosted') {
             return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost().':idp';
         } else {
-            throw new Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
+            throw new \Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
         }
     }
 
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php
index 0a1ee73a5..7b9d478f5 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php
@@ -1,14 +1,15 @@
 <?php
 
+namespace SimpleSAML\Metadata;
 
 /**
  * Class for handling metadata files in serialized format.
  *
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Metadata_MetaDataStorageSource
-{
 
+class MetaDataStorageHandlerSerialize extends MetaDataStorageSource
+{
     /**
      * The file extension we use for our metadata files.
      *
@@ -77,7 +78,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Met
 
         $dh = @opendir($this->directory);
         if ($dh === false) {
-            SimpleSAML\Logger::warning(
+            \SimpleSAML\Logger::warning(
                 'Serialize metadata handler: Unable to open directory: '.var_export($this->directory, true)
             );
             return $ret;
@@ -92,7 +93,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Met
             $path = $this->directory.'/'.$entry;
 
             if (!is_dir($path)) {
-                SimpleSAML\Logger::warning(
+                \SimpleSAML\Logger::warning(
                     'Serialize metadata handler: Metadata directory contained a file where only directories should '.
                     'exist: '.var_export($path, true)
                 );
@@ -129,7 +130,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Met
 
         $dh = @opendir($dir);
         if ($dh === false) {
-            SimpleSAML\Logger::warning('Serialize metadata handler: Unable to open directory: '.var_export($dir, true));
+            \SimpleSAML\Logger::warning('Serialize metadata handler: Unable to open directory: '.var_export($dir, true));
             return $ret;
         }
 
@@ -182,7 +183,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Met
         $data = @file_get_contents($filePath);
         if ($data === false) {
             $error = error_get_last();
-            SimpleSAML\Logger::warning(
+            \SimpleSAML\Logger::warning(
                 'Error reading file '.$filePath.': '.$error['message']
             );
             return null;
@@ -190,7 +191,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Met
 
         $data = @unserialize($data);
         if ($data === false) {
-            SimpleSAML\Logger::warning('Error unserializing file: '.$filePath);
+            \SimpleSAML\Logger::warning('Error unserializing file: '.$filePath);
             return null;
         }
 
@@ -222,30 +223,30 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Met
 
         $dir = dirname($filePath);
         if (!is_dir($dir)) {
-            SimpleSAML\Logger::info('Creating directory: '.$dir);
+            \SimpleSAML\Logger::info('Creating directory: '.$dir);
             $res = @mkdir($dir, 0777, true);
             if ($res === false) {
                 $error = error_get_last();
-                SimpleSAML\Logger::error('Failed to create directory '.$dir.': '.$error['message']);
+                \SimpleSAML\Logger::error('Failed to create directory '.$dir.': '.$error['message']);
                 return false;
             }
         }
 
         $data = serialize($metadata);
 
-        SimpleSAML\Logger::debug('Writing: '.$newPath);
+        \SimpleSAML\Logger::debug('Writing: '.$newPath);
 
         $res = file_put_contents($newPath, $data);
         if ($res === false) {
             $error = error_get_last();
-            SimpleSAML\Logger::error('Error saving file '.$newPath.': '.$error['message']);
+            \SimpleSAML\Logger::error('Error saving file '.$newPath.': '.$error['message']);
             return false;
         }
 
         $res = rename($newPath, $filePath);
         if ($res === false) {
             $error = error_get_last();
-            SimpleSAML\Logger::error('Error renaming '.$newPath.' to '.$filePath.': '.$error['message']);
+            \SimpleSAML\Logger::error('Error renaming '.$newPath.' to '.$filePath.': '.$error['message']);
             return false;
         }
 
@@ -267,7 +268,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Met
         $filePath = $this->getMetadataPath($entityId, $set);
 
         if (!file_exists($filePath)) {
-            SimpleSAML\Logger::warning(
+            \SimpleSAML\Logger::warning(
                 'Attempted to erase nonexistent metadata entry '.
                 var_export($entityId, true).' in set '.var_export($set, true).'.'
             );
@@ -277,7 +278,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerSerialize extends SimpleSAML_Met
         $res = unlink($filePath);
         if ($res === false) {
             $error = error_get_last();
-            SimpleSAML\Logger::error(
+            \SimpleSAML\Logger::error(
                 'Failed to delete file '.$filePath.
                 ': '.$error['message']
             );
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php
index 49e238412..11852e706 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php
@@ -1,5 +1,6 @@
 <?php
 
+namespace SimpleSAML\Metadata;
 
 /**
  * This class implements a metadata source which loads metadata from XML files.
@@ -8,7 +9,8 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_MetaDataStorageSource
+
+class MetaDataStorageHandlerXML extends MetaDataStorageSource
 {
 
     /**
@@ -42,7 +44,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_
         } elseif (array_key_exists('xml', $config)) {
             $srcXml = $config['xml'];
         } else {
-            throw new Exception("Missing one of 'file', 'url' and 'xml' in XML metadata source configuration.");
+            throw new \Exception("Missing one of 'file', 'url' and 'xml' in XML metadata source configuration.");
         }
 
 
@@ -53,11 +55,11 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_
         $AAD = array();
 
         if(isset($src)) {
-            $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($src);
+            $entities = SAMLParser::parseDescriptorsFile($src);
         } elseif(isset($srcXml)) {
-            $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($srcXml);
+            $entities = SAMLParser::parseDescriptorsString($srcXml);
         } else {
-            throw new Exception("Neither source file path/URI nor string data provided");
+            throw new \Exception("Neither source file path/URI nor string data provided");
         }
         foreach ($entities as $entityId => $entity) {
             $md = $entity->getMetadata1xSP();
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
index b4e39f2d1..360b619ce 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
@@ -1,5 +1,6 @@
 <?php
 
+namespace SimpleSAML\Metadata;
 
 /**
  * This abstract class defines an interface for metadata storage sources.
@@ -12,10 +13,9 @@
  * @author Andreas Aakre Solberg, UNINETT AS.
  * @package SimpleSAMLphp
  */
-abstract class SimpleSAML_Metadata_MetaDataStorageSource
-{
-
 
+abstract class MetaDataStorageSource
+{
     /**
      * Parse array with metadata sources.
      *
@@ -26,7 +26,7 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource
      *
      * @return array  Parsed metadata configuration.
      *
-     * @throws Exception If something is wrong in the configuration.
+     * @throws \Exception If something is wrong in the configuration.
      */
     public static function parseSources($sourcesConfig)
     {
@@ -36,7 +36,7 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource
 
         foreach ($sourcesConfig as $sourceConfig) {
             if (!is_array($sourceConfig)) {
-                throw new Exception("Found an element in metadata source configuration which wasn't an array.");
+                throw new \Exception("Found an element in metadata source configuration which wasn't an array.");
             }
 
             $sources[] = self::getSource($sourceConfig);
@@ -55,7 +55,7 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource
      *
      * @return mixed An instance of a metadata source with the given configuration.
      *
-     * @throws Exception If the metadata source type is invalid.
+     * @throws \Exception If the metadata source type is invalid.
      */
     public static function getSource($sourceConfig)
     {
@@ -69,26 +69,26 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource
 
         switch ($type) {
             case 'flatfile':
-                return new SimpleSAML_Metadata_MetaDataStorageHandlerFlatFile($sourceConfig);
+                return new MetaDataStorageHandlerFlatFile($sourceConfig);
             case 'xml':
-                return new SimpleSAML_Metadata_MetaDataStorageHandlerXML($sourceConfig);
+                return new MetaDataStorageHandlerXML($sourceConfig);
             case 'serialize':
-                return new SimpleSAML_Metadata_MetaDataStorageHandlerSerialize($sourceConfig);
+                return new MetaDataStorageHandlerSerialize($sourceConfig);
             case 'mdx':
             case 'mdq':
-                return new \SimpleSAML\Metadata\Sources\MDQ($sourceConfig);
+                return new Sources\MDQ($sourceConfig);
             case 'pdo':
-                return new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($sourceConfig);
+                return new MetaDataStorageHandlerPdo($sourceConfig);
             default:
                 // metadata store from module
                 try {
-                    $className = SimpleSAML\Module::resolveClass(
+                    $className = \SimpleSAML\Module::resolveClass(
                         $type,
                         'MetadataStore',
-                        'SimpleSAML_Metadata_MetaDataStorageSource'
+                        '\SimpleSAML\Metadata\MetaDataStorageSource'
                     );
-                } catch (Exception $e) {
-                    throw new SimpleSAML\Error\CriticalConfigurationError(
+                } catch (\Exception $e) {
+                    throw new \SimpleSAML\Error\CriticalConfigurationError(
                         "Invalid 'type' for metadata source. Cannot find store '$type'.",
                         null
                     );
@@ -196,7 +196,7 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource
             }
 
             foreach ($cidrHints as $hint_entry) {
-                if (SimpleSAML\Utils\Net::ipCIDRcheck($hint_entry, $ip)) {
+                if (\SimpleSAML\Utils\Net::ipCIDRcheck($hint_entry, $ip)) {
                     if ($type === 'entityid') {
                         return $entry['entityid'];
                     } else {
diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php
index 0935e4004..5640151e0 100644
--- a/lib/SimpleSAML/Metadata/SAMLBuilder.php
+++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php
@@ -638,7 +638,7 @@ class SAMLBuilder
      * Add metadata of a SAML attribute authority.
      *
      * @param array $metadata The AttributeAuthorityDescriptor, in the format returned by
-     * SimpleSAML_Metadata_SAMLParser.
+     * \SimpleSAML\Metadata\SAMLParser.
      */
     public function addAttributeAuthority(array $metadata)
     {
diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index 28c7f7806..0ff8fb95e 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -1,10 +1,14 @@
 <?php
 
+namespace SimpleSAML\Metadata;
+
+use RobRichards\XMLSecLibs\XMLSecurityKey;
+
 /**
  * This is class for parsing of SAML 1.x and SAML 2.0 metadata.
  *
  * Metadata is loaded by calling the static methods parseFile, parseString or parseElement.
- * These functions returns an instance of SimpleSAML_Metadata_SAMLParser. To get metadata
+ * These functions returns an instance of SAMLParser. To get metadata
  * from this object, use the methods getMetadata1xSP or getMetadata20SP.
  *
  * To parse a file which can contain a collection of EntityDescriptor or EntitiesDescriptor elements, use the
@@ -12,7 +16,7 @@
  * an array of SAMLParser elements where each element represents an EntityDescriptor-element.
  */
 
-class SimpleSAML_Metadata_SAMLParser
+class SAMLParser
 {
     /**
      * This is the list of SAML 1.x protocols.
@@ -202,7 +206,7 @@ class SimpleSAML_Metadata_SAMLParser
      *
      * @param string $file The path to the file which contains the metadata.
      *
-     * @return SimpleSAML_Metadata_SAMLParser An instance of this class with the metadata loaded.
+     * @return SAMLParser An instance of this class with the metadata loaded.
      * @throws Exception If the file does not parse as XML.
      */
     public static function parseFile($file)
@@ -212,7 +216,7 @@ class SimpleSAML_Metadata_SAMLParser
         try {
             $doc = \SAML2\DOMDocumentFactory::fromString($data);
         } catch (\Exception $e) {
-            throw new Exception('Failed to read XML from file: '.$file);
+            throw new \Exception('Failed to read XML from file: '.$file);
         }
 
         return self::parseDocument($doc);
@@ -224,7 +228,7 @@ class SimpleSAML_Metadata_SAMLParser
      *
      * @param string $metadata A string which contains XML encoded metadata.
      *
-     * @return SimpleSAML_Metadata_SAMLParser An instance of this class with the metadata loaded.
+     * @return SAMLParser An instance of this class with the metadata loaded.
      * @throws Exception If the string does not parse as XML.
      */
     public static function parseString($metadata)
@@ -232,7 +236,7 @@ class SimpleSAML_Metadata_SAMLParser
         try {
             $doc = \SAML2\DOMDocumentFactory::fromString($metadata);
         } catch (\Exception $e) {
-            throw new Exception('Failed to parse XML string.');
+            throw new \Exception('Failed to parse XML string.');
         }
 
         return self::parseDocument($doc);
@@ -240,15 +244,15 @@ class SimpleSAML_Metadata_SAMLParser
 
 
     /**
-     * This function parses a DOMDocument which is assumed to contain a single EntityDescriptor element.
+     * This function parses a \DOMDocument which is assumed to contain a single EntityDescriptor element.
      *
-     * @param DOMDocument $document The DOMDocument which contains the EntityDescriptor element.
+     * @param \DOMDocument $document The \DOMDocument which contains the EntityDescriptor element.
      *
-     * @return SimpleSAML_Metadata_SAMLParser An instance of this class with the metadata loaded.
+     * @return SAMLParser An instance of this class with the metadata loaded.
      */
     public static function parseDocument($document)
     {
-        assert($document instanceof DOMDocument);
+        assert($document instanceof \DOMDocument);
 
         $entityElement = self::findEntityDescriptor($document);
 
@@ -262,12 +266,12 @@ class SimpleSAML_Metadata_SAMLParser
      * @param \SAML2\XML\md\EntityDescriptor $entityElement A \SAML2\XML\md\EntityDescriptor object which represents a
      *     EntityDescriptor element.
      *
-     * @return SimpleSAML_Metadata_SAMLParser An instance of this class with the metadata loaded.
+     * @return SAMLParser An instance of this class with the metadata loaded.
      */
     public static function parseElement($entityElement)
     {
         assert($entityElement instanceof \SAML2\XML\md\EntityDescriptor);
-        return new SimpleSAML_Metadata_SAMLParser($entityElement, null, array());
+        return new SAMLParser($entityElement, null, array());
     }
 
 
@@ -279,13 +283,13 @@ class SimpleSAML_Metadata_SAMLParser
      *
      * @param string $file The path to the file which contains the EntityDescriptor or EntitiesDescriptor element.
      *
-     * @return SimpleSAML_Metadata_SAMLParser[] An array of SAMLParser instances.
-     * @throws Exception If the file does not parse as XML.
+     * @return SAMLParser[] An array of SAMLParser instances.
+     * @throws \Exception If the file does not parse as XML.
      */
     public static function parseDescriptorsFile($file)
     {
         if ($file === null) {
-            throw new Exception('Cannot open file NULL. File name not specified.');
+            throw new \Exception('Cannot open file NULL. File name not specified.');
         }
 
         $data = \SimpleSAML\Utils\HTTP::fetch($file);
@@ -293,11 +297,11 @@ class SimpleSAML_Metadata_SAMLParser
         try {
             $doc = \SAML2\DOMDocumentFactory::fromString($data);
         } catch (\Exception $e) {
-            throw new Exception('Failed to read XML from file: '.$file);
+            throw new \Exception('Failed to read XML from file: '.$file);
         }
 
         if ($doc->documentElement === null) {
-            throw new Exception('Opened file is not an XML document: '.$file);
+            throw new \Exception('Opened file is not an XML document: '.$file);
         }
 
         return self::parseDescriptorsElement($doc->documentElement);
@@ -311,16 +315,16 @@ class SimpleSAML_Metadata_SAMLParser
      *
      * @param string $string The string with XML data.
      *
-     * @return SimpleSAML_Metadata_SAMLParser[] An associative array of SAMLParser instances. The key of the array will
+     * @return SAMLParser[] An associative array of SAMLParser instances. The key of the array will
      *     be the entity id.
-     * @throws Exception If the string does not parse as XML.
+     * @throws \Exception If the string does not parse as XML.
      */
     public static function parseDescriptorsString($string)
     {
         try {
             $doc = \SAML2\DOMDocumentFactory::fromString($string);
         } catch (\Exception $e) {
-            throw new Exception('Failed to parse XML string.');
+            throw new \Exception('Failed to parse XML string.');
         }
 
         return self::parseDescriptorsElement($doc->documentElement);
@@ -331,25 +335,25 @@ class SimpleSAML_Metadata_SAMLParser
      * This function parses a DOMElement which represents either an EntityDescriptor element or an
      * EntitiesDescriptor element. It will return an associative array of SAMLParser instances in both cases.
      *
-     * @param DOMElement|NULL $element The DOMElement which contains the EntityDescriptor element or the
+     * @param \DOMElement|NULL $element The DOMElement which contains the EntityDescriptor element or the
      *     EntitiesDescriptor element.
      *
-     * @return SimpleSAML_Metadata_SAMLParser[] An associative array of SAMLParser instances. The key of the array will
+     * @return SAMLParser[] An associative array of SAMLParser instances. The key of the array will
      *     be the entity id.
-     * @throws Exception if the document is empty or the root is an unexpected node.
+     * @throws \Exception if the document is empty or the root is an unexpected node.
      */
-    public static function parseDescriptorsElement(DOMElement $element = null)
+    public static function parseDescriptorsElement(\DOMElement $element = null)
     {
         if ($element === null) {
-            throw new Exception('Document was empty.');
+            throw new \Exception('Document was empty.');
         }
 
-        if (SimpleSAML\Utils\XML::isDOMNodeOfType($element, 'EntityDescriptor', '@md') === true) {
+        if (\SimpleSAML\Utils\XML::isDOMNodeOfType($element, 'EntityDescriptor', '@md') === true) {
             return self::processDescriptorsElement(new \SAML2\XML\md\EntityDescriptor($element));
-        } elseif (SimpleSAML\Utils\XML::isDOMNodeOfType($element, 'EntitiesDescriptor', '@md') === true) {
+        } elseif (\SimpleSAML\Utils\XML::isDOMNodeOfType($element, 'EntitiesDescriptor', '@md') === true) {
             return self::processDescriptorsElement(new \SAML2\XML\md\EntitiesDescriptor($element));
         } else {
-            throw new Exception('Unexpected root node: ['.$element->namespaceURI.']:'.$element->localName);
+            throw new \Exception('Unexpected root node: ['.$element->namespaceURI.']:'.$element->localName);
         }
     }
 
@@ -364,7 +368,7 @@ class SimpleSAML_Metadata_SAMLParser
      * @param array                                                         $parentExtensions An optional array of
      *     extensions from the parent element.
      *
-     * @return SimpleSAML_Metadata_SAMLParser[] Array of SAMLParser instances.
+     * @return SAMLParser[] Array of SAMLParser instances.
      */
     private static function processDescriptorsElement(
         $element,
@@ -375,9 +379,9 @@ class SimpleSAML_Metadata_SAMLParser
         assert($maxExpireTime === null || is_int($maxExpireTime));
 
         if ($element instanceof \SAML2\XML\md\EntityDescriptor) {
-            $ret = new SimpleSAML_Metadata_SAMLParser($element, $maxExpireTime, $validators, $parentExtensions);
+            $ret = new SAMLParser($element, $maxExpireTime, $validators, $parentExtensions);
             $ret = array($ret->getEntityId() => $ret);
-            /** @var SimpleSAML_Metadata_SAMLParser[] $ret */
+            /** @var SAMLParser[] $ret */
             return $ret;
         }
 
@@ -490,7 +494,7 @@ class SimpleSAML_Metadata_SAMLParser
             $metadata['EntityAttributes'] = $this->entityAttributes;
 
             // check for entity categories
-            if (SimpleSAML\Utils\Config\Metadata::isHiddenFromDiscovery($metadata)) {
+            if (\SimpleSAML\Utils\Config\Metadata::isHiddenFromDiscovery($metadata)) {
                 $metadata['hide.from.discovery'] = true;
             }
         }
@@ -1025,7 +1029,7 @@ class SimpleSAML_Metadata_SAMLParser
                     // Registration Authority cannot be overridden (warn only if override attempts to change the value)
                     if (isset($ret['RegistrationInfo']['registrationAuthority'])
                         && $ret['RegistrationInfo']['registrationAuthority'] !== $e->registrationAuthority) {
-                        SimpleSAML\Logger::warning('Invalid attempt to override registrationAuthority \''
+                        \SimpleSAML\Logger::warning('Invalid attempt to override registrationAuthority \''
                           . $ret['RegistrationInfo']['registrationAuthority'] . "' with '{$e->registrationAuthority}'");
                     } else {
                         $ret['RegistrationInfo']['registrationAuthority'] = $e->registrationAuthority;
@@ -1115,8 +1119,8 @@ class SimpleSAML_Metadata_SAMLParser
 
                 $name = $attribute->getAttribute('Name');
                 $values = array_map(
-                    array('SimpleSAML\Utils\XML', 'getDOMText'),
-                    SimpleSAML\Utils\XML::getDOMChildren($attribute, 'AttributeValue', '@saml2')
+                    array('\SimpleSAML\Utils\XML', 'getDOMText'),
+                    \SimpleSAML\Utils\XML::getDOMChildren($attribute, 'AttributeValue', '@saml2')
                 );
 
                 if ($name === 'tags') {
@@ -1385,24 +1389,24 @@ class SimpleSAML_Metadata_SAMLParser
      *
      * This function will throw an exception if it is unable to locate the node.
      *
-     * @param DOMDocument $doc The DOMDocument where we should find the EntityDescriptor node.
+     * @param \DOMDocument $doc The \DOMDocument where we should find the EntityDescriptor node.
      *
-     * @return \SAML2\XML\md\EntityDescriptor The DOMEntity which represents the EntityDescriptor.
-     * @throws Exception If the document is empty or the first element is not an EntityDescriptor element.
+     * @return \SAML2\XML\md\EntityDescriptor The \DOMEntity which represents the EntityDescriptor.
+     * @throws \Exception If the document is empty or the first element is not an EntityDescriptor element.
      */
     private static function findEntityDescriptor($doc)
     {
-        assert($doc instanceof DOMDocument);
+        assert($doc instanceof \DOMDocument);
 
         // find the EntityDescriptor DOMElement. This should be the first (and only) child of the DOMDocument
         $ed = $doc->documentElement;
 
         if ($ed === null) {
-            throw new Exception('Failed to load SAML metadata from empty XML document.');
+            throw new \Exception('Failed to load SAML metadata from empty XML document.');
         }
 
-        if (SimpleSAML\Utils\XML::isDOMNodeOfType($ed, 'EntityDescriptor', '@md') === false) {
-            throw new Exception('Expected first element in the metadata document to be an EntityDescriptor element.');
+        if (\SimpleSAML\Utils\XML::isDOMNodeOfType($ed, 'EntityDescriptor', '@md') === false) {
+            throw new \Exception('Expected first element in the metadata document to be an EntityDescriptor element.');
         }
 
         return new \SAML2\XML\md\EntityDescriptor($ed);
@@ -1424,7 +1428,7 @@ class SimpleSAML_Metadata_SAMLParser
             assert(is_string($cert));
             $certFile = \SimpleSAML\Utils\Config::getCertPath($cert);
             if (!file_exists($certFile)) {
-                throw new Exception(
+                throw new \Exception(
                     'Could not find certificate file ['.$certFile.'], which is needed to validate signature'
                 );
             }
@@ -1437,12 +1441,12 @@ class SimpleSAML_Metadata_SAMLParser
                     if ($validator->validate($key)) {
                         return true;
                     }
-                } catch (Exception $e) {
+                } catch (\Exception $e) {
                     // this certificate did not sign this element, skip
                 }
             }
         }
-        SimpleSAML\Logger::debug('Could not validate signature');
+        \SimpleSAML\Logger::debug('Could not validate signature');
         return false;
     }
 
@@ -1472,7 +1476,7 @@ class SimpleSAML_Metadata_SAMLParser
                 }
             }
         }
-        SimpleSAML\Logger::debug('Fingerprint was ['.$fingerprint.'] not one of ['.join(', ', $candidates).']');
+        \SimpleSAML\Logger::debug('Fingerprint was ['.$fingerprint.'] not one of ['.join(', ', $candidates).']');
         return false;
     }
 }
diff --git a/lib/SimpleSAML/Metadata/Signer.php b/lib/SimpleSAML/Metadata/Signer.php
index 25f7a2e42..eb87586ac 100644
--- a/lib/SimpleSAML/Metadata/Signer.php
+++ b/lib/SimpleSAML/Metadata/Signer.php
@@ -1,5 +1,9 @@
 <?php
 
+namespace SimpleSAML\Metadata;
+
+use RobRichards\XMLSecLibs\XMLSecurityKey;
+use RobRichards\XMLSecLibs\XMLSecurityDSig;
 
 /**
  * This class implements a helper function for signing of metadata.
@@ -7,9 +11,9 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Metadata_Signer
-{
 
+class Signer
+{
     /**
      * This functions finds what key & certificate files should be used to sign the metadata
      * for the given entity.
@@ -31,7 +35,7 @@ class SimpleSAML_Metadata_Signer
             if (!array_key_exists('metadata.sign.privatekey', $entityMetadata)
                 || !array_key_exists('metadata.sign.certificate', $entityMetadata)
             ) {
-                throw new Exception(
+                throw new \Exception(
                     'Missing either the "metadata.sign.privatekey" or the'.
                     ' "metadata.sign.certificate" configuration option in the metadata for'.
                     ' the '.$type.' "'.$entityMetadata['entityid'].'". If one of'.
@@ -56,7 +60,7 @@ class SimpleSAML_Metadata_Signer
         $certificate = $config->getString('metadata.sign.certificate', null);
         if ($privatekey !== null || $certificate !== null) {
             if ($privatekey === null || $certificate === null) {
-                throw new Exception(
+                throw new \Exception(
                     'Missing either the "metadata.sign.privatekey" or the'.
                     ' "metadata.sign.certificate" configuration option in the global'.
                     ' configuration. If one of these options is specified, then the other'.
@@ -80,7 +84,7 @@ class SimpleSAML_Metadata_Signer
             if (!array_key_exists('privatekey', $entityMetadata)
                 || !array_key_exists('certificate', $entityMetadata)
             ) {
-                throw new Exception(
+                throw new \Exception(
                     'Both the "privatekey" and the "certificate" option must'.
                     ' be set in the metadata for the '.$type.' "'.
                     $entityMetadata['entityid'].'" before it is possible to sign metadata'.
@@ -100,7 +104,7 @@ class SimpleSAML_Metadata_Signer
             return $ret;
         }
 
-        throw new Exception(
+        throw new \Exception(
             'Could not find what key & certificate should be used to sign the metadata'.
             ' for the '.$type.' "'.$entityMetadata['entityid'].'".'
         );
@@ -116,14 +120,14 @@ class SimpleSAML_Metadata_Signer
      *     'Shib 1.3 SP'.
      *
      * @return boolean True if metadata signing is enabled, false otherwise.
-     * @throws Exception If the value of the 'metadata.sign.enable' option is not a boolean.
+     * @throws \Exception If the value of the 'metadata.sign.enable' option is not a boolean.
      */
     private static function isMetadataSigningEnabled($config, $entityMetadata, $type)
     {
         // first check the metadata for the entity
         if (array_key_exists('metadata.sign.enable', $entityMetadata)) {
             if (!is_bool($entityMetadata['metadata.sign.enable'])) {
-                throw new Exception(
+                throw new \Exception(
                     'Invalid value for the "metadata.sign.enable" configuration option for'.
                     ' the '.$type.' "'.$entityMetadata['entityid'].'". This option'.
                     ' should be a boolean.'
@@ -209,7 +213,7 @@ class SimpleSAML_Metadata_Signer
      * @param string $type A string which describes the type entity this is, e.g. 'SAML 2 IdP' or 'Shib 1.3 SP'.
      *
      * @return string The $metadataString with the signature embedded.
-     * @throws Exception If the certificate or private key cannot be loaded, or the metadata doesn't parse properly.
+     * @throws \Exception If the certificate or private key cannot be loaded, or the metadata doesn't parse properly.
      */
     public static function sign($metadataString, $entityMetadata, $type)
     {
@@ -225,13 +229,13 @@ class SimpleSAML_Metadata_Signer
 
         $keyFile = \SimpleSAML\Utils\Config::getCertPath($keyCertFiles['privatekey']);
         if (!file_exists($keyFile)) {
-            throw new Exception('Could not find private key file ['.$keyFile.'], which is needed to sign the metadata');
+            throw new \Exception('Could not find private key file ['.$keyFile.'], which is needed to sign the metadata');
         }
         $keyData = file_get_contents($keyFile);
 
         $certFile = \SimpleSAML\Utils\Config::getCertPath($keyCertFiles['certificate']);
         if (!file_exists($certFile)) {
-            throw new Exception(
+            throw new \Exception(
                 'Could not find certificate file ['.$certFile.'], which is needed to sign the metadata'
             );
         }
@@ -241,8 +245,8 @@ class SimpleSAML_Metadata_Signer
         // convert the metadata to a DOM tree
         try {
             $xml = \SAML2\DOMDocumentFactory::fromString($metadataString);
-        } catch (Exception $e) {
-            throw new Exception('Error parsing self-generated metadata.');
+        } catch (\Exception $e) {
+            throw new \Exception('Error parsing self-generated metadata.');
         }
 
         $signature_cf = self::getMetadataSigningAlgorithm($config, $entityMetadata, $type);
diff --git a/lib/SimpleSAML/Metadata/Sources/MDQ.php b/lib/SimpleSAML/Metadata/Sources/MDQ.php
index ba61c2cb2..bb0b053f8 100644
--- a/lib/SimpleSAML/Metadata/Sources/MDQ.php
+++ b/lib/SimpleSAML/Metadata/Sources/MDQ.php
@@ -13,9 +13,9 @@ use SimpleSAML\Utils\HTTP;
  * @author Tamas Frank, NIIFI
  * @package SimpleSAMLphp
  */
-class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
-{
 
+class MDQ extends \SimpleSAML\Metadata\MetaDataStorageSource
+{
     /**
      * The URL of MDQ server (url:port)
      *
@@ -216,13 +216,13 @@ class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
     /**
      * Retrieve metadata for the correct set from a SAML2Parser.
      *
-     * @param \SimpleSAML_Metadata_SAMLParser $entity A SAML2Parser representing an entity.
+     * @param \SimpleSAML\Metadata\SAMLParser $entity A SAML2Parser representing an entity.
      * @param string                         $set The metadata set we are looking for.
      *
      * @return array|NULL  The associative array with the metadata, or NULL if no metadata for
      *                     the given set was found.
      */
-    private static function getParsedSet(\SimpleSAML_Metadata_SAMLParser $entity, $set)
+    private static function getParsedSet(\SimpleSAML\Metadata\SAMLParser $entity, $set)
     {
         assert(is_string($set));
 
@@ -248,7 +248,7 @@ class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
 
 
     /**
-     * Overriding this function from the superclass SimpleSAML_Metadata_MetaDataStorageSource.
+     * Overriding this function from the superclass \SimpleSAML\Metadata\MetaDataStorageSource.
      *
      * This function retrieves metadata for the given entity id in the given set of metadata.
      * It will return NULL if it is unable to locate the metadata.
@@ -311,7 +311,7 @@ class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
         }
 
         /** @var string $xmldata */
-        $entity = \SimpleSAML_Metadata_SAMLParser::parseString($xmldata);
+        $entity = \SimpleSAML\Metadata\SAMLParser::parseString($xmldata);
         Logger::debug(__CLASS__.': completed parsing of ['.$mdq_url.']');
 
         if ($this->validateFingerprint !== null) {
diff --git a/lib/SimpleSAML/XHTML/IdPDisco.php b/lib/SimpleSAML/XHTML/IdPDisco.php
index e362ff711..22d815be6 100644
--- a/lib/SimpleSAML/XHTML/IdPDisco.php
+++ b/lib/SimpleSAML/XHTML/IdPDisco.php
@@ -35,7 +35,7 @@ class IdPDisco
     /**
      * An instance of the metadata handler, which will allow us to fetch metadata about IdPs.
      *
-     * @var SimpleSAML_Metadata_MetaDataStorageHandler
+     * @var \SimpleSAML\Metadata\MetaDataStorageHandler
      */
     protected $metadata;
 
@@ -120,7 +120,7 @@ class IdPDisco
 
         // initialize standard classes
         $this->config = \SimpleSAML\Configuration::getInstance();
-        $this->metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $this->metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $this->session = \SimpleSAML\Session::getSessionFromRequest();
         $this->instance = $instance;
         $this->metadataSets = $metadataSets;
diff --git a/lib/SimpleSAML/XML/Shib13/AuthnRequest.php b/lib/SimpleSAML/XML/Shib13/AuthnRequest.php
index f52fea212..e1c83c02f 100644
--- a/lib/SimpleSAML/XML/Shib13/AuthnRequest.php
+++ b/lib/SimpleSAML/XML/Shib13/AuthnRequest.php
@@ -36,7 +36,7 @@ class AuthnRequest
 
     public function createRedirect($destination, $shire)
     {
-        $metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $idpmetadata = $metadata->getMetaDataConfig($destination, 'shib13-idp-remote');
 
         $desturl = $idpmetadata->getDefaultEndpoint('SingleSignOnService', array('urn:mace:shibboleth:1.0:profiles:AuthnRequest'));
diff --git a/lib/SimpleSAML/XML/Shib13/AuthnResponse.php b/lib/SimpleSAML/XML/Shib13/AuthnResponse.php
index f499b7134..c380fa172 100644
--- a/lib/SimpleSAML/XML/Shib13/AuthnResponse.php
+++ b/lib/SimpleSAML/XML/Shib13/AuthnResponse.php
@@ -97,7 +97,7 @@ class AuthnResponse
         $issuer = $this->getIssuer();
 
         // Get the metadata of the issuer
-        $metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $md = $metadata->getMetaDataConfig($issuer, 'shib13-idp-remote');
 
         $publicKeys = $md->getPublicKeys('signing');
@@ -201,7 +201,7 @@ class AuthnResponse
     
     public function getAttributes()
     {
-        $metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $md = $metadata->getMetadata($this->getIssuer(), 'shib13-idp-remote');
         $base64 = isset($md['base64attributes']) ? $md['base64attributes'] : false;
 
diff --git a/modules/adfs/lib/IdP/ADFS.php b/modules/adfs/lib/IdP/ADFS.php
index 0f2d08406..e468ddce4 100644
--- a/modules/adfs/lib/IdP/ADFS.php
+++ b/modules/adfs/lib/IdP/ADFS.php
@@ -13,7 +13,7 @@ class sspmod_adfs_IdP_ADFS
             $requestid = $query['wctx'];
             $issuer = $query['wtrealm'];
 
-            $metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+            $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
             $spMetadata = $metadata->getMetaDataConfig($issuer, 'adfs-sp-remote');
 
             \SimpleSAML\Logger::info('ADFS - IdP.prp: Incoming Authentication request: '.$issuer.' id '.$requestid);
@@ -227,7 +227,7 @@ MSG;
     // accepts an association array, and returns a URL that can be accessed to terminate the association
     public static function getLogoutURL(SimpleSAML_IdP $idp, array $association, $relayState)
     {
-        $metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $spMetadata = $metadata->getMetaDataConfig($association['adfs:entityID'], 'adfs-sp-remote');
         $returnTo = \SimpleSAML\Module::getModuleURL('adfs/idp/prp.php?assocId='.urlencode($association["id"]).'&relayState='.urlencode($relayState));
         return $spMetadata->getValue('prp').'?wa=wsignoutcleanup1.0&wreply='.urlencode($returnTo);
diff --git a/modules/adfs/www/idp/metadata.php b/modules/adfs/www/idp/metadata.php
index ecf822a3d..e78548d32 100644
--- a/modules/adfs/www/idp/metadata.php
+++ b/modules/adfs/www/idp/metadata.php
@@ -2,7 +2,7 @@
 
 // load configuration and metadata
 $config = \SimpleSAML\Configuration::getInstance();
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 if (!$config->getBoolean('enable.adfs-idp', false)) {
     throw new \SimpleSAML\Error\Error('NOACCESS');
@@ -139,7 +139,7 @@ try {
     }
 
     // sign the metadata if enabled
-    $metaxml = SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'ADFS IdP');
+    $metaxml = \SimpleSAML\Metadata\Signer::sign($metaxml, $idpmeta->toArray(), 'ADFS IdP');
 
     if ($output_xhtml) {
         $defaultidp = $config->getString('default-adfs-idp', null);
diff --git a/modules/adfs/www/idp/prp.php b/modules/adfs/www/idp/prp.php
index 6346b8d00..b0705a2c7 100644
--- a/modules/adfs/www/idp/prp.php
+++ b/modules/adfs/www/idp/prp.php
@@ -6,11 +6,11 @@
  * @package SimpleSAMLphp
  */
 
-SimpleSAML\Logger::info('ADFS - IdP.prp: Accessing ADFS IdP endpoint prp');
+\SimpleSAML\Logger::info('ADFS - IdP.prp: Accessing ADFS IdP endpoint prp');
 
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpEntityId = $metadata->getMetaDataCurrentEntityID('adfs-idp-hosted');
-$idp = SimpleSAML_IdP::getById('adfs:' . $idpEntityId);
+$idp = \SimpleSAML_IdP::getById('adfs:' . $idpEntityId);
 
 if (isset($_GET['wa'])) {
     if ($_GET['wa'] === 'wsignout1.0') {
diff --git a/modules/consent/lib/Auth/Process/Consent.php b/modules/consent/lib/Auth/Process/Consent.php
index b4c644aaf..6cf65a241 100644
--- a/modules/consent/lib/Auth/Process/Consent.php
+++ b/modules/consent/lib/Auth/Process/Consent.php
@@ -237,7 +237,7 @@ class sspmod_consent_Auth_Process_Consent extends SimpleSAML_Auth_ProcessingFilt
         $spEntityId = $state['Destination']['entityid'];
         $idpEntityId = $state['Source']['entityid'];
 
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
         /**
          * If the consent module is active on a bridge $state['saml:sp:IdP']
diff --git a/modules/consentAdmin/www/consentAdmin.php b/modules/consentAdmin/www/consentAdmin.php
index 5e8dc0cc1..d9a200151 100644
--- a/modules/consentAdmin/www/consentAdmin.php
+++ b/modules/consentAdmin/www/consentAdmin.php
@@ -102,7 +102,7 @@ $as->requireAuth();
 $attributes = $as->getAttributes();
 
 // Get metadata storage handler
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 /*
  * Get IdP id and metadata
diff --git a/modules/core/www/frontpage_federation.php b/modules/core/www/frontpage_federation.php
index 2e109c340..95d45d114 100644
--- a/modules/core/www/frontpage_federation.php
+++ b/modules/core/www/frontpage_federation.php
@@ -44,7 +44,7 @@ $metadataHosted = array();
 \SimpleSAML\Module::callHooks('metadata_hosted', $metadataHosted);
 
 
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 $metaentries = array('hosted' => $metadataHosted, 'remote' => array() );
 
diff --git a/modules/core/www/idp/logout-iframe-post.php b/modules/core/www/idp/logout-iframe-post.php
index 1e42d84cb..ce4932d7e 100644
--- a/modules/core/www/idp/logout-iframe-post.php
+++ b/modules/core/www/idp/logout-iframe-post.php
@@ -22,7 +22,7 @@ if (!isset($associations[$assocId])) {
 }
 $association = $associations[$assocId];
 
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpMetadata = $idp->getConfig();
 $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
 
diff --git a/modules/core/www/idp/logout-iframe.php b/modules/core/www/idp/logout-iframe.php
index 4e9496720..332b86d63 100644
--- a/modules/core/www/idp/logout-iframe.php
+++ b/modules/core/www/idp/logout-iframe.php
@@ -20,7 +20,7 @@ if ($type !== 'embed') {
 
 $state = \SimpleSAML_Auth_State::loadState($_REQUEST['id'], 'core:Logout-IFrame');
 $idp = \SimpleSAML_IdP::getByState($state);
-$mdh = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$mdh = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 if ($type !== 'init') { // update association state
     foreach ($state['core:Logout-IFrame:Associations'] as $assocId => &$sp) {
diff --git a/modules/core/www/show_metadata.php b/modules/core/www/show_metadata.php
index d91af1d41..2edfd3e78 100644
--- a/modules/core/www/show_metadata.php
+++ b/modules/core/www/show_metadata.php
@@ -20,7 +20,7 @@ if (!in_array(
     throw new Exception('Invalid set');
 }
 
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 $m = $metadata->getMetadata($_REQUEST['entityid'], $_REQUEST['set']);
 
diff --git a/modules/exampleattributeserver/www/attributeserver.php b/modules/exampleattributeserver/www/attributeserver.php
index 9b568511e..75c6944d8 100644
--- a/modules/exampleattributeserver/www/attributeserver.php
+++ b/modules/exampleattributeserver/www/attributeserver.php
@@ -1,6 +1,6 @@
 <?php
 
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 $binding = \SAML2\Binding::getCurrentBinding();
 $query = $binding->receive();
diff --git a/modules/metarefresh/hooks/hook_cron.php b/modules/metarefresh/hooks/hook_cron.php
index cc450c9d4..c4761f928 100644
--- a/modules/metarefresh/hooks/hook_cron.php
+++ b/modules/metarefresh/hooks/hook_cron.php
@@ -36,7 +36,7 @@ function metarefresh_hook_cron(&$croninfo) {
 			$outputDir = $config->resolvePath($outputDir);
 			$outputFormat = $set->getValueValidate('outputFormat', array('flatfile', 'serialize'), 'flatfile');
 
-			$oldMetadataSrc = SimpleSAML_Metadata_MetaDataStorageSource::getSource(array(
+			$oldMetadataSrc = \SimpleSAML\Metadata\MetaDataStorageSource::getSource(array(
 				'type' => $outputFormat,
 				'directory' => $outputDir,
 			));
diff --git a/modules/metarefresh/lib/MetaLoader.php b/modules/metarefresh/lib/MetaLoader.php
index 4d1cf818a..3b88b2bcd 100644
--- a/modules/metarefresh/lib/MetaLoader.php
+++ b/modules/metarefresh/lib/MetaLoader.php
@@ -272,7 +272,7 @@ class sspmod_metarefresh_MetaLoader
         if ($doc->documentElement === null) {
             throw new Exception('Opened file is not an XML document: ' . $source['src']);
         }
-        return SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($doc->documentElement);
+        return \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($doc->documentElement);
     }
 
 
@@ -449,7 +449,7 @@ class sspmod_metarefresh_MetaLoader
     {
         assert(is_string($outputDir));
 
-        $metaHandler = new SimpleSAML_Metadata_MetaDataStorageHandlerSerialize(array('directory' => $outputDir));
+        $metaHandler = new \SimpleSAML\Metadata\MetaDataStorageHandlerSerialize(array('directory' => $outputDir));
 
         /* First we add all the metadata entries to the metadata handler. */
         foreach ($this->metadata as $set => $elements) {
diff --git a/modules/negotiate/www/retry.php b/modules/negotiate/www/retry.php
index 7b0351b76..ee792df4d 100644
--- a/modules/negotiate/www/retry.php
+++ b/modules/negotiate/www/retry.php
@@ -10,7 +10,7 @@
 
 $state = \SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], sspmod_negotiate_Auth_Source_Negotiate::STAGEID);
 
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpid = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted', 'metaindex');
 $idpmeta = $metadata->getMetaData($idpid, 'saml20-idp-hosted');
 
diff --git a/modules/saml/lib/Auth/Source/SP.php b/modules/saml/lib/Auth/Source/SP.php
index d38bbd172..b1a59d31d 100644
--- a/modules/saml/lib/Auth/Source/SP.php
+++ b/modules/saml/lib/Auth/Source/SP.php
@@ -109,7 +109,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
                 ' because it isn\'t a valid IdP for this SP.');
         }
 
-        $metadataHandler = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadataHandler = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
         // First, look in saml20-idp-remote.
         try {
@@ -393,7 +393,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
 
         if (isset($state['saml:IDPList']) && sizeof($state['saml:IDPList']) > 0) {
             // we have a SAML IDPList (we are a proxy): filter the list of IdPs available
-            $mdh = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+            $mdh = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
             $known_idps = $mdh->getList();
             $intersection = array_intersect($state['saml:IDPList'], array_keys($known_idps));
 
@@ -458,7 +458,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
              * First, check if we recognize any of the IdPs requested.
              */
 
-            $mdh = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+            $mdh = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
             $known_idps = $mdh->getList();
             $intersection = array_intersect($state['saml:IDPList'], array_keys($known_idps));
 
diff --git a/modules/saml/lib/IdP/SAML1.php b/modules/saml/lib/IdP/SAML1.php
index a1b688951..2f5d81b29 100644
--- a/modules/saml/lib/IdP/SAML1.php
+++ b/modules/saml/lib/IdP/SAML1.php
@@ -36,7 +36,7 @@ class sspmod_saml_IdP_SAML1
         $idpMetadata = $idp->getConfig();
 
         $config = \SimpleSAML\Configuration::getInstance();
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
         $statsData = array(
             'spEntityID' => $spEntityId,
@@ -91,9 +91,9 @@ class sspmod_saml_IdP_SAML1
             $target = null;
         }
 
-        SimpleSAML\Logger::info('Shib1.3 - IdP.SSOService: Got incoming Shib authnRequest from ' . var_export($spEntityId, true) . '.');
+        \SimpleSAML\Logger::info('Shib1.3 - IdP.SSOService: Got incoming Shib authnRequest from ' . var_export($spEntityId, true) . '.');
 
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $spMetadata = $metadata->getMetaDataConfig($spEntityId, 'shib13-sp-remote');
 
         $found = false;
@@ -108,7 +108,7 @@ class sspmod_saml_IdP_SAML1
             break;
         }
         if (!$found) {
-            throw new Exception('Invalid AssertionConsumerService for SP ' .
+            throw new \Exception('Invalid AssertionConsumerService for SP ' .
                 var_export($spEntityId, true) . ': ' . var_export($shire, true));
         }
 
diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php
index 0aa15b664..6e7084773 100644
--- a/modules/saml/lib/IdP/SAML2.php
+++ b/modules/saml/lib/IdP/SAML2.php
@@ -2,6 +2,7 @@
 
 use RobRichards\XMLSecLibs\XMLSecurityKey;
 use SimpleSAML\Configuration;
+use SimpleSAML\Logger;
 use SAML2\SOAP;
 
 /**
@@ -31,14 +32,14 @@ class sspmod_saml_IdP_SAML2
             '$metadata['.var_export($spEntityId, true).']'
         );
 
-        SimpleSAML\Logger::info('Sending SAML 2.0 Response to '.var_export($spEntityId, true));
+        Logger::info('Sending SAML 2.0 Response to '.var_export($spEntityId, true));
 
         $requestId = $state['saml:RequestId'];
         $relayState = $state['saml:RelayState'];
         $consumerURL = $state['saml:ConsumerURL'];
         $protocolBinding = $state['saml:Binding'];
 
-        $idp = SimpleSAML_IdP::getByState($state);
+        $idp = \SimpleSAML_IdP::getByState($state);
 
         $idpMetadata = $idp->getConfig();
 
@@ -78,7 +79,7 @@ class sspmod_saml_IdP_SAML2
         if (isset($state['saml:AuthnRequestReceivedAt'])) {
             $statsData['logintime'] = microtime(true) - $state['saml:AuthnRequestReceivedAt'];
         }
-        SimpleSAML_Stats::log('saml:idp:Response', $statsData);
+        \SimpleSAML_Stats::log('saml:idp:Response', $statsData);
 
         // send the response
         $binding = \SAML2\Binding::getBinding($protocolBinding);
@@ -118,8 +119,8 @@ class sspmod_saml_IdP_SAML2
 
         $error = \sspmod_saml_Error::fromException($exception);
 
-        SimpleSAML\Logger::warning("Returning error to SP with entity ID '".var_export($spEntityId, true)."'.");
-        $exception->log(SimpleSAML\Logger::WARNING);
+        Logger::warning("Returning error to SP with entity ID '".var_export($spEntityId, true)."'.");
+        $exception->log(Logger::WARNING);
 
         $ar = self::buildResponse($idpMetadata, $spMetadata, $consumerURL);
         $ar->setInResponseTo($requestId);
@@ -141,7 +142,7 @@ class sspmod_saml_IdP_SAML2
         if (isset($state['saml:AuthnRequestReceivedAt'])) {
             $statsData['logintime'] = microtime(true) - $state['saml:AuthnRequestReceivedAt'];
         }
-        SimpleSAML_Stats::log('saml:idp:Response:error', $statsData);
+        \SimpleSAML_Stats::log('saml:idp:Response:error', $statsData);
 
         $binding = \SAML2\Binding::getBinding($protocolBinding);
         $binding->send($ar);
@@ -161,7 +162,7 @@ class sspmod_saml_IdP_SAML2
      */
     private static function getAssertionConsumerService(
         array $supportedBindings,
-        Configuration $spMetadata,
+        \SimpleSAML\Configuration $spMetadata,
         $AssertionConsumerServiceURL,
         $ProtocolBinding,
         $AssertionConsumerServiceIndex
@@ -221,15 +222,15 @@ class sspmod_saml_IdP_SAML2
             return $firstFalse;
         }
 
-        SimpleSAML\Logger::warning('Authentication request specifies invalid AssertionConsumerService:');
+        Logger::warning('Authentication request specifies invalid AssertionConsumerService:');
         if ($AssertionConsumerServiceURL !== null) {
-            SimpleSAML\Logger::warning('AssertionConsumerServiceURL: '.var_export($AssertionConsumerServiceURL, true));
+            Logger::warning('AssertionConsumerServiceURL: '.var_export($AssertionConsumerServiceURL, true));
         }
         if ($ProtocolBinding !== null) {
-            SimpleSAML\Logger::warning('ProtocolBinding: '.var_export($ProtocolBinding, true));
+            Logger::warning('ProtocolBinding: '.var_export($ProtocolBinding, true));
         }
         if ($AssertionConsumerServiceIndex !== null) {
-            SimpleSAML\Logger::warning(
+            Logger::warning(
                 'AssertionConsumerServiceIndex: '.var_export($AssertionConsumerServiceIndex, true)
             );
         }
@@ -247,7 +248,7 @@ class sspmod_saml_IdP_SAML2
      */
     public static function receiveAuthnRequest(SimpleSAML_IdP $idp)
     {
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $idpMetadata = $idp->getConfig();
 
         $supportedBindings = array(\SAML2\Constants::BINDING_HTTP_POST);
@@ -311,7 +312,7 @@ class sspmod_saml_IdP_SAML2
 
             $idpInit = true;
 
-            SimpleSAML\Logger::info(
+            Logger::info(
                 'SAML2.0 - IdP.SSOService: IdP initiated authentication: '.var_export($spEntityId, true)
             );
         } else {
@@ -365,7 +366,7 @@ class sspmod_saml_IdP_SAML2
 
             $idpInit = false;
 
-            SimpleSAML\Logger::info(
+            Logger::info(
                 'SAML2.0 - IdP.SSOService: incoming authentication request: '.var_export($spEntityId, true)
             );
         }
@@ -442,7 +443,7 @@ class sspmod_saml_IdP_SAML2
     public static function processSOAPAuthnRequest(array &$state)
     {
         if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
-            SimpleSAML\Logger::error("ECP AuthnRequest did not contain Basic Authentication header");
+            Logger::error("ECP AuthnRequest did not contain Basic Authentication header");
             // TODO Throw some sort of ECP-specific exception / convert this to SOAP fault
             throw new \SimpleSAML\Error\Error("WRONGUSERPASS");
         }
@@ -462,9 +463,9 @@ class sspmod_saml_IdP_SAML2
     {
         assert(is_string($relayState) || $relayState === null);
 
-        SimpleSAML\Logger::info('Sending SAML 2.0 LogoutRequest to: '.var_export($association['saml:entityID'], true));
+        Logger::info('Sending SAML 2.0 LogoutRequest to: '.var_export($association['saml:entityID'], true));
 
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $idpMetadata = $idp->getConfig();
         $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
 
@@ -502,7 +503,7 @@ class sspmod_saml_IdP_SAML2
 
         $spEntityId = $state['saml:SPEntityId'];
 
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $idpMetadata = $idp->getConfig();
         $spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-remote');
 
@@ -516,10 +517,10 @@ class sspmod_saml_IdP_SAML2
                 'Code'    => \SAML2\Constants::STATUS_SUCCESS,
                 'SubCode' => \SAML2\Constants::STATUS_PARTIAL_LOGOUT,
             ));
-            SimpleSAML\Logger::info('Sending logout response for partial logout to SP '.var_export($spEntityId, true));
+            Logger::info('Sending logout response for partial logout to SP '.var_export($spEntityId, true));
         } else {
             $partial = false;
-            SimpleSAML\Logger::debug('Sending logout response to SP '.var_export($spEntityId, true));
+            Logger::debug('Sending logout response to SP '.var_export($spEntityId, true));
         }
 
         SimpleSAML_Stats::log('saml:idp:LogoutResponse:sent', array(
@@ -563,14 +564,14 @@ class sspmod_saml_IdP_SAML2
             throw new \SimpleSAML\Error\BadRequest('Received message on logout endpoint without issuer.');
         }
 
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $idpMetadata = $idp->getConfig();
         $spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-remote');
 
         sspmod_saml_Message::validateMessage($spMetadata, $idpMetadata, $message);
 
         if ($message instanceof \SAML2\LogoutResponse) {
-            SimpleSAML\Logger::info('Received SAML 2.0 LogoutResponse from: '.var_export($spEntityId, true));
+            Logger::info('Received SAML 2.0 LogoutResponse from: '.var_export($spEntityId, true));
             $statsData = array(
                 'spEntityID'  => $spEntityId,
                 'idpEntityID' => $idpMetadata->getString('entityid'),
@@ -584,7 +585,7 @@ class sspmod_saml_IdP_SAML2
 
             if (!$message->isSuccess()) {
                 $logoutError = sspmod_saml_Message::getResponseError($message);
-                SimpleSAML\Logger::warning('Unsuccessful logout. Status was: '.$logoutError);
+                Logger::warning('Unsuccessful logout. Status was: '.$logoutError);
             } else {
                 $logoutError = null;
             }
@@ -593,14 +594,14 @@ class sspmod_saml_IdP_SAML2
 
             $idp->handleLogoutResponse($assocId, $relayState, $logoutError);
         } elseif ($message instanceof \SAML2\LogoutRequest) {
-            SimpleSAML\Logger::info('Received SAML 2.0 LogoutRequest from: '.var_export($spEntityId, true));
+            Logger::info('Received SAML 2.0 LogoutRequest from: '.var_export($spEntityId, true));
             SimpleSAML_Stats::log('saml:idp:LogoutRequest:recv', array(
                 'spEntityID'  => $spEntityId,
                 'idpEntityID' => $idpMetadata->getString('entityid'),
             ));
 
             $spStatsId = $spMetadata->getString('core:statistics-id', $spEntityId);
-            SimpleSAML\Logger::stats('saml20-idp-SLO spinit '.$spStatsId.' '.$idpMetadata->getString('entityid'));
+            Logger::stats('saml20-idp-SLO spinit '.$spStatsId.' '.$idpMetadata->getString('entityid'));
 
             $state = array(
                 'Responder'       => array('sspmod_saml_IdP_SAML2', 'sendLogoutResponse'),
@@ -630,9 +631,9 @@ class sspmod_saml_IdP_SAML2
     {
         assert(is_string($relayState) || $relayState === null);
 
-        SimpleSAML\Logger::info('Sending SAML 2.0 LogoutRequest to: '.var_export($association['saml:entityID'], true));
+        Logger::info('Sending SAML 2.0 LogoutRequest to: '.var_export($association['saml:entityID'], true));
 
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $idpMetadata = $idp->getConfig();
         $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
 
@@ -668,7 +669,7 @@ class sspmod_saml_IdP_SAML2
      */
     public static function getAssociationConfig(SimpleSAML_IdP $idp, array $association)
     {
-        $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         try {
             return $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
         } catch (Exception $e) {
@@ -697,7 +698,7 @@ class sspmod_saml_IdP_SAML2
             $attribute = $idpMetadata->getString('simplesaml.nameidattribute', null);
             if ($attribute === null) {
                 if (!isset($state['UserID'])) {
-                    SimpleSAML\Logger::error('Unable to generate NameID. Check the userid.attribute option.');
+                    Logger::error('Unable to generate NameID. Check the userid.attribute option.');
                     return null;
                 }
                 $attributeValue = $state['UserID'];
@@ -718,7 +719,7 @@ class sspmod_saml_IdP_SAML2
 
         $attributes = $state['Attributes'];
         if (!array_key_exists($attribute, $attributes)) {
-            SimpleSAML\Logger::error('Unable to add NameID: Missing '.var_export($attribute, true).
+            Logger::error('Unable to add NameID: Missing '.var_export($attribute, true).
                 ' in the attributes of the user.');
             return null;
         }
@@ -1005,7 +1006,7 @@ class sspmod_saml_IdP_SAML2
                    or random id if not assigned/configured */
                 $nameIdValue = self::generateNameIdValue($idpMetadata, $spMetadata, $state);
                 if ($nameIdValue === null) {
-                    SimpleSAML\Logger::warning('Falling back to transient NameID.');
+                    Logger::warning('Falling back to transient NameID.');
                     $nameIdFormat = \SAML2\Constants::NAMEID_TRANSIENT;
                     $nameIdValue = SimpleSAML\Utils\Random::generateID();
                 }
diff --git a/modules/saml/www/idp/certs.php b/modules/saml/www/idp/certs.php
index d9385a8e9..abcffdc98 100644
--- a/modules/saml/www/idp/certs.php
+++ b/modules/saml/www/idp/certs.php
@@ -2,7 +2,7 @@
 
 // Load SimpleSAMLphp, configuration and metadata
 $config = \SimpleSAML\Configuration::getInstance();
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 if (!$config->getBoolean('enable.saml20-idp', false)) {
     throw new \SimpleSAML\Error\Error('NOACCESS');
diff --git a/modules/saml/www/sp/metadata.php b/modules/saml/www/sp/metadata.php
index 2df29bf91..10766a65d 100644
--- a/modules/saml/www/sp/metadata.php
+++ b/modules/saml/www/sp/metadata.php
@@ -257,7 +257,7 @@ if (isset($metaArray20['attributes']) && is_array($metaArray20['attributes'])) {
 }
 
 // sign the metadata if enabled
-$xml = \SimpleSAML_Metadata_Signer::sign($xml, $spconfig->toArray(), 'SAML 2 SP');
+$xml = \SimpleSAML\Metadata\Signer::sign($xml, $spconfig->toArray(), 'SAML 2 SP');
 
 if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] == 'xhtml') {
 
diff --git a/modules/saml/www/sp/saml2-logout.php b/modules/saml/www/sp/saml2-logout.php
index ceafd6c36..f6e2f0e9d 100644
--- a/modules/saml/www/sp/saml2-logout.php
+++ b/modules/saml/www/sp/saml2-logout.php
@@ -14,7 +14,7 @@ $sourceId = substr($_SERVER['PATH_INFO'], 1);
 
 $source = SimpleSAML_Auth_Source::getById($sourceId);
 if ($source === null) {
-    throw new Exception('Could not find authentication source with id ' . $sourceId);
+    throw new \Exception('Could not find authentication source with id ' . $sourceId);
 }
 if (!($source instanceof sspmod_saml_Auth_Source_SP)) {
     throw new \SimpleSAML\Error\Exception('Source type changed?');
@@ -22,7 +22,7 @@ if (!($source instanceof sspmod_saml_Auth_Source_SP)) {
 
 try {
     $binding = \SAML2\Binding::getCurrentBinding();
-} catch (Exception $e) { // TODO: look for a specific exception
+} catch (\Exception $e) { // TODO: look for a specific exception
     // This is dirty. Instead of checking the message of the exception, \SAML2\Binding::getCurrentBinding() should throw
     // an specific exception when the binding is unknown, and we should capture that here
     if ($e->getMessage() === 'Unable to find the current binding.') {
@@ -41,7 +41,7 @@ if ($idpEntityId === null) {
 
 $spEntityId = $source->getEntityId();
 
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpMetadata = $source->getIdPMetadata($idpEntityId);
 $spMetadata = $source->getMetadata();
 
@@ -76,7 +76,7 @@ if ($message instanceof \SAML2\LogoutResponse) {
     if ($message->isNameIdEncrypted()) {
         try {
             $keys = sspmod_saml_Message::getDecryptionKeys($idpMetadata, $spMetadata);
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             throw new \SimpleSAML\Error\Exception('Error decrypting NameID: ' . $e->getMessage());
         }
 
@@ -89,7 +89,7 @@ if ($message instanceof \SAML2\LogoutResponse) {
                 SimpleSAML\Logger::debug('Decryption with key #' . $i . ' succeeded.');
                 $lastException = null;
                 break;
-            } catch (Exception $e) {
+            } catch (\Exception $e) {
                 SimpleSAML\Logger::debug('Decryption with key #' . $i . ' failed with exception: ' . $e->getMessage());
                 $lastException = $e;
             }
diff --git a/modules/statistics/lib/Statistics/FieldPresentation/Entity.php b/modules/statistics/lib/Statistics/FieldPresentation/Entity.php
index 5556d08f8..d41df2696 100644
--- a/modules/statistics/lib/Statistics/FieldPresentation/Entity.php
+++ b/modules/statistics/lib/Statistics/FieldPresentation/Entity.php
@@ -4,7 +4,7 @@ class sspmod_statistics_Statistics_FieldPresentation_Entity extends sspmod_stati
 {
     public function getPresentation()
     {
-        $mh = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $mh = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
         $metadata = $mh->getList($this->config);
 
         $translation = array('_' => 'All services');
diff --git a/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php b/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php
index 35964f2ac..b98f0a8ab 100644
--- a/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php
+++ b/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php
@@ -1,21 +1,21 @@
 <?php
 
-
 /**
  * Class SimpleSAML_Metadata_MetaDataStorageSourceTest
  */
+
 class SimpleSAML_Metadata_MetaDataStorageSourceTest extends PHPUnit_Framework_TestCase
 {
     /**
-     * Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig XML bad source
-     * @expectedException Exception
+     * Test \SimpleSAML\Metadata\MetaDataStorageSourceTest::getConfig XML bad source
+     * @expectedException \Exception
      */
     public function testBadXMLSource() {
-        SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "foo"=>"baa"]);
+        \SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type"=>"xml", "foo"=>"baa"]);
     }
 
     /**
-     * Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig invalid static XML source
+     * Test \SimpleSAML\Metadata\MetaDataStorageSourceTest::getConfig invalid static XML source
      * @expectedException Exception
      */
     public function testInvalidStaticXMLSource() {
@@ -23,11 +23,11 @@ class SimpleSAML_Metadata_MetaDataStorageSourceTest extends PHPUnit_Framework_Te
 <EntityDescriptor ID=\"_12345678-90ab-cdef-1234-567890abcdef\" entityID=\"https://saml.idp/entityid\" xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\">
 </EntityDescriptor>
 ";
-        SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "xml"=>$strTestXML]);
+        \SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type"=>"xml", "xml"=>$strTestXML]);
     }
 
     /**
-     * Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig XML static XML source
+     * Test \SimpleSAML\Metadata\MetaDataStorageSourceTest::getConfig XML static XML source
      */
     public function testStaticXMLSource() {
         $testEntityId = "https://saml.idp/entityid";
@@ -47,7 +47,7 @@ xmlns:fed=\"http://docs.oasis-open.org/wsfed/federation/200706\">
 ";
         // The primary test here is that - in contrast to the others above - this loads without error
         // As a secondary thing, check that the entity ID from the static source provided can be extracted
-        $source = SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "xml"=>$strTestXML]);
+        $source = \SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type"=>"xml", "xml"=>$strTestXML]);
         $idpSet = $source->getMetadataSet("saml20-idp-remote");
         $this->assertArrayHasKey($testEntityId, $idpSet,  "Did not extract expected IdP entity ID from static XML source");
 	// Finally verify that a different entity ID does not get loaded
diff --git a/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php b/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php
index 0e34ad063..0a8254598 100644
--- a/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php
+++ b/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace SimpleSAML\Metadata;
 
 use PHPUnit\Framework\TestCase;
@@ -32,7 +33,7 @@ XML
         );
 
 
-        $entities = \SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($document->documentElement);
+        $entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($document->documentElement);
         $this->assertArrayHasKey('theEntityID', $entities);
         // RegistrationInfo is accessible in the SP or IDP metadata accessors
         $metadata = $entities['theEntityID']->getMetadata20SP();
@@ -74,7 +75,7 @@ XML
 XML
         );
 
-        $entities = \SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($document->documentElement);
+        $entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($document->documentElement);
         $this->assertArrayHasKey('theEntityID', $entities);
         $this->assertArrayHasKey('subEntityId', $entities);
         // RegistrationInfo is accessible in the SP or IDP metadata accessors
@@ -116,7 +117,7 @@ XML
 XML
         );
 
-        $entities = \SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($document->documentElement);
+        $entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($document->documentElement);
         $this->assertArrayHasKey('theEntityID', $entities);
 
         $metadata = $entities['theEntityID']->getMetadata20SP();
diff --git a/www/admin/metadata-converter.php b/www/admin/metadata-converter.php
index 7fba906da..db3114fb4 100644
--- a/www/admin/metadata-converter.php
+++ b/www/admin/metadata-converter.php
@@ -15,7 +15,7 @@ if (!empty($_FILES['xmlfile']['tmp_name'])) {
 
 if (!empty($xmldata)) {
     \SimpleSAML\Utils\XML::checkSAMLMessage($xmldata, 'saml-meta');
-    $entities = \SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($xmldata);
+    $entities = \SimpleSAML\Metadata\SAMLParser::parseDescriptorsString($xmldata);
 
     // get all metadata for the entities
     foreach ($entities as &$entity) {
diff --git a/www/saml2/idp/ArtifactResolutionService.php b/www/saml2/idp/ArtifactResolutionService.php
index 65602126b..59e3a0f77 100644
--- a/www/saml2/idp/ArtifactResolutionService.php
+++ b/www/saml2/idp/ArtifactResolutionService.php
@@ -15,7 +15,7 @@ if (!$config->getBoolean('enable.saml20-idp', false)) {
     throw new \SimpleSAML\Error\Error('NOACCESS');
 }
 
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
 $idpMetadata = $metadata->getMetaDataConfig($idpEntityId, 'saml20-idp-hosted');
 
diff --git a/www/saml2/idp/SSOService.php b/www/saml2/idp/SSOService.php
index 479e6557a..55bf4cfb6 100644
--- a/www/saml2/idp/SSOService.php
+++ b/www/saml2/idp/SSOService.php
@@ -13,13 +13,13 @@ require_once('../../_include.php');
 
 \SimpleSAML\Logger::info('SAML2.0 - IdP.SSOService: Accessing SAML 2.0 IdP endpoint SSOService');
 
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
 $idp = \SimpleSAML_IdP::getById('saml2:' . $idpEntityId);
 
 try {
-    sspmod_saml_IdP_SAML2::receiveAuthnRequest($idp);
-} catch (Exception $e) {
+    \sspmod_saml_IdP_SAML2::receiveAuthnRequest($idp);
+} catch (\Exception $e) {
     if ($e->getMessage() === "Unable to find the current binding.") {
         throw new \SimpleSAML\Error\Error('SSOPARAMS', $e, 400);
     } else {
diff --git a/www/saml2/idp/SingleLogoutService.php b/www/saml2/idp/SingleLogoutService.php
index 15164f2ed..90a0a38f0 100644
--- a/www/saml2/idp/SingleLogoutService.php
+++ b/www/saml2/idp/SingleLogoutService.php
@@ -12,7 +12,7 @@ require_once('../../_include.php');
 
 \SimpleSAML\Logger::info('SAML2.0 - IdP.SingleLogoutService: Accessing SAML 2.0 IdP endpoint SingleLogoutService');
 
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
 $idp = \SimpleSAML_IdP::getById('saml2:'.$idpEntityId);
 
@@ -21,7 +21,7 @@ if (isset($_REQUEST['ReturnTo'])) {
 } else {
     try {
         sspmod_saml_IdP_SAML2::receiveLogoutMessage($idp);
-    } catch (Exception $e) { // TODO: look for a specific exception
+    } catch (\Exception $e) { // TODO: look for a specific exception
         /*
          * This is dirty. Instead of checking the message of the exception, \SAML2\Binding::getCurrentBinding() should
          * throw an specific exception when the binding is unknown, and we should capture that here
@@ -33,4 +33,4 @@ if (isset($_REQUEST['ReturnTo'])) {
         }
     }
 }
-assert(FALSE);
+assert(false);
diff --git a/www/saml2/idp/initSLO.php b/www/saml2/idp/initSLO.php
index 92ae9467a..6ab7cd5b1 100644
--- a/www/saml2/idp/initSLO.php
+++ b/www/saml2/idp/initSLO.php
@@ -2,7 +2,7 @@
 
 require_once('../../_include.php');
 
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
 $idp = \SimpleSAML_IdP::getById('saml2:'.$idpEntityId);
 
diff --git a/www/saml2/idp/metadata.php b/www/saml2/idp/metadata.php
index 783ea37c7..c79485129 100644
--- a/www/saml2/idp/metadata.php
+++ b/www/saml2/idp/metadata.php
@@ -10,7 +10,7 @@ use SimpleSAML\Utils\Config\Metadata as Metadata;
 
 // load SimpleSAMLphp configuration and metadata
 $config = \SimpleSAML\Configuration::getInstance();
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 if (!$config->getBoolean('enable.saml20-idp', false)) {
     throw new \SimpleSAML\Error\Error('NOACCESS');
@@ -210,7 +210,7 @@ try {
     $metaflat = '$metadata['.var_export($idpentityid, true).'] = '.var_export($metaArray, true).';';
 
     // sign the metadata if enabled
-    $metaxml = \SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');
+    $metaxml = \SimpleSAML\Metadata\Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');
 
     if (array_key_exists('output', $_GET) && $_GET['output'] == 'xhtml') {
         $defaultidp = $config->getString('default-saml20-idp', null);
diff --git a/www/shib13/idp/SSOService.php b/www/shib13/idp/SSOService.php
index 1a65ab18f..2055d3985 100644
--- a/www/shib13/idp/SSOService.php
+++ b/www/shib13/idp/SSOService.php
@@ -12,7 +12,7 @@ require_once '../../_include.php';
 
 SimpleSAML\Logger::info('Shib1.3 - IdP.SSOService: Accessing Shibboleth 1.3 IdP endpoint SSOService');
 
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpEntityId = $metadata->getMetaDataCurrentEntityID('shib13-idp-hosted');
 $idp = SimpleSAML_IdP::getById('saml1:' . $idpEntityId);
 sspmod_saml_IdP_SAML1::receiveAuthnRequest($idp);
diff --git a/www/shib13/idp/metadata.php b/www/shib13/idp/metadata.php
index cc862557a..060ba6bcd 100644
--- a/www/shib13/idp/metadata.php
+++ b/www/shib13/idp/metadata.php
@@ -4,7 +4,7 @@ require_once('../../_include.php');
 
 // load configuration and metadata
 $config = \SimpleSAML\Configuration::getInstance();
-$metadata = \SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 if (!$config->getBoolean('enable.shib13-idp', false)) {
     throw new \SimpleSAML\Error\Error('NOACCESS');
@@ -80,7 +80,7 @@ try {
     $metaxml = $metaBuilder->getEntityDescriptorText();
 
     // sign the metadata if enabled
-    $metaxml = \SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'Shib 1.3 IdP');
+    $metaxml = \SimpleSAML\Metadata\Signer::sign($metaxml, $idpmeta->toArray(), 'Shib 1.3 IdP');
 
     if (array_key_exists('output', $_GET) && $_GET['output'] == 'xhtml') {
         $defaultidp = $config->getString('default-shib13-idp', null);
-- 
GitLab