From ba8a620c59d75f11e11710099214d8e7cea1a083 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Thu, 31 May 2018 14:30:30 +0200
Subject: [PATCH] Replace SimpleSAML_Auth_* with namespaced version

---
 docs/simplesamlphp-authproc.md                |  8 +-
 docs/simplesamlphp-authsource.md              | 14 ++--
 docs/simplesamlphp-errorhandling.md           | 80 +++++++++---------
 docs/simplesamlphp-sp-api.md                  |  2 +-
 lib/SimpleSAML/Auth/Default.php               | 37 ++++----
 lib/SimpleSAML/Auth/LDAP.php                  | 84 ++++++++++---------
 lib/SimpleSAML/Auth/ProcessingChain.php       | 62 +++++++-------
 lib/SimpleSAML/Auth/ProcessingFilter.php      |  7 +-
 lib/SimpleSAML/Auth/Simple.php                | 12 +--
 lib/SimpleSAML/Auth/Source.php                | 76 ++++++++---------
 lib/SimpleSAML/Auth/SourceFactory.php         |  4 +-
 lib/SimpleSAML/Auth/State.php                 | 51 +++++------
 lib/SimpleSAML/Auth/TimeLimitedToken.php      |  2 +-
 lib/SimpleSAML/AuthMemCookie.php              |  6 +-
 .../Error/UnserializableException.php         |  2 +-
 lib/SimpleSAML/IdP.php                        | 12 +--
 lib/SimpleSAML/IdP/IFrameLogoutHandler.php    |  2 +-
 .../IdP/TraditionalLogoutHandler.php          |  4 +-
 lib/SimpleSAML/Utilities.php                  |  4 +-
 lib/SimpleSAML/Utils/Auth.php                 |  2 +-
 .../lib/Auth/Process/ExpiryWarning.php        |  8 +-
 .../authX509/lib/Auth/Source/X509userCert.php |  4 +-
 modules/authX509/www/expirywarning.php        |  4 +-
 .../lib/Auth/Process/OTP2YubiPrefix.php       |  2 +-
 .../authYubiKey/lib/Auth/Source/YubiKey.php   | 10 +--
 .../authfacebook/lib/Auth/Source/Facebook.php | 10 +--
 modules/authfacebook/lib/Facebook.php         |  2 +-
 modules/authfacebook/www/linkback.php         | 28 +++----
 .../authlinkedin/lib/Auth/Source/LinkedIn.php |  6 +-
 modules/authlinkedin/www/linkback.php         | 16 ++--
 .../authorize/lib/Auth/Process/Authorize.php  |  6 +-
 modules/authorize/www/authorize_403.php       |  2 +-
 .../authtwitter/lib/Auth/Source/Twitter.php   |  6 +-
 modules/authtwitter/www/linkback.php          | 28 +++----
 .../lib/Auth/Source/LiveID.php                |  4 +-
 modules/authwindowslive/www/linkback.php      | 14 ++--
 modules/cas/lib/Auth/Source/CAS.php           | 14 ++--
 modules/cas/www/linkback.php                  |  4 +-
 modules/cdc/lib/Auth/Process/CDC.php          |  6 +-
 modules/cdc/www/resume.php                    |  4 +-
 modules/consent/lib/Auth/Process/Consent.php  |  4 +-
 modules/consent/www/getconsent.php            |  4 +-
 modules/consent/www/logout.php                |  2 +-
 modules/consent/www/noconsent.php             |  2 +-
 modules/consentAdmin/www/consentAdmin.php     |  2 +-
 .../core/lib/Auth/Process/AttributeAdd.php    |  2 +-
 .../core/lib/Auth/Process/AttributeAlter.php  |  2 +-
 .../core/lib/Auth/Process/AttributeCopy.php   |  3 +-
 .../core/lib/Auth/Process/AttributeLimit.php  |  3 +-
 .../core/lib/Auth/Process/AttributeMap.php    |  5 +-
 .../core/lib/Auth/Process/AttributeRealm.php  |  3 +-
 .../lib/Auth/Process/AttributeValueMap.php    |  4 +-
 modules/core/lib/Auth/Process/Cardinality.php |  7 +-
 .../lib/Auth/Process/CardinalitySingle.php    |  5 +-
 .../lib/Auth/Process/ExtendIdPSession.php     |  3 +-
 .../core/lib/Auth/Process/GenerateGroups.php  |  4 +-
 .../core/lib/Auth/Process/LanguageAdaptor.php |  3 +-
 modules/core/lib/Auth/Process/PHP.php         |  2 +-
 .../core/lib/Auth/Process/ScopeAttribute.php  |  3 +-
 .../lib/Auth/Process/ScopeFromAttribute.php   |  4 +-
 .../Auth/Process/StatisticsWithAttribute.php  |  3 +-
 modules/core/lib/Auth/Process/TargetedID.php  |  4 +-
 .../lib/Auth/Process/WarnShortSSOInterval.php |  7 +-
 modules/core/lib/Auth/UserPassBase.php        | 10 +--
 modules/core/lib/Auth/UserPassOrgBase.php     | 14 ++--
 modules/core/www/authenticate.php             | 10 +--
 modules/core/www/cardinality_error.php        |  2 +-
 modules/core/www/idp/logout-iframe-done.php   |  2 +-
 modules/core/www/idp/logout-iframe.php        |  4 +-
 modules/core/www/idp/resumelogout.php         |  2 +-
 modules/core/www/loginuserpass.php            |  6 +-
 modules/core/www/loginuserpassorg.php         |  4 +-
 modules/core/www/short_sso_interval.php       |  5 +-
 .../lib/Auth/Process/RedirectTest.php         |  9 +-
 .../exampleauth/lib/Auth/Source/External.php  | 20 +++--
 .../exampleauth/lib/Auth/Source/Static.php    |  4 +-
 .../exampleauth/lib/Auth/Source/UserPass.php  |  4 +-
 modules/exampleauth/www/authpage.php          |  2 +-
 modules/exampleauth/www/redirecttest.php      |  4 +-
 modules/exampleauth/www/resume.php            |  1 +
 .../lib/Auth/Process/ExpiryDate.php           |  6 +-
 modules/expirycheck/www/about2expire.php      |  4 +-
 modules/expirycheck/www/expired.php           |  2 +-
 .../lib/Auth/Process/AttributeAddFromLDAP.php |  2 +-
 modules/ldap/lib/Auth/Process/BaseFilter.php  |  8 +-
 modules/ldap/lib/ConfigHelper.php             |  6 +-
 .../multiauth/lib/Auth/Source/MultiAuth.php   | 18 ++--
 modules/multiauth/www/selectsource.php        |  8 +-
 modules/negotiate/docs/negotiate.md           | 18 ++--
 .../negotiate/lib/Auth/Source/Negotiate.php   | 16 ++--
 modules/negotiate/www/backend.php             |  4 +-
 modules/negotiate/www/retry.php               |  4 +-
 modules/oauth/www/registry.edit.php           |  2 +-
 modules/oauth/www/registry.php                |  2 +-
 .../lib/Auth/Process/Warning.php              | 12 +--
 modules/preprodwarning/www/showwarning.php    |  4 +-
 modules/saml/hooks/hook_metadata_hosted.php   |  2 +-
 .../lib/Auth/Process/AuthnContextClassRef.php |  2 +-
 .../Process/ExpectedAuthnContextClassRef.php  |  8 +-
 .../saml/lib/Auth/Process/FilterScopes.php    |  2 +-
 .../saml/lib/Auth/Process/NameIDAttribute.php |  2 +-
 .../Process/PersistentNameID2TargetedID.php   |  2 +-
 modules/saml/lib/Auth/Source/SP.php           | 33 ++++----
 modules/saml/lib/BaseNameIDGenerator.php      |  2 +-
 modules/saml/lib/IdP/SAML1.php                |  2 +-
 modules/saml/lib/IdP/SAML2.php                |  4 +-
 modules/saml/www/proxy/invalid_session.php    |  8 +-
 modules/saml/www/sp/discoresp.php             |  4 +-
 modules/saml/www/sp/metadata.php              |  2 +-
 modules/saml/www/sp/saml1-acs.php             |  4 +-
 modules/saml/www/sp/saml2-acs.php             | 14 ++--
 modules/saml/www/sp/saml2-logout.php          | 18 ++--
 .../lib/Auth/Process/SmartID.php              |  2 +-
 .../lib/Auth/Process/SmartName.php            |  3 +-
 tests/lib/SimpleSAML/Auth/SourceTest.php      |  7 +-
 tests/lib/SimpleSAML/Auth/StateTest.php       | 14 ++--
 tests/lib/SimpleSAML/ModuleTest.php           |  4 +-
 117 files changed, 555 insertions(+), 533 deletions(-)

diff --git a/docs/simplesamlphp-authproc.md b/docs/simplesamlphp-authproc.md
index 3b5408396..f65111cff 100644
--- a/docs/simplesamlphp-authproc.md
+++ b/docs/simplesamlphp-authproc.md
@@ -160,16 +160,16 @@ Writing your own Auth Proc Filter
 
 Look at the included *Auth Proc Filters* as examples. Copy the classes into your own module and start playing around.
 
-Authentication processing filters are created by creating a class under `Auth/Process/` in a module. This class is expected to subclass `SimpleSAML_Auth_ProcessingFilter`. A filter must implement at least one function - the `process(&$request)`-function. This function can access the `$request`-array to add, delete and modify attributes, and can also do more advanced processing based on the SP/IdP metadata (which is also included in the `$request`-array). When this function returns, it is assumed that the filter has finished processing.
+Authentication processing filters are created by creating a class under `Auth/Process/` in a module. This class is expected to subclass `\SimpleSAML\Auth\ProcessingFilter`. A filter must implement at least one function - the `process(&$request)`-function. This function can access the `$request`-array to add, delete and modify attributes, and can also do more advanced processing based on the SP/IdP metadata (which is also included in the `$request`-array). When this function returns, it is assumed that the filter has finished processing.
 
-If a filter for some reason needs to redirect the user, for example to show a web page, it should save the current request. Upon completion it should retrieve the request, update it with the changes it is going to make, and call `SimpleSAML_Auth_ProcessingChain::resumeProcessing`. This function will continue processing the next configured filter.
+If a filter for some reason needs to redirect the user, for example to show a web page, it should save the current request. Upon completion it should retrieve the request, update it with the changes it is going to make, and call `\SimpleSAML\Auth\ProcessingChain::resumeProcessing`. This function will continue processing the next configured filter.
 
 Requirements for authentication processing filters:
 
- - Must be derived from the `SimpleSAML_Auth_ProcessingFilter`-class.
+ - Must be derived from the `\SimpleSAML\Auth\ProcessingFilter`-class.
  - If a constructor is implemented, it must first call the parent constructor, passing along all parameters, before accessing any of the parameters. In general, only the $config parameter should be accessed.
  - The `process(&$request)`-function must be implemented. If this function completes, it is assumed that processing is completed, and that the $request array has been updated.
- - If the `process`-function does not return, it must at a later time call `SimpleSAML_Auth_ProcessingChain::resumeProcessing` with the new request state. The request state must be an update of the array passed to the `process`-function.
+ - If the `process`-function does not return, it must at a later time call `\SimpleSAML\Auth\ProcessingChain::resumeProcessing` with the new request state. The request state must be an update of the array passed to the `process`-function.
  - No pages may be shown to the user from the `process`-function. Instead, the request state should be saved, and the user should be redirected to a new page. This must be done to prevent unpredictable events if the user for example reloads the page.
  - No state information should be stored in the filter object. It must instead be stored in the request state array. Any changes to variables in the filter object may be lost.
  - The filter object must be serializable. It may be serialized between being constructed and the call to the `process`-function. This means that, for example, no database connections should be created in the constructor and later used in the `process`-function.
diff --git a/docs/simplesamlphp-authsource.md b/docs/simplesamlphp-authsource.md
index 514b96f36..09a8bb033 100644
--- a/docs/simplesamlphp-authsource.md
+++ b/docs/simplesamlphp-authsource.md
@@ -2,7 +2,7 @@ Creating authentication sources
 ===============================
 
 All authentication sources are located in the `lib/Auth/Source/` directory in a module, and the class name is `sspmod_<module>_Auth_Source_<name>`.
-The authentication source must extend the `SimpleSAML_Auth_Source` class or one of its subclasses.
+The authentication source must extend the `\SimpleSAML\Auth\Source` class or one of its subclasses.
 
 The "entry point" of an authentication source is the `authenticate()`-function.
 Once that function is called, the authentication module can do whatever it wishes to do.
@@ -13,18 +13,18 @@ There are only two requirements:
 
 - Return control to SimpleSAMLphp after authenticating the user.
   If the module is able to authenticate the user without doing any redirects, it should just update the state-array and return.
-  If the module does a redirect, it must call `SimpleSAML_Auth_Source::completeAuth()` with the updated state array.
+  If the module does a redirect, it must call `\SimpleSAML\Auth\Source::completeAuth()` with the updated state array.
 
 Everything else is up to the module.
 If the module needs to redirect the user, for example because it needs to show the user a page asking for credentials, it needs to save the state array.
-For that we have the `SimpleSAML_Auth_State` class.
+For that we have the `\SimpleSAML\Auth\State` class.
 This is only a convenience class, and you are not required to use it (but its use is encouraged, since it handles some potential pitfalls).
 
 
 Saving state
 ------------
 
-The `SimpleSAML_Auth_State` class has two functions that you should use:
+The `\SimpleSAML\Auth\State` class has two functions that you should use:
 `saveState($state, $stage)`, and `loadState($id, $stage)`.
 The `$stage` parameter must be an unique identifier for the current position in the authentication.
 It is used to prevent a malicious user from taking a state you save in one location, and give it to a different location.
@@ -51,7 +51,7 @@ Generic rules & requirements
 ----------------------------
 
 -  
-    Must be derived from the `SimpleSAML_Auth_Source`-class.
+    Must be derived from the `\SimpleSAML\Auth\Source`-class.
 
     **Rationale**:
      - Deriving all authentication sources from a single base class allows us extend all authentication sources by extending the base class.
@@ -62,7 +62,7 @@ Generic rules & requirements
 
     **Rationale**:
      - PHP doesn't automatically call any parent constructor, so it needs to be done manually.
-     - The `$info`-array is used to provide information to the `SimpleSAML_Auth_Source` base class, and therefore needs to be included.
+     - The `$info`-array is used to provide information to the `\SimpleSAML\Auth\Source` base class, and therefore needs to be included.
      - Including the `$config`-array makes it possible to add generic configuration options that are valid for all authentication sources.
 
 -  
@@ -74,7 +74,7 @@ Generic rules & requirements
        This can be used if the authentication doesn't require user input, for example if the authentication can be done based on the IP-address of the user.
 
 -  
-    If the `authenticate`-function does not return, it must at a later time call `SimpleSAML_Auth_Source::completeAuth` with the new state array.
+    If the `authenticate`-function does not return, it must at a later time call `\SimpleSAML\Auth\Source::completeAuth` with the new state array.
     The state array must be an update of the array passed to the `authenticate`-function.
 
     **Rationale**:
diff --git a/docs/simplesamlphp-errorhandling.md b/docs/simplesamlphp-errorhandling.md
index 02195b056..7fbc4f16b 100644
--- a/docs/simplesamlphp-errorhandling.md
+++ b/docs/simplesamlphp-errorhandling.md
@@ -14,7 +14,7 @@ This document describes the way errors and exceptions are handled in authenticat
 The basic goal is to be able to throw an exception during authentication, and then have that exception transported back to the SP in a way that the SP understands.
 
 This means that internal SimpleSAMLphp exceptions must be mapped to transport specific error codes for the various transports that are supported by SimpleSAMLphp.
-E.g.: When a `SimpleSAML_Error_NoPassive` error is thrown by an authentication processing filter in a SAML 2.0 IdP, we want to map that exception to the `urn:oasis:names:tc:SAML:2.0:status:NoPassive` status code.
+E.g.: When a `\SimpleSAML\Error\NoPassive` error is thrown by an authentication processing filter in a SAML 2.0 IdP, we want to map that exception to the `urn:oasis:names:tc:SAML:2.0:status:NoPassive` status code.
 That status code should then be returned to the SP.
 
 
@@ -26,34 +26,34 @@ The simplest case is if you want to throw it during the `authenticate()`-method
 In those methods, you can just throw an exception:
 
     public function process(&$state) {
-        if ($state['something'] === FALSE) {
-            throw new SimpleSAML_Error_Exception('Something is wrong...');
+        if ($state['something'] === false) {
+            throw new \SimpleSAML\Error\Exception('Something is wrong...');
         }
     }
 
 Exceptions thrown at this stage will be caught and delivered to the appropriate error handler.
 
-If you want to throw an exception outside of those methods, i.e. after you have done a redirect, you need to use the `SimpleSAML_Auth_State::throwException()` function:
+If you want to throw an exception outside of those methods, i.e. after you have done a redirect, you need to use the `\SimpleSAML\Auth\State::throwException()` function:
 
     <?php
     $id = $_REQUEST['StateId'];
-    $state = SimpleSAML_Auth_State::loadState($id, 'somestage...');
-    SimpleSAML_Auth_State::throwException($state,
-        new SimpleSAML_Error_Exception('Something is wrong...'));
+    $state = \SimpleSAML\Auth\State::loadState($id, 'somestage...');
+    \SimpleSAML\Auth\State::throwException($state,
+        new \SimpleSAML\Error\Exception('Something is wrong...'));
     ?>
 
-The `SimpleSAML_Auth_State::throwException` function will then transfer your exception to the appropriate error handler.
+The `\SimpleSAML\Auth\State::throwException` function will then transfer your exception to the appropriate error handler.
 
 
 ### Note
 
-Note that we use the `SimpleSAML_Error_Exception` class in both cases.
+Note that we use the `\SimpleSAML\Error\Exception` class in both cases.
 This is because the delivery of the exception may require a redirect to a different web page.
 In those cases, the exception needs to be serialized.
 The normal `Exception` class in PHP isn't always serializable.
 
-If you throw an exception that isn't a subclass of the `SimpleSAML_Error_Exception` class, your exception will be converted to an instance of `SimpleSAML_Error_UnserializableException`.
-The `SimpleSAML_Auth_State::throwException` function does not accept any exceptions that does not subclass the `SimpleSAML_Error_Exception` class.
+If you throw an exception that isn't a subclass of the `\SimpleSAML\Error\Exception` class, your exception will be converted to an instance of `\SimpleSAML\Error\UnserializableException`.
+The `\SimpleSAML\Auth\State::throwException` function does not accept any exceptions that does not subclass the `\SimpleSAML\Error\Exception` class.
 
 
 Returning specific SAML 2 errors
@@ -61,7 +61,7 @@ Returning specific SAML 2 errors
 
 By default, all thrown exceptions will be converted to a generic SAML 2 error.
 In some cases, you may want to convert the exception to a specific SAML 2 status code.
-For example, the `SimpleSAML_Error_NoPassive` exception should be converted to a SAML 2 status code with the following properties:
+For example, the `\SimpleSAML\Error\NoPassive` exception should be converted to a SAML 2 status code with the following properties:
 
 * The top-level status code should be `urn:oasis:names:tc:SAML:2.0:status:Responder`.
 * The second-level status code should be `urn:oasis:names:tc:SAML:2.0:status:NoPassive`.
@@ -97,7 +97,7 @@ This is handled by the `toException()` method in `sspmod_saml_Error`.
 The assertion consumer script of the SAML 2 authentication source (`modules/saml2/sp/acs.php`) uses this method.
 The result is that generic exceptions are thrown from that authentication source.
 
-For example, `NoPassive` errors will be converted back to instances of `SimpleSAML_Error_NoPassive`.
+For example, `NoPassive` errors will be converted back to instances of `\SimpleSAML\Error\NoPassive`.
 
 
 Other protocols
@@ -113,9 +113,9 @@ Technical details
 This section attempts to describe the internals of the error handling framework.
 
 
-### `SimpleSAML_Error_Exception`
+### `\SimpleSAML\Error\Exception`
 
-The `SimpleSAML_Error_Exception` class extends the normal PHP `Exception` class.
+The `\SimpleSAML\Error\Exception` class extends the normal PHP `Exception` class.
 It makes the exceptions serializable by overriding the `__sleep()` method.
 The `__sleep()` method returns all variables in the class which should be serialized when saving the class.
 
@@ -136,7 +136,7 @@ This may be confusing since the new stack trace leads into the `unserialize()` f
 It is therefore recommended to use the getBacktrace() method.
 
 
-### `SimpleSAML_Auth_State`
+### `\SimpleSAML\Auth\State`
 
 There are two methods in this class that deals with exceptions:
 
@@ -147,44 +147,44 @@ There are two methods in this class that deals with exceptions:
 #### `throwException`
 
 This method delivers the exception to the code that initialized the exception handling in the authentication state.
-That would be `SimpleSAML_Auth_Default` for authtentication sources, and `www/saml2/idp/SSOService.php` for processing filters.
+That would be `\SimpleSAML\Auth\DefaultAuth` for authtentication sources, and `www/saml2/idp/SSOService.php` for processing filters.
 To configure how and where the exception should be delivered, there are two fields in the state-array which can be set:
 
-* `SimpleSAML_Auth_State::EXCEPTION_HANDLER_FUNC`, in which case the exception will be delivered by a function call to the function specified in that field.
-* `SimpleSAML_Auth_State::EXCEPTION_HANDLER_URL`, in which case the exception will be delivered by a redirect to the URL specified in that field.
+* `\SimpleSAML\Auth\State::EXCEPTION_HANDLER_FUNC`, in which case the exception will be delivered by a function call to the function specified in that field.
+* `\SimpleSAML\Auth\State::EXCEPTION_HANDLER_URL`, in which case the exception will be delivered by a redirect to the URL specified in that field.
 
 If the exception is delivered by a function call, the function will be called with two parameters: The exception and the state array.
 
-If the exception is delivered by a redirect, SimpleSAML_Auth_State will save the exception in a field in the state array, pass a parameter with the id of the state array to the URL.
-The `SimpleSAML_Auth_State::EXCEPTION_PARAM` constant contains the name of that parameter, while the `SimpleSAML_Auth_State::EXCEPTION_DATA` constant holds the name of the field where the exception is saved.
+If the exception is delivered by a redirect, \SimpleSAML\Auth\State will save the exception in a field in the state array, pass a parameter with the id of the state array to the URL.
+The `\SimpleSAML\Auth\State::EXCEPTION_PARAM` constant contains the name of that parameter, while the `\SimpleSAML\Auth\State::EXCEPTION_DATA` constant holds the name of the field where the exception is saved.
 
 
 #### `loadException`
 
-To retrieve the exception, the application should check for the state parameter in the request, and then retrieve the state array by calling `SimpleSAML_Auth_State::loadExceptionState()`.
-The exception can be located in a field named `SimpleSAML_Auth_State::EXCEPTION_DATA`.
+To retrieve the exception, the application should check for the state parameter in the request, and then retrieve the state array by calling `\SimpleSAML\Auth\State::loadExceptionState()`.
+The exception can be located in a field named `\SimpleSAML\Auth\State::EXCEPTION_DATA`.
 The following code illustrates this behaviour:
 
-    if (array_key_exists(SimpleSAML_Auth_State::EXCEPTION_PARAM, $_REQUEST)) {
-        $state = SimpleSAML_Auth_State::loadExceptionState();
-        $exception = $state[SimpleSAML_Auth_State::EXCEPTION_DATA];
+    if (array_key_exists(\SimpleSAML\Auth\State::EXCEPTION_PARAM, $_REQUEST)) {
+        $state = \SimpleSAML\Auth\State::loadExceptionState();
+        $exception = $state[\SimpleSAML\Auth\State::EXCEPTION_DATA];
 
         /* Process exception. */
     }
 
 
-### `SimpleSAML_Auth_Default`
+### `\SimpleSAML\Auth\DefaultAuth`
 
 This class accepts an `$errorURL` parameter to the `initLogin()` function.
-This parameter is stored in the `SimpleSAML_Auth_State::EXCEPTION_HANDLER_URL` of the state array.
+This parameter is stored in the `\SimpleSAML\Auth\State::EXCEPTION_HANDLER_URL` of the state array.
 Exceptions thrown by the authentication source will be delivered to that URL.
 
 It also wraps the call to the `authenticate()` function inside a try-catch block.
 Any exceptions thrown during that function call will be delivered to the URL specified in the `$errorURL` parameter.
-This is done for consistency, since `SimpleSAML_Auth_Default` never transfers control back to the caller by returning.
+This is done for consistency, since `\SimpleSAML\Auth\DefaultAuth` never transfers control back to the caller by returning.
 
 
-### `SimpleSAML_Auth_ProcessingChain`
+### `\SimpleSAML\Auth\ProcessingChain`
 
 This class requires the caller to add the error handler to the state array before calling the `processState()` function.
 Exceptions thrown by the processing filters will be delivered directly to the caller of `processState()` if possible.
@@ -195,9 +195,9 @@ The result will be delivered directly if it is possible, but if not, it will be
 
 The code for handling this becomes something like:
 
-    if (array_key_exists(SimpleSAML_Auth_State::EXCEPTION_PARAM, $_REQUEST)) {
-        $state = SimpleSAML_Auth_State::loadExceptionState();
-        $exception = $state[SimpleSAML_Auth_State::EXCEPTION_DATA];
+    if (array_key_exists(\SimpleSAML\Auth\State::EXCEPTION_PARAM, $_REQUEST)) {
+        $state = \SimpleSAML\Auth\State::loadExceptionState();
+        $exception = $state[\SimpleSAML\Auth\State::EXCEPTION_DATA];
 
         /* Handle exception... */
         [...]
@@ -206,14 +206,14 @@ The code for handling this becomes something like:
     $procChain = [...];
 
     $state = array(
-        'ReturnURL' => SimpleSAML_Utilities::selfURLNoQuery(),
-        SimpleSAML_Auth_State::EXCEPTION_HANDLER_URL => SimpleSAML_Utilities::selfURLNoQuery(),
+        'ReturnURL' => \SimpleSAML\Utilities::selfURLNoQuery(),
+        \SimpleSAML\Auth\State::EXCEPTION_HANDLER_URL => \SimpleSAML\Utilities::selfURLNoQuery(),
         [...],
     )
 
     try {
         $procChain->processState($state);
-    } catch (SimpleSAML_Error_Exception $e) {
+    } catch (\SimpleSAML\Error\Exception $e) {
         /* Handle exception. */
         [...];
     }
@@ -221,7 +221,7 @@ The code for handling this becomes something like:
 
 #### Note
 
-An exception which isn't a subclass of `SimpleSAML_Error_Exception` will be converted to the `SimpleSAML_Error_UnserializedException` class.
+An exception which isn't a subclass of `\SimpleSAML\Error\Exception` will be converted to the `\SimpleSAML\Error\UnserializedException` class.
 This happens regardless of whether the exception is delivered directly or through the error handler.
 This is done to be consistent in what the application receives - now it will always receive the same exception, regardless of whether it is delivered directly or through a redirect.
 
@@ -229,12 +229,12 @@ This is done to be consistent in what the application receives - now it will alw
 Custom error show function
 --------------------------
 
-Optional custom error show function, called from SimpleSAML_Error_Error::show, is defined with 'errors.show_function' in config.php.
+Optional custom error show function, called from \SimpleSAML\Error\Error::show, is defined with 'errors.show_function' in config.php.
 
-Example code for this function, which implements the same functionality as SimpleSAML_Error_Error::show, looks something like:
+Example code for this function, which implements the same functionality as \SimpleSAML\Error\Error::show, looks something like:
 
     public static function show(\SimpleSAML\Configuration $config, array $data) {
-        $t = new SimpleSAML_XHTML_Template($config, 'error.php', 'errors');
+        $t = new \SimpleSAML\XHTML\Template($config, 'error.php', 'errors');
         $t->data = array_merge($t->data, $data);
         $t->show();
         exit;
diff --git a/docs/simplesamlphp-sp-api.md b/docs/simplesamlphp-sp-api.md
index 2de1b509a..cc43e4bcd 100644
--- a/docs/simplesamlphp-sp-api.md
+++ b/docs/simplesamlphp-sp-api.md
@@ -157,7 +157,7 @@ Same as the previous, but check the result of the logout operation afterwards.
 
 And in logged_out.php:
 
-    $state = SimpleSAML_Auth_State::loadState((string)$_REQUEST['LogoutState'], 'MyLogoutState');
+    $state = \SimpleSAML\Auth\State::loadState((string)$_REQUEST['LogoutState'], 'MyLogoutState');
     $ls = $state['saml:sp:LogoutStatus']; /* Only works for SAML SP */
     if ($ls['Code'] === 'urn:oasis:names:tc:SAML:2.0:status:Success' && !isset($ls['SubCode'])) {
         /* Successful logout. */
diff --git a/lib/SimpleSAML/Auth/Default.php b/lib/SimpleSAML/Auth/Default.php
index e50959bfa..bd698a05c 100644
--- a/lib/SimpleSAML/Auth/Default.php
+++ b/lib/SimpleSAML/Auth/Default.php
@@ -1,5 +1,7 @@
 <?php
 
+namespace SimpleSAML\Auth;
+
 /**
  * Implements the default behaviour for authentication.
  *
@@ -12,10 +14,10 @@
  * @deprecated This class will be removed in SSP 2.0.
  */
 
-class SimpleSAML_Auth_Default
+class DefaultAuth
 {
     /**
-     * @deprecated This method will be removed in SSP 2.0. Use SimpleSAML_Auth_Source::initLogin() instead.
+     * @deprecated This method will be removed in SSP 2.0. Use Source::initLogin() instead.
      */
     public static function initLogin(
         $authId,
@@ -31,21 +33,20 @@ class SimpleSAML_Auth_Default
 
     /**
      * @deprecated This method will be removed in SSP 2.0. Please use
-     * SimpleSAML_Auth_State::getPersistentAuthData() instead.
+     * State::getPersistentAuthData() instead.
      */
     public static function extractPersistentAuthState(array &$state)
     {
-
-        return SimpleSAML_Auth_State::getPersistentAuthData($state);
+        return State::getPersistentAuthData($state);
     }
 
 
     /**
-     * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Auth_Source::loginCompleted() instead.
+     * @deprecated This method will be removed in SSP 2.0. Please use Source::loginCompleted() instead.
      */
     public static function loginCompleted($state)
     {
-        SimpleSAML_Auth_Source::loginCompleted($state);
+        Source::loginCompleted($state);
     }
 
 
@@ -62,10 +63,10 @@ class SimpleSAML_Auth_Default
         $state = $session->getAuthData($authority, 'LogoutState');
         $session->doLogout($authority);
 
-        $state['SimpleSAML_Auth_Default.ReturnURL'] = $returnURL;
+        $state['\SimpleSAML\Auth\DefaultAuth.ReturnURL'] = $returnURL;
         $state['LogoutCompletedHandler'] = array(get_class(), 'logoutCompleted');
 
-        $as = SimpleSAML_Auth_Source::getById($authority);
+        $as = Source::getById($authority);
         if ($as === null) {
             // The authority wasn't an authentication source...
             self::logoutCompleted($state);
@@ -95,18 +96,18 @@ class SimpleSAML_Auth_Default
     public static function logoutCompleted($state)
     {
         assert(is_array($state));
-        assert(array_key_exists('SimpleSAML_Auth_Default.ReturnURL', $state));
+        assert(array_key_exists('\SimpleSAML\Auth\DefaultAuth.ReturnURL', $state));
 
-        \SimpleSAML\Utils\HTTP::redirectTrustedURL($state['SimpleSAML_Auth_Default.ReturnURL']);
+        \SimpleSAML\Utils\HTTP::redirectTrustedURL($state['\SimpleSAML\Auth\DefaultAuth.ReturnURL']);
     }
 
 
     /**
-     * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Auth_Source::logoutCallback() instead.
+     * @deprecated This method will be removed in SSP 2.0. Please use Source::logoutCallback() instead.
      */
     public static function logoutCallback($state)
     {
-        SimpleSAML_Auth_Source::logoutCallback($state);
+        Source::logoutCallback($state);
     }
 
 
@@ -116,7 +117,7 @@ class SimpleSAML_Auth_Default
      */
     public static function handleUnsolicitedAuth($authId, array $state, $redirectTo)
     {
-        sspmod_saml_Auth_Source_SP::handleUnsolicitedAuth($authId, $state, $redirectTo);
+        \sspmod_saml_Auth_Source_SP::handleUnsolicitedAuth($authId, $state, $redirectTo);
     }
 
 
@@ -124,14 +125,14 @@ class SimpleSAML_Auth_Default
      * Return an authentication source by ID.
      *
      * @param string $id The id of the authentication source.
-     * @return SimpleSAML_Auth_Source The authentication source.
-     * @throws Exception If the $id does not correspond with an authentication source.
+     * @return Source The authentication source.
+     * @throws \Exception If the $id does not correspond with an authentication source.
      */
     private static function getAuthSource($id)
     {
-        $as = SimpleSAML_Auth_Source::getById($id);
+        $as = Source::getById($id);
         if ($as === null) {
-            throw new Exception('Invalid authentication source: ' . $id);
+            throw new \Exception('Invalid authentication source: ' . $id);
         }
         return $as;
     }
diff --git a/lib/SimpleSAML/Auth/LDAP.php b/lib/SimpleSAML/Auth/LDAP.php
index 40affecb2..437ff7bf3 100644
--- a/lib/SimpleSAML/Auth/LDAP.php
+++ b/lib/SimpleSAML/Auth/LDAP.php
@@ -1,5 +1,10 @@
 <?php
 
+namespace SimpleSAML\Auth;
+
+use SimpleSAmL\Error;
+use SimpleSAMl\Logger;
+
 /**
  * Constants defining possible errors
  */
@@ -23,7 +28,8 @@ if (!defined('LDAP_OPT_DIAGNOSTIC_MESSAGE')) {
  * @author Anders Lund, UNINETT AS. <anders.lund@uninett.no>
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Auth_LDAP
+
+class LDAP
 {
     /**
      * LDAP link identifier.
@@ -57,7 +63,7 @@ class SimpleSAML_Auth_LDAP
     public function __construct($hostname, $enable_tls = true, $debug = false, $timeout = 0, $port = 389, $referrals = true)
     {
         // Debug
-        SimpleSAML\Logger::debug('Library - LDAP __construct(): Setup LDAP with '.
+        Logger::debug('Library - LDAP __construct(): Setup LDAP with '.
                         'host=\''.$hostname.
                         '\', tls='.var_export($enable_tls, true).
                         ', debug='.var_export($debug, true).
@@ -71,7 +77,7 @@ class SimpleSAML_Auth_LDAP
          * OpenLDAP 2.x.x or Netscape Directory SDK x.x needed for this option.
          */
         if ($debug && !ldap_set_option(null, LDAP_OPT_DEBUG_LEVEL, 7)) {
-                SimpleSAML\Logger::warning('Library - LDAP __construct(): Unable to set debug level (LDAP_OPT_DEBUG_LEVEL) to 7');
+                Logger::warning('Library - LDAP __construct(): Unable to set debug level (LDAP_OPT_DEBUG_LEVEL) to 7');
         }
 
         /*
@@ -98,10 +104,10 @@ class SimpleSAML_Auth_LDAP
         $this->timeout = $timeout;
         if ($timeout > 0) {
             if (!@ldap_set_option($this->ldap, LDAP_OPT_NETWORK_TIMEOUT, $timeout)) {
-                SimpleSAML\Logger::warning('Library - LDAP __construct(): Unable to set timeouts (LDAP_OPT_NETWORK_TIMEOUT) to '.$timeout);
+                Logger::warning('Library - LDAP __construct(): Unable to set timeouts (LDAP_OPT_NETWORK_TIMEOUT) to '.$timeout);
             }
             if (!@ldap_set_option($this->ldap, LDAP_OPT_TIMELIMIT, $timeout)) {
-                SimpleSAML\Logger::warning('Library - LDAP __construct(): Unable to set timeouts (LDAP_OPT_TIMELIMIT) to '.$timeout);
+                Logger::warning('Library - LDAP __construct(): Unable to set timeouts (LDAP_OPT_TIMELIMIT) to '.$timeout);
             }
         }
 
@@ -120,7 +126,7 @@ class SimpleSAML_Auth_LDAP
      *
      * @param string $description
      * The exception's description
-     * @return Exception
+     * @return \Exception
      */
     private function makeException($description, $type = null)
     {
@@ -128,7 +134,7 @@ class SimpleSAML_Auth_LDAP
 
         // Log LDAP code and description, if possible
         if (empty($this->ldap)) {
-            SimpleSAML\Logger::error($description);
+            Logger::error($description);
         } else {
             $errNo = @ldap_errno($this->ldap);
         }
@@ -137,22 +143,22 @@ class SimpleSAML_Auth_LDAP
         if ($type) {
             if ($errNo !== 0) {
                 // Only log real LDAP errors; not success
-                SimpleSAML\Logger::error($description.'; cause: \''.ldap_error($this->ldap).'\' (0x'.dechex($errNo).')');
+                Logger::error($description.'; cause: \''.ldap_error($this->ldap).'\' (0x'.dechex($errNo).')');
             } else {
-                SimpleSAML\Logger::error($description);
+                Logger::error($description);
             }
 
             switch ($type) {
                 case ERR_INTERNAL:// 1 - ExInternal
-                    return new \SimpleSAML\Error\Exception($description, $errNo);
+                    return new Error\Exception($description, $errNo);
                 case ERR_NO_USER:// 2 - ExUserNotFound
-                    return new \SimpleSAML\Error\UserNotFound($description, $errNo);
+                    return new Error\UserNotFound($description, $errNo);
                 case ERR_WRONG_PW:// 3 - ExInvalidCredential
-                    return new \SimpleSAML\Error\InvalidCredential($description, $errNo);
+                    return new Error\InvalidCredential($description, $errNo);
                 case ERR_AS_DATA_INCONSIST:// 4 - ExAsDataInconsist
-                    return new \SimpleSAML\Error\AuthSource('ldap', $description);
+                    return new Error\AuthSource('ldap', $description);
                 case ERR_AS_INTERNAL:// 5 - ExAsInternal
-                    return new \SimpleSAML\Error\AuthSource('ldap', $description);
+                    return new Error\AuthSource('ldap', $description);
             }
         } else {
             if ($errNo !== 0) {
@@ -163,17 +169,17 @@ class SimpleSAML_Auth_LDAP
             }
             switch ($errNo) {
                 case 0x20://LDAP_NO_SUCH_OBJECT
-                    SimpleSAML\Logger::warning($description);
-                    return new \SimpleSAML\Error\UserNotFound($description, $errNo);
+                    Logger::warning($description);
+                    return new Error\UserNotFound($description, $errNo);
                 case 0x31://LDAP_INVALID_CREDENTIALS
-                    SimpleSAML\Logger::info($description);
-                    return new \SimpleSAML\Error\InvalidCredential($description, $errNo);
+                    Logger::info($description);
+                    return new Error\InvalidCredential($description, $errNo);
                 case -1://NO_SERVER_CONNECTION
-                    SimpleSAML\Logger::error($description);
-                    return new \SimpleSAML\Error\AuthSource('ldap', $description);
+                    Logger::error($description);
+                    return new Error\AuthSource('ldap', $description);
                 default:
-                    SimpleSAML\Logger::error($description);
-                    return new \SimpleSAML\Error\AuthSource('ldap', $description);
+                    Logger::error($description);
+                    return new Error\AuthSource('ldap', $description);
             }
         }
     }
@@ -194,16 +200,16 @@ class SimpleSAML_Auth_LDAP
      * @param string $scope
      * @return string
      * The DN of the resulting found element.
-     * @throws \SimpleSAML\Error\Exception if:
+     * @throws Error\Exception if:
      * - Attribute parameter is wrong type
-     * @throws \SimpleSAML\Error\AuthSource if:
+     * @throws Error\AuthSource if:
      * - Not able to connect to LDAP server
      * - False search result
      * - Count return false
      * - Searche found more than one result
      * - Failed to get first entry from result
      * - Failed to get DN for entry
-     * @throws \SimpleSAML\Error\UserNotFound if:
+     * @throws Error\UserNotFound if:
      * - Zero entries were found
      */
     private function search($base, $attribute, $value, $searchFilter = null, $scope = "subtree")
@@ -223,7 +229,7 @@ class SimpleSAML_Auth_LDAP
         }
 
         // Search using generated filter
-        SimpleSAML\Logger::debug('Library - LDAP search(): Searching base ('.$scope.') \''.$base.'\' for \''.$filter.'\'');
+        Logger::debug('Library - LDAP search(): Searching base ('.$scope.') \''.$base.'\' for \''.$filter.'\'');
         if ($scope === 'base') {
             $result = @ldap_read($this->ldap, $base, $filter, array(), 0, 0, $this->timeout, LDAP_DEREF_NEVER);
         } else if ($scope === 'onelevel') {
@@ -282,17 +288,17 @@ class SimpleSAML_Auth_LDAP
      * The DN of the matching element, if found. If no element was found and
      * $allowZeroHits is set to FALSE, an exception will be thrown; otherwise
      * NULL will be returned.
-     * @throws \SimpleSAML\Error\AuthSource if:
+     * @throws Error\AuthSource if:
      * - LDAP search encounter some problems when searching cataloge
      * - Not able to connect to LDAP server
-     * @throws \SimpleSAML\Error\UserNotFound if:
+     * @throws Error\UserNotFound if:
      * - $allowZeroHits is FALSE and no result is found
      *
      */
     public function searchfordn($base, $attribute, $value, $allowZeroHits = false, $searchFilter = null, $scope = 'subtree')
     {
         // Traverse all search bases, returning DN if found
-        $bases = SimpleSAML\Utils\Arrays::arrayize($base);
+        $bases = \SimpleSAML\Utils\Arrays::arrayize($base);
         foreach ($bases as $current) {
             try {
                 // Single base search
@@ -303,12 +309,12 @@ class SimpleSAML_Auth_LDAP
                     return $result;
                 }
                 // If search failed, attempt the other base DNs
-            } catch (\SimpleSAML\Error\UserNotFound $e) {
+            } catch (Error\UserNotFound $e) {
                 // Just continue searching
             }
         }
         // Decide what to do for zero entries
-        SimpleSAML\Logger::debug('Library - LDAP searchfordn(): No entries found');
+        Logger::debug('Library - LDAP searchfordn(): No entries found');
         if ($allowZeroHits) {
             // Zero hits allowed
             return null;
@@ -324,7 +330,7 @@ class SimpleSAML_Auth_LDAP
      * This method was created specifically for the ldap:AttributeAddUsersGroups->searchActiveDirectory()
      * method, but could be used for other LDAP search needs. It will search LDAP and return all the entries.
      *
-     * @throws Exception
+     * @throws \Exception
      * @param string|array $bases
      * @param string|array $filters Array of 'attribute' => 'values' to be combined into the filter, or a raw filter string
      * @param string|array $attributes Array of attributes requested from LDAP
@@ -442,7 +448,7 @@ class SimpleSAML_Auth_LDAP
      * Returns TRUE if successful, FALSE if
      * LDAP_INVALID_CREDENTIALS, LDAP_X_PROXY_AUTHZ_FAILURE,
      * LDAP_INAPPROPRIATE_AUTH, LDAP_INSUFFICIENT_ACCESS
-     * @throws \SimpleSAML\Error\Exception on other errors
+     * @throws Error\Exception on other errors
      */
     public function bind($dn, $password, array $sasl_args = null)
     {
@@ -473,7 +479,7 @@ class SimpleSAML_Auth_LDAP
         if ($error === true) {
             // Good
             $this->authz_id = $authz_id;
-            SimpleSAML\Logger::debug('Library - LDAP bind(): Bind successful with DN \''.$dn.'\'');
+            Logger::debug('Library - LDAP bind(): Bind successful with DN \''.$dn.'\'');
             return true;
         }
 
@@ -520,7 +526,7 @@ class SimpleSAML_Auth_LDAP
         }
 
         // Log debug message
-        SimpleSAML\Logger::debug(
+        Logger::debug(
             'ldap:LdapConnection->setOption : Set the LDAP option ['.
             $option.'] with the value ['.$value.']'
         );
@@ -554,7 +560,7 @@ class SimpleSAML_Auth_LDAP
             // TODO: Verify that this originally was the intended behaviour. Could $attributes be a string?
             $attributes = array();
         }
-        SimpleSAML\Logger::debug('Library - LDAP getAttributes(): Getting '.$description.' from DN \''.$dn.'\'');
+        Logger::debug('Library - LDAP getAttributes(): Getting '.$description.' from DN \''.$dn.'\'');
 
         // Attempt to get attributes
         // TODO: Should aliases be dereferenced?
@@ -585,7 +591,7 @@ class SimpleSAML_Auth_LDAP
 
                 if (!empty($maxsize) && strlen($value) > $maxsize) {
                     // Ignoring and warning
-                    SimpleSAML\Logger::warning('Library - LDAP getAttributes(): Attribute \''.
+                    Logger::warning('Library - LDAP getAttributes(): Attribute \''.
                         $name.'\' exceeded maximum allowed size by '.(strlen($value) - $maxsize));
                     continue;
                 }
@@ -603,7 +609,7 @@ class SimpleSAML_Auth_LDAP
         }
 
         // We're done
-        SimpleSAML\Logger::debug('Library - LDAP getAttributes(): Found attributes \'('.join(',', array_keys($result)).')\'');
+        Logger::debug('Library - LDAP getAttributes(): Found attributes \'('.join(',', array_keys($result)).')\'');
         return $result;
     }
 
@@ -638,7 +644,7 @@ class SimpleSAML_Auth_LDAP
             // escape characters with a special meaning, also in the password
             $password = addcslashes($password, ',+"\\<>;*');
             if (!$this->bind($dn, $password)) {
-                SimpleSAML\Logger::info('Library - LDAP validate(): Failed to authenticate \''.$username.'\' using DN \''.$dn.'\'');
+                Logger::info('Library - LDAP validate(): Failed to authenticate \''.$username.'\' using DN \''.$dn.'\'');
                 return false;
             }
         }
diff --git a/lib/SimpleSAML/Auth/ProcessingChain.php b/lib/SimpleSAML/Auth/ProcessingChain.php
index a20663517..08ffb0ce9 100644
--- a/lib/SimpleSAML/Auth/ProcessingChain.php
+++ b/lib/SimpleSAML/Auth/ProcessingChain.php
@@ -1,5 +1,7 @@
 <?php
 
+namespace SimpleSAML\Auth;
+
 /**
  * Class for implementing authentication processing chains for IdPs.
  *
@@ -10,18 +12,19 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Auth_ProcessingChain
+
+class ProcessingChain
 {
     /**
      * The list of remaining filters which should be applied to the state.
      */
-    const FILTERS_INDEX = 'SimpleSAML_Auth_ProcessingChain.filters';
+    const FILTERS_INDEX = '\SimpleSAML\Auth\ProcessingChain.filters';
 
 
     /**
      * The stage we use for completed requests.
      */
-    const COMPLETED_STAGE = 'SimpleSAML_Auth_ProcessingChain.completed';
+    const COMPLETED_STAGE = '\SimpleSAML\Auth\ProcessingChain.completed';
 
 
     /**
@@ -69,8 +72,7 @@ class SimpleSAML_Auth_ProcessingChain
             self::addFilters($this->filters, $spFilters);
         }
 
-
-        SimpleSAML\Logger::debug('Filter config for ' . $idpMetadata['entityid'] . '->' .
+        \SimpleSAML\Logger::debug('Filter config for ' . $idpMetadata['entityid'] . '->' .
             $spMetadata['entityid'] . ': ' . str_replace("\n", '', var_export($this->filters, true)));
     }
 
@@ -108,7 +110,7 @@ class SimpleSAML_Auth_ProcessingChain
      * Parse an array of authentication processing filters.
      *
      * @param array $filterSrc  Array with filter configuration.
-     * @return array  Array of SimpleSAML_Auth_ProcessingFilter objects.
+     * @return array  Array of ProcessingFilter objects.
      */
     private static function parseFilterList($filterSrc)
     {
@@ -122,7 +124,7 @@ class SimpleSAML_Auth_ProcessingChain
             }
 
             if (!is_array($filter)) {
-                throw new Exception('Invalid authentication processing filter configuration: ' .
+                throw new \Exception('Invalid authentication processing filter configuration: ' .
                     'One of the filters wasn\'t a string or an array.');
             }
 
@@ -136,20 +138,20 @@ class SimpleSAML_Auth_ProcessingChain
     /**
      * Parse an authentication processing filter.
      *
-     * @param array $config     Array with the authentication processing filter configuration.
-     * @param int $priority     The priority of the current filter, (not included in the filter
-     *                          definition.)
-     * @return SimpleSAML_Auth_ProcessingFilter  The parsed filter.
+     * @param array $config      Array with the authentication processing filter configuration.
+     * @param int $priority      The priority of the current filter, (not included in the filter
+     *                           definition.)
+     * @return ProcessingFilter  The parsed filter.
      */
     private static function parseFilter($config, $priority)
     {
         assert(is_array($config));
 
         if (!array_key_exists('class', $config)) {
-            throw new Exception('Authentication processing filter without name given.');
+            throw new \Exception('Authentication processing filter without name given.');
         }
 
-        $className = SimpleSAML\Module::resolveClass($config['class'], 'Auth_Process', 'SimpleSAML_Auth_ProcessingFilter');
+        $className = \SimpleSAML\Module::resolveClass($config['class'], 'Auth\Process', '\SimpleSAML\Auth\ProcessingFilter');
         $config['%priority'] = $priority;
         unset($config['class']);
         return new $className($config, null);
@@ -168,11 +170,11 @@ class SimpleSAML_Auth_ProcessingChain
      * If an exception is thrown during processing, it should be handled by the caller of
      * this function. If the user has redirected to a different page, the exception will be
      * returned through the exception handler defined on the state array. See
-     * SimpleSAML_Auth_State for more information.
+     * State for more information.
      *
-     * @see SimpleSAML_Auth_State
-     * @see SimpleSAML_Auth_State::EXCEPTION_HANDLER_URL
-     * @see SimpleSAML_Auth_State::EXCEPTION_HANDLER_FUNC
+     * @see State
+     * @see State::EXCEPTION_HANDLER_URL
+     * @see State::EXCEPTION_HANDLER_FUNC
      *
      * @param array &$state  The state we are processing.
      */
@@ -198,7 +200,7 @@ class SimpleSAML_Auth_ProcessingChain
         } catch (\SimpleSAML\Error\Exception $e) {
             // No need to convert the exception
             throw $e;
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             /*
 			 * To be consistent with the exception we return after an redirect,
 			 * we convert this exception before returning it.
@@ -230,10 +232,10 @@ class SimpleSAML_Auth_ProcessingChain
             try {
                 $filter->process($state);
             } catch (\SimpleSAML\Error\Exception $e) {
-                SimpleSAML_Auth_State::throwException($state, $e);
-            } catch (Exception $e) {
+                State::throwException($state, $e);
+            } catch (\Exception $e) {
                 $e = new \SimpleSAML\Error\UnserializableException($e);
-                SimpleSAML_Auth_State::throwException($state, $e);
+                State::throwException($state, $e);
             }
         }
 
@@ -248,13 +250,13 @@ class SimpleSAML_Auth_ProcessingChain
 			 * Save state information, and redirect to the URL specified
 			 * in $state['ReturnURL'].
 			 */
-            $id = SimpleSAML_Auth_State::saveState($state, self::COMPLETED_STAGE);
+            $id = State::saveState($state, self::COMPLETED_STAGE);
             \SimpleSAML\Utils\HTTP::redirectTrustedURL($state['ReturnURL'], array(self::AUTHPARAM => $id));
         } else {
             /* Pass the state to the function defined in $state['ReturnCall']. */
 
             // We are done with the state array in the session. Delete it.
-            SimpleSAML_Auth_State::deleteState($state);
+            State::deleteState($state);
 
             $func = $state['ReturnCall'];
             assert(is_callable($func));
@@ -307,14 +309,14 @@ class SimpleSAML_Auth_ProcessingChain
      * Retrieve a state which has finished processing.
      *
      * @param string $id The state identifier.
-     * @see SimpleSAML_Auth_State::parseStateID()
+     * @see State::parseStateID()
      * @return Array The state referenced by the $id parameter.
      */
     public static function fetchProcessedState($id)
     {
         assert(is_string($id));
 
-        return SimpleSAML_Auth_State::loadState($id, self::COMPLETED_STAGE);
+        return State::loadState($id, self::COMPLETED_STAGE);
     }
 
 
@@ -328,10 +330,10 @@ class SimpleSAML_Auth_ProcessingChain
 
         if (isset($state['Destination']['userid.attribute'])) {
             $attributeName = $state['Destination']['userid.attribute'];
-            SimpleSAML\Logger::warning("The 'userid.attribute' option has been deprecated.");
+            \SimpleSAML\Logger::warning("The 'userid.attribute' option has been deprecated.");
         } elseif (isset($state['Source']['userid.attribute'])) {
             $attributeName = $state['Source']['userid.attribute'];
-            SimpleSAML\Logger::warning("The 'userid.attribute' option has been deprecated.");
+            \SimpleSAML\Logger::warning("The 'userid.attribute' option has been deprecated.");
         } else {
             // Default attribute
             $attributeName = 'eduPersonPrincipalName';
@@ -343,12 +345,12 @@ class SimpleSAML_Auth_ProcessingChain
 
         $uid = $state['Attributes'][$attributeName];
         if (count($uid) === 0) {
-            SimpleSAML\Logger::warning('Empty user id attribute [' . $attributeName . '].');
+            \SimpleSAML\Logger::warning('Empty user id attribute [' . $attributeName . '].');
             return;
         }
 
         if (count($uid) > 1) {
-            SimpleSAML\Logger::warning('Multiple attribute values for user id attribute [' . $attributeName . '].');
+            \SimpleSAML\Logger::warning('Multiple attribute values for user id attribute [' . $attributeName . '].');
             return;
         }
 
@@ -356,7 +358,7 @@ class SimpleSAML_Auth_ProcessingChain
         $uid = $uid[0];
 
         if (empty($uid)) {
-            SimpleSAML\Logger::warning('Empty value in attribute '.$attributeName.". on user. Cannot set UserID.");
+            \SimpleSAML\Logger::warning('Empty value in attribute '.$attributeName.". on user. Cannot set UserID.");
             return;
         }
         $state['UserID'] = $uid;
diff --git a/lib/SimpleSAML/Auth/ProcessingFilter.php b/lib/SimpleSAML/Auth/ProcessingFilter.php
index e6126da1d..baeb5834b 100644
--- a/lib/SimpleSAML/Auth/ProcessingFilter.php
+++ b/lib/SimpleSAML/Auth/ProcessingFilter.php
@@ -1,5 +1,6 @@
 <?php
 
+namespace SimpleSAML\Auth;
 
 /**
  * Base class for authentication processing filters.
@@ -18,9 +19,9 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-abstract class SimpleSAML_Auth_ProcessingFilter
-{
 
+abstract class ProcessingFilter
+{
     /**
      * Priority of this filter.
      *
@@ -49,7 +50,7 @@ abstract class SimpleSAML_Auth_ProcessingFilter
         if (array_key_exists('%priority', $config)) {
             $this->priority = $config['%priority'];
             if (!is_int($this->priority)) {
-                throw new Exception('Invalid priority: ' . var_export($this->priority, true));
+                throw new \Exception('Invalid priority: ' . var_export($this->priority, true));
             }
             unset($config['%priority']);
         }
diff --git a/lib/SimpleSAML/Auth/Simple.php b/lib/SimpleSAML/Auth/Simple.php
index 314e48b6b..a7efadca9 100644
--- a/lib/SimpleSAML/Auth/Simple.php
+++ b/lib/SimpleSAML/Auth/Simple.php
@@ -2,8 +2,6 @@
 
 namespace SimpleSAML\Auth;
 
-use \SimpleSAML_Auth_Source as Source;
-use \SimpleSAML_Auth_State as State;
 use \SimpleSAML\Configuration;
 use \SimpleSAML\Error\AuthSource as AuthSourceError;
 use \SimpleSAML\Module;
@@ -26,7 +24,7 @@ class Simple
     protected $authSource;
 
     /**
-     * @var \SimpleSAML\Configuration|null
+     * @var Configuration|null
      */
     protected $app_config;
 
@@ -47,9 +45,9 @@ class Simple
     /**
      * Retrieve the implementing authentication source.
      *
-     * @return \SimpleSAML_Auth_Source The authentication source.
+     * @return Source The authentication source.
      *
-     * @throws \SimpleSAML\Error\AuthSource If the requested auth source is unknown.
+     * @throws AuthSourceError If the requested auth source is unknown.
      */
     public function getAuthSource()
     {
@@ -92,7 +90,6 @@ class Simple
      */
     public function requireAuth(array $params = array())
     {
-
         $session = Session::getSessionFromRequest();
 
         if ($session->isValid($this->authSource)) {
@@ -120,7 +117,6 @@ class Simple
      */
     public function login(array $params = array())
     {
-
         if (array_key_exists('KeepPost', $params)) {
             $keepPost = (bool) $params['KeepPost'];
         } else {
@@ -257,7 +253,6 @@ class Simple
      */
     public function getAttributes()
     {
-
         if (!$this->isAuthenticated()) {
             // Not authenticated
             return array();
@@ -296,7 +291,6 @@ class Simple
      */
     public function getAuthDataArray()
     {
-
         if (!$this->isAuthenticated()) {
             return null;
         }
diff --git a/lib/SimpleSAML/Auth/Source.php b/lib/SimpleSAML/Auth/Source.php
index 8e1be0243..eacec3ead 100644
--- a/lib/SimpleSAML/Auth/Source.php
+++ b/lib/SimpleSAML/Auth/Source.php
@@ -1,6 +1,6 @@
 <?php
 
-use SimpleSAML\Auth\SourceFactory;
+namespace SimpleSAML\Auth;
 
 /**
  * This class defines a base class for authentication source.
@@ -11,7 +11,7 @@ use SimpleSAML\Auth\SourceFactory;
  * @package SimpleSAMLphp
  */
 
-abstract class SimpleSAML_Auth_Source
+abstract class Source
 {
     /**
      * The authentication source identifier. This identifier can be used to look up this object, for example when
@@ -46,7 +46,7 @@ abstract class SimpleSAML_Auth_Source
      *
      * @param string $type The type of the authentication source.
      *
-     * @return SimpleSAML_Auth_Source[]  Array of SimpleSAML_Auth_Source objects of the specified type.
+     * @return Source[]  Array of \SimpleSAML\Auth\Source objects of the specified type.
      * @throws Exception If the authentication source is invalid.
      */
     public static function getSourcesOfType($type)
@@ -137,7 +137,7 @@ abstract class SimpleSAML_Auth_Source
         assert(is_array($state));
         assert(array_key_exists('LoginCompletedHandler', $state));
 
-        SimpleSAML_Auth_State::deleteState($state);
+        State::deleteState($state);
 
         $func = $state['LoginCompletedHandler'];
         assert(is_callable($func));
@@ -166,36 +166,36 @@ abstract class SimpleSAML_Auth_Source
         assert(is_string($errorURL) || $errorURL === null);
 
         $state = array_merge($params, array(
-            'SimpleSAML_Auth_Default.id' => $this->authId, // TODO: remove in 2.0
-            'SimpleSAML_Auth_Source.id' => $this->authId,
-            'SimpleSAML_Auth_Default.Return' => $return, // TODO: remove in 2.0
-            'SimpleSAML_Auth_Source.Return' => $return,
-            'SimpleSAML_Auth_Default.ErrorURL' => $errorURL, // TODO: remove in 2.0
-            'SimpleSAML_Auth_Source.ErrorURL' => $errorURL,
+            '\SimpleSAML\Auth\DefaultAuth.id' => $this->authId, // TODO: remove in 2.0
+            '\SimpleSAML\Auth\Source.id' => $this->authId,
+            '\SimpleSAML\Auth\DefaultAuth.Return' => $return, // TODO: remove in 2.0
+            '\SimpleSAML\Auth\Source.Return' => $return,
+            '\SimpleSAML\Auth\DefaultAuth.ErrorURL' => $errorURL, // TODO: remove in 2.0
+            '\SimpleSAML\Auth\Source.ErrorURL' => $errorURL,
             'LoginCompletedHandler' => array(get_class(), 'loginCompleted'),
             'LogoutCallback' => array(get_class(), 'logoutCallback'),
             'LogoutCallbackState' => array(
-                'SimpleSAML_Auth_Default.logoutSource' => $this->authId, // TODO: remove in 2.0
-                'SimpleSAML_Auth_Source.logoutSource' => $this->authId,
+                '\SimpleSAML\Auth\DefaultAuth.logoutSource' => $this->authId, // TODO: remove in 2.0
+                '\SimpleSAML\Auth\Source.logoutSource' => $this->authId,
             ),
         ));
 
         if (is_string($return)) {
-            $state['SimpleSAML_Auth_Default.ReturnURL'] = $return; // TODO: remove in 2.0
-            $state['SimpleSAML_Auth_Source.ReturnURL'] = $return;
+            $state['\SimpleSAML\Auth\DefaultAuth.ReturnURL'] = $return; // TODO: remove in 2.0
+            $state['\SimpleSAML\Auth\Source.ReturnURL'] = $return;
         }
 
         if ($errorURL !== null) {
-            $state[SimpleSAML_Auth_State::EXCEPTION_HANDLER_URL] = $errorURL;
+            $state[State::EXCEPTION_HANDLER_URL] = $errorURL;
         }
 
         try {
             $this->authenticate($state);
         } catch (\SimpleSAML\Error\Exception $e) {
-            SimpleSAML_Auth_State::throwException($state, $e);
-        } catch (Exception $e) {
+            State::throwException($state, $e);
+        } catch (\Exception $e) {
             $e = new \SimpleSAML\Error\UnserializableException($e);
-            SimpleSAML_Auth_State::throwException($state, $e);
+            State::throwException($state, $e);
         }
         self::loginCompleted($state);
     }
@@ -211,17 +211,17 @@ abstract class SimpleSAML_Auth_Source
     public static function loginCompleted($state)
     {
         assert(is_array($state));
-        assert(array_key_exists('SimpleSAML_Auth_Source.Return', $state));
-        assert(array_key_exists('SimpleSAML_Auth_Source.id', $state));
+        assert(array_key_exists('\SimpleSAML\Auth\Source.Return', $state));
+        assert(array_key_exists('\SimpleSAML\Auth\Source.id', $state));
         assert(array_key_exists('Attributes', $state));
         assert(!array_key_exists('LogoutState', $state) || is_array($state['LogoutState']));
 
-        $return = $state['SimpleSAML_Auth_Source.Return'];
+        $return = $state['\SimpleSAML\Auth\Source.Return'];
 
         // save session state
         $session = \SimpleSAML\Session::getSessionFromRequest();
-        $authId = $state['SimpleSAML_Auth_Source.id'];
-        $session->doLogin($authId, SimpleSAML_Auth_State::getPersistentAuthData($state));
+        $authId = $state['\SimpleSAML\Auth\Source.id'];
+        $session->doLogin($authId, State::getPersistentAuthData($state));
 
         if (is_string($return)) { // redirect...
             \SimpleSAML\Utils\HTTP::redirectTrustedURL($return);
@@ -266,7 +266,7 @@ abstract class SimpleSAML_Auth_Source
         assert(is_array($state));
         assert(array_key_exists('LogoutCompletedHandler', $state));
 
-        SimpleSAML_Auth_State::deleteState($state);
+        State::deleteState($state);
 
         $func = $state['LogoutCompletedHandler'];
         assert(is_callable($func));
@@ -285,8 +285,8 @@ abstract class SimpleSAML_Auth_Source
      * @param string $authId The authentication source identifier.
      * @param array  $config The configuration.
      *
-     * @return SimpleSAML_Auth_Source The parsed authentication source.
-     * @throws Exception If the authentication source is invalid.
+     * @return Source The parsed authentication source.
+     * @throws \Exception If the authentication source is invalid.
      */
     private static function parseAuthSource($authId, $config)
     {
@@ -303,14 +303,14 @@ abstract class SimpleSAML_Auth_Source
 
         try {
             // Check whether or not there's a factory responsible for instantiating our Auth Source instance
-            $factoryClass = SimpleSAML\Module::resolveClass($id, 'Auth_Source_Factory', 'SimpleSAML\Auth\SourceFactory');
+            $factoryClass = \SimpleSAML\Module::resolveClass($id, 'Auth\Source\Factory', '\SimpleSAML\Auth\SourceFactory');
 
             /** @var SourceFactory $factory */
             $factory = new $factoryClass;
             $authSource = $factory->create($info, $config);
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             // If not, instantiate the Auth Source here
-            $className = SimpleSAML\Module::resolveClass($id, 'Auth_Source', 'SimpleSAML_Auth_Source');
+            $className = \SimpleSAML\Module::resolveClass($id, 'Auth\Source', '\SimpleSAML\Auth\Source');
             $authSource = new $className($info, $config);
         }
 
@@ -332,7 +332,7 @@ abstract class SimpleSAML_Auth_Source
      * @param string      $authId The authentication source identifier.
      * @param string|NULL $type The type of authentication source. If NULL, any type will be accepted.
      *
-     * @return SimpleSAML_Auth_Source|NULL The AuthSource object, or NULL if no authentication
+     * @return Source|NULL The AuthSource object, or NULL if no authentication
      *     source with the given identifier is found.
      * @throws \SimpleSAML\Error\Exception If no such authentication source is found or it is invalid.
      */
@@ -378,13 +378,13 @@ abstract class SimpleSAML_Auth_Source
     public static function logoutCallback($state)
     {
         assert(is_array($state));
-        assert(array_key_exists('SimpleSAML_Auth_Source.logoutSource', $state));
+        assert(array_key_exists('\SimpleSAML\Auth\Source.logoutSource', $state));
 
-        $source = $state['SimpleSAML_Auth_Source.logoutSource'];
+        $source = $state['\SimpleSAML\Auth\Source.logoutSource'];
 
         $session = \SimpleSAML\Session::getSessionFromRequest();
         if (!$session->isValid($source)) {
-            SimpleSAML\Logger::warning(
+            \SimpleSAML\Logger::warning(
                 'Received logout from an invalid authentication source '.
                 var_export($source, true)
             );
@@ -433,7 +433,7 @@ abstract class SimpleSAML_Auth_Source
 
         $session = \SimpleSAML\Session::getSessionFromRequest();
         $session->setData(
-            'SimpleSAML_Auth_Source.LogoutCallbacks',
+            '\SimpleSAML\Auth\Source.LogoutCallbacks',
             $id,
             $data,
             \SimpleSAML\Session::DATA_TIMEOUT_SESSION_END
@@ -459,7 +459,7 @@ abstract class SimpleSAML_Auth_Source
 
         $session = \SimpleSAML\Session::getSessionFromRequest();
 
-        $data = $session->getData('SimpleSAML_Auth_Source.LogoutCallbacks', $id);
+        $data = $session->getData('\SimpleSAML\Auth\Source.LogoutCallbacks', $id);
         if ($data === null) {
             // FIXME: fix for IdP-first flow (issue 397) -> reevaluate logout callback infrastructure
             $session->doLogout($this->authId);
@@ -474,7 +474,7 @@ abstract class SimpleSAML_Auth_Source
         $callback = $data['callback'];
         $callbackState = $data['state'];
 
-        $session->deleteData('SimpleSAML_Auth_Source.LogoutCallbacks', $id);
+        $session->deleteData('\SimpleSAML\Auth\Source.LogoutCallbacks', $id);
         call_user_func($callback, $callbackState);
     }
 
@@ -498,12 +498,12 @@ abstract class SimpleSAML_Auth_Source
      * @param array $source An array with the auth source configuration.
      * @param string $id The auth source identifier.
      *
-     * @throws Exception If the first element of $source is not an identifier for the auth source.
+     * @throws \Exception If the first element of $source is not an identifier for the auth source.
      */
     protected static function validateSource($source, $id)
     {
         if (!array_key_exists(0, $source) || !is_string($source[0])) {
-            throw new Exception(
+            throw new \Exception(
                 'Invalid authentication source \''.$id.
                 '\': First element must be a string which identifies the authentication source.'
             );
diff --git a/lib/SimpleSAML/Auth/SourceFactory.php b/lib/SimpleSAML/Auth/SourceFactory.php
index 1cc6a6c9a..9f5fdfafb 100644
--- a/lib/SimpleSAML/Auth/SourceFactory.php
+++ b/lib/SimpleSAML/Auth/SourceFactory.php
@@ -2,14 +2,12 @@
 
 namespace SimpleSAML\Auth;
 
-use SimpleSAML_Auth_Source;
-
 interface SourceFactory
 {
     /**
      * @param array $info
      * @param array $config
-     * @return SimpleSAML_Auth_Source
+     * @return Source
      */
     public function create(array $info, array $config);
 }
diff --git a/lib/SimpleSAML/Auth/State.php b/lib/SimpleSAML/Auth/State.php
index f91769871..44454b41f 100644
--- a/lib/SimpleSAML/Auth/State.php
+++ b/lib/SimpleSAML/Auth/State.php
@@ -1,14 +1,16 @@
 <?php
 
+namespace SimpleSAML\Auth;
+
 /**
  * This is a helper class for saving and loading state information.
  *
  * The state must be an associative array. This class will add additional keys to this
- * array. These keys will always start with 'SimpleSAML_Auth_State.'.
+ * array. These keys will always start with '\SimpleSAML\Auth\State.'.
  *
  * It is also possible to add a restart URL to the state. If state information is lost, for
  * example because it timed out, or the user loaded a bookmarked page, the loadState function
- * will redirect to this URL. To use this, set $state[SimpleSAML_Auth_State::RESTART] to this
+ * will redirect to this URL. To use this, set $state[\SimpleSAML\Auth\State::RESTART] to this
  * URL.
  *
  * Both the saveState and the loadState function takes in a $stage parameter. This parameter is
@@ -27,61 +29,62 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class SimpleSAML_Auth_State
+
+class State
 {
     /**
      * The index in the state array which contains the identifier.
      */
-    const ID = 'SimpleSAML_Auth_State.id';
+    const ID = '\SimpleSAML\Auth\State.id';
 
 
     /**
      * The index in the cloned state array which contains the identifier of the
      * original state.
      */
-    const CLONE_ORIGINAL_ID = 'SimpleSAML_Auth_State.cloneOriginalId';
+    const CLONE_ORIGINAL_ID = '\SimpleSAML\Auth\State.cloneOriginalId';
 
 
     /**
      * The index in the state array which contains the current stage.
      */
-    const STAGE = 'SimpleSAML_Auth_State.stage';
+    const STAGE = '\SimpleSAML\Auth\State.stage';
 
 
     /**
      * The index in the state array which contains the restart URL.
      */
-    const RESTART = 'SimpleSAML_Auth_State.restartURL';
+    const RESTART = '\SimpleSAML\Auth\State.restartURL';
 
 
     /**
      * The index in the state array which contains the exception handler URL.
      */
-    const EXCEPTION_HANDLER_URL = 'SimpleSAML_Auth_State.exceptionURL';
+    const EXCEPTION_HANDLER_URL = '\SimpleSAML\Auth\State.exceptionURL';
 
 
     /**
      * The index in the state array which contains the exception handler function.
      */
-    const EXCEPTION_HANDLER_FUNC = 'SimpleSAML_Auth_State.exceptionFunc';
+    const EXCEPTION_HANDLER_FUNC = '\SimpleSAML\Auth\State.exceptionFunc';
 
 
     /**
      * The index in the state array which contains the exception data.
      */
-    const EXCEPTION_DATA = 'SimpleSAML_Auth_State.exceptionData';
+    const EXCEPTION_DATA = '\SimpleSAML\Auth\State.exceptionData';
 
 
     /**
      * The stage of a state with an exception.
      */
-    const EXCEPTION_STAGE = 'SimpleSAML_Auth_State.exceptionStage';
+    const EXCEPTION_STAGE = '\SimpleSAML\Auth\State.exceptionStage';
 
 
     /**
      * The URL parameter which contains the exception state id.
      */
-    const EXCEPTION_PARAM = 'SimpleSAML_Auth_State_exceptionId';
+    const EXCEPTION_PARAM = '\SimpleSAML\Auth\State.exceptionId';
 
 
     /**
@@ -145,7 +148,7 @@ class SimpleSAML_Auth_State
         assert(is_bool($rawId));
 
         if (!array_key_exists(self::ID, $state)) {
-            $state[self::ID] = SimpleSAML\Utils\Random::generateID();
+            $state[self::ID] = \SimpleSAML\Utils\Random::generateID();
         }
 
         $id = $state[self::ID];
@@ -203,9 +206,9 @@ class SimpleSAML_Auth_State
         // Save state
         $serializedState = serialize($state);
         $session = \SimpleSAML\Session::getSessionFromRequest();
-        $session->setData('SimpleSAML_Auth_State', $id, $serializedState, self::getStateTimeout());
+        $session->setData('\SimpleSAML\Auth\State', $id, $serializedState, self::getStateTimeout());
 
-        SimpleSAML\Logger::debug('Saved state: '.var_export($return, true));
+        \SimpleSAML\Logger::debug('Saved state: '.var_export($return, true));
 
         return $return;
     }
@@ -228,9 +231,9 @@ class SimpleSAML_Auth_State
             $clonedState[self::CLONE_ORIGINAL_ID] = $state[self::ID];
             unset($clonedState[self::ID]);
 
-            SimpleSAML\Logger::debug('Cloned state: '.var_export($state[self::ID], true));
+            \SimpleSAML\Logger::debug('Cloned state: '.var_export($state[self::ID], true));
         } else {
-            SimpleSAML\Logger::debug('Cloned state with undefined id.');
+            \SimpleSAML\Logger::debug('Cloned state with undefined id.');
         }
 
         return $clonedState;
@@ -249,7 +252,7 @@ class SimpleSAML_Auth_State
      * @param bool   $allowMissing Whether to allow the state to be missing.
      *
      * @throws \SimpleSAML\Error\NoState If we couldn't find the state and there's no URL defined to redirect to.
-     * @throws Exception If the stage of the state is invalid and there's no URL defined to redirect to.
+     * @throws \Exception If the stage of the state is invalid and there's no URL defined to redirect to.
      *
      * @return array|NULL  State information, or null if the state is missing and $allowMissing is true.
      */
@@ -258,12 +261,12 @@ class SimpleSAML_Auth_State
         assert(is_string($id));
         assert(is_string($stage));
         assert(is_bool($allowMissing));
-        SimpleSAML\Logger::debug('Loading state: '.var_export($id, true));
+        \SimpleSAML\Logger::debug('Loading state: '.var_export($id, true));
 
         $sid = self::parseStateID($id);
 
         $session = \SimpleSAML\Session::getSessionFromRequest();
-        $state = $session->getData('SimpleSAML_Auth_State', $sid['id']);
+        $state = $session->getData('\SimpleSAML\Auth\State', $sid['id']);
 
         if ($state === null) {
             // Could not find saved data
@@ -293,10 +296,10 @@ class SimpleSAML_Auth_State
             $msg = 'Wrong stage in state. Was \''.$state[self::STAGE].
                 '\', should be \''.$stage.'\'.';
 
-            SimpleSAML\Logger::warning($msg);
+            \SimpleSAML\Logger::warning($msg);
 
             if ($sid['url'] === null) {
-                throw new Exception($msg);
+                throw new \Exception($msg);
             }
 
             \SimpleSAML\Utils\HTTP::redirectUntrustedURL($sid['url']);
@@ -322,10 +325,10 @@ class SimpleSAML_Auth_State
             return;
         }
 
-        SimpleSAML\Logger::debug('Deleting state: '.var_export($state[self::ID], true));
+        \SimpleSAML\Logger::debug('Deleting state: '.var_export($state[self::ID], true));
 
         $session = \SimpleSAML\Session::getSessionFromRequest();
-        $session->deleteData('SimpleSAML_Auth_State', $state[self::ID]);
+        $session->deleteData('\SimpleSAML\Auth\State', $state[self::ID]);
     }
 
 
diff --git a/lib/SimpleSAML/Auth/TimeLimitedToken.php b/lib/SimpleSAML/Auth/TimeLimitedToken.php
index 920dd2d12..eb6620d5e 100644
--- a/lib/SimpleSAML/Auth/TimeLimitedToken.php
+++ b/lib/SimpleSAML/Auth/TimeLimitedToken.php
@@ -5,9 +5,9 @@ namespace SimpleSAML\Auth;
 /**
  * A class that generates and verifies time-limited tokens.
  */
+
 class TimeLimitedToken
 {
-
     /**
      * @var string
      */
diff --git a/lib/SimpleSAML/AuthMemCookie.php b/lib/SimpleSAML/AuthMemCookie.php
index 958952041..1c5fb7c96 100644
--- a/lib/SimpleSAML/AuthMemCookie.php
+++ b/lib/SimpleSAML/AuthMemCookie.php
@@ -110,15 +110,15 @@ class AuthMemCookie
     /**
      * This function creates and initializes a Memcache object from our configuration.
      *
-     * @return Memcache A Memcache object initialized from our configuration.
-     * @throws Exception If the servers configuration is invalid.
+     * @return \Memcache A Memcache object initialized from our configuration.
+     * @throws \Exception If the servers configuration is invalid.
      */
     public function getMemcache()
     {
         $memcacheHost = $this->amcConfig->getString('memcache.host', '127.0.0.1');
         $memcachePort = $this->amcConfig->getInteger('memcache.port', 11211);
 
-        $class = class_exists('Memcache') ? 'Memcache' : (class_exists('Memcached') ? 'Memcached' : false);
+        $class = class_exists('Memcache') ? '\Memcache' : (class_exists('Memcached') ? '\Memcached' : false);
         if (!$class) {
             throw new \Exception('Missing Memcached implementation. You must install either the Memcache or Memcached extension.');
         }
diff --git a/lib/SimpleSAML/Error/UnserializableException.php b/lib/SimpleSAML/Error/UnserializableException.php
index 38cf79e94..515b46091 100644
--- a/lib/SimpleSAML/Error/UnserializableException.php
+++ b/lib/SimpleSAML/Error/UnserializableException.php
@@ -5,7 +5,7 @@ namespace SimpleSAML\Error;
 /**
  * Class for saving normal exceptions for serialization.
  *
- * This class is used by the SimpleSAML_Auth_State class when it needs
+ * This class is used by the \SimpleSAML\Auth\State class when it needs
  * to serialize an exception which doesn't subclass the
  * \SimpleSAML\Error\Exception class.
  *
diff --git a/lib/SimpleSAML/IdP.php b/lib/SimpleSAML/IdP.php
index 6edfc85bb..8089ad074 100644
--- a/lib/SimpleSAML/IdP.php
+++ b/lib/SimpleSAML/IdP.php
@@ -95,7 +95,7 @@ class SimpleSAML_IdP
         }
 
         $auth = $this->config->getString('auth');
-        if (SimpleSAML_Auth_Source::getById($auth) !== null) {
+        if (\SimpleSAML\Auth\Source::getById($auth) !== null) {
             $this->authSource = new \SimpleSAML\Auth\Simple($auth);
         } else {
             throw new \SimpleSAML\Error\Exception('No such "'.$auth.'" auth source found.');
@@ -315,7 +315,7 @@ class SimpleSAML_IdP
 
         $idpMetadata = $idp->getConfig()->toArray();
 
-        $pc = new SimpleSAML_Auth_ProcessingChain($idpMetadata, $spMetadata, 'idp');
+        $pc = new \SimpleSAML\Auth\ProcessingChain($idpMetadata, $spMetadata, 'idp');
 
         $state['ReturnCall'] = array('SimpleSAML_IdP', 'postAuthProc');
         $state['Destination'] = $spMetadata;
@@ -409,10 +409,10 @@ class SimpleSAML_IdP
             }
             $this->postAuth($state);
         } catch (\SimpleSAML\Error\Exception $e) {
-            SimpleSAML_Auth_State::throwException($state, $e);
+            \SimpleSAML\Auth\State::throwException($state, $e);
         } catch (Exception $e) {
             $e = new \SimpleSAML\Error\UnserializableException($e);
-            SimpleSAML_Auth_State::throwException($state, $e);
+            \SimpleSAML\Auth\State::throwException($state, $e);
         }
     }
 
@@ -484,8 +484,8 @@ class SimpleSAML_IdP
         }
 
         // terminate the local session
-        $id = SimpleSAML_Auth_State::saveState($state, 'core:Logout:afterbridge');
-        $returnTo = SimpleSAML\Module::getModuleURL('core/idp/resumelogout.php', array('id' => $id));
+        $id = \SimpleSAML\Auth\State::saveState($state, 'core:Logout:afterbridge');
+        $returnTo = \SimpleSAML\Module::getModuleURL('core/idp/resumelogout.php', array('id' => $id));
 
         $this->authSource->logout($returnTo);
 
diff --git a/lib/SimpleSAML/IdP/IFrameLogoutHandler.php b/lib/SimpleSAML/IdP/IFrameLogoutHandler.php
index 2761214f8..af9aebbdd 100644
--- a/lib/SimpleSAML/IdP/IFrameLogoutHandler.php
+++ b/lib/SimpleSAML/IdP/IFrameLogoutHandler.php
@@ -66,7 +66,7 @@ class IFrameLogoutHandler implements LogoutHandlerInterface
         }
 
         $params = array(
-            'id' => \SimpleSAML_Auth_State::saveState($state, 'core:Logout-IFrame'),
+            'id' => \SimpleSAML\Auth\State::saveState($state, 'core:Logout-IFrame'),
         );
         if (isset($state['core:Logout-IFrame:InitType'])) {
             $params['type'] = $state['core:Logout-IFrame:InitType'];
diff --git a/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php b/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php
index f8f5cc8ea..eb8d0ec6a 100644
--- a/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php
+++ b/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php
@@ -46,7 +46,7 @@ class TraditionalLogoutHandler implements LogoutHandlerInterface
             $this->idp->finishLogout($state);
         }
 
-        $relayState = \SimpleSAML_Auth_State::saveState($state, 'core:LogoutTraditional', true);
+        $relayState = \SimpleSAML\Auth\State::saveState($state, 'core:LogoutTraditional', true);
 
         $id = $association['id'];
         Logger::info('Logging out of '.var_export($id, true).'.');
@@ -103,7 +103,7 @@ class TraditionalLogoutHandler implements LogoutHandlerInterface
             throw new \SimpleSAML\Error\Exception('RelayState lost during logout.');
         }
 
-        $state = \SimpleSAML_Auth_State::loadState($relayState, 'core:LogoutTraditional');
+        $state = \SimpleSAML\Auth\State::loadState($relayState, 'core:LogoutTraditional');
 
         if ($error === null) {
             Logger::info('Logged out of '.var_export($assocId, true).'.');
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index e72ba1790..2189449ff 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -111,11 +111,11 @@ class SimpleSAML_Utilities
 
 
     /**
-     * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Auth_State::parseStateID() instead.
+     * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Auth\State::parseStateID() instead.
      */
     public static function parseStateID($stateId)
     {
-        return SimpleSAML_Auth_State::parseStateID($stateId);
+        return \SimpleSAML\Auth\State::parseStateID($stateId);
     }
 
 
diff --git a/lib/SimpleSAML/Utils/Auth.php b/lib/SimpleSAML/Utils/Auth.php
index d938c3108..ad6c4df4b 100644
--- a/lib/SimpleSAML/Utils/Auth.php
+++ b/lib/SimpleSAML/Utils/Auth.php
@@ -63,7 +63,7 @@ class Auth
         }
 
         // not authenticated as admin user, start authentication
-        if (\SimpleSAML_Auth_Source::getById('admin') !== null) {
+        if (\SimpleSAML\Auth\Source::getById('admin') !== null) {
             $as = new \SimpleSAML\Auth\Simple('admin');
             $as->login();
         } else {
diff --git a/modules/authX509/lib/Auth/Process/ExpiryWarning.php b/modules/authX509/lib/Auth/Process/ExpiryWarning.php
index 0a6fe5bf9..8e0972429 100644
--- a/modules/authX509/lib/Auth/Process/ExpiryWarning.php
+++ b/modules/authX509/lib/Auth/Process/ExpiryWarning.php
@@ -14,7 +14,7 @@
  * @author Joost van Dijk, SURFnet. <Joost.vanDijk@surfnet.nl>
  * @package SimpleSAMLphp
  */
-class sspmod_authX509_Auth_Process_ExpiryWarning extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_authX509_Auth_Process_ExpiryWarning extends \SimpleSAML\Auth\ProcessingFilter
 {
 
     private $warndaysbefore = 30;
@@ -83,13 +83,13 @@ class sspmod_authX509_Auth_Process_ExpiryWarning extends SimpleSAML_Auth_Process
             return;
         }
 
-        SimpleSAML\Logger::warning('authX509: user certificate expires in ' . $daysleft . ' days');
+        \SimpleSAML\Logger::warning('authX509: user certificate expires in ' . $daysleft . ' days');
         $state['daysleft'] = $daysleft;
         $state['renewurl'] = $this->renewurl;
 
         /* Save state and redirect. */
-        $id = SimpleSAML_Auth_State::saveState($state, 'warning:expire');
-        $url = SimpleSAML\Module::getModuleURL('authX509/expirywarning.php');
+        $id = \SimpleSAML\Auth\State::saveState($state, 'warning:expire');
+        $url = \SimpleSAML\Module::getModuleURL('authX509/expirywarning.php');
         \SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
     }
 
diff --git a/modules/authX509/lib/Auth/Source/X509userCert.php b/modules/authX509/lib/Auth/Source/X509userCert.php
index 49860c2c6..2dc74bc77 100644
--- a/modules/authX509/lib/Auth/Source/X509userCert.php
+++ b/modules/authX509/lib/Auth/Source/X509userCert.php
@@ -7,7 +7,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
+class sspmod_authX509_Auth_Source_X509userCert extends \SimpleSAML\Auth\Source
 {
     /**
      * x509 attributes to use from the certificate for searching the user in the LDAP directory.
@@ -198,7 +198,7 @@ class sspmod_authX509_Auth_Source_X509userCert extends SimpleSAML_Auth_Source
      */
     public function authSuccesful(&$state)
     {
-        SimpleSAML_Auth_Source::completeAuth($state);
+        \SimpleSAML\Auth\Source::completeAuth($state);
 
         assert(false); // should never be reached
         return;
diff --git a/modules/authX509/www/expirywarning.php b/modules/authX509/www/expirywarning.php
index d7861254e..b5b445ca1 100644
--- a/modules/authX509/www/expirywarning.php
+++ b/modules/authX509/www/expirywarning.php
@@ -12,12 +12,12 @@ if (!array_key_exists('StateId', $_REQUEST)) {
     throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = \SimpleSAML_Auth_State::loadState($id, 'warning:expire');
+$state = \SimpleSAML\Auth\State::loadState($id, 'warning:expire');
 
 
 if (array_key_exists('proceed', $_REQUEST)) {
     // The user has pressed the proceed-button
-    \SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+    \SimpleSAML\Auth\ProcessingChain::resumeProcessing($state);
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
diff --git a/modules/authYubiKey/lib/Auth/Process/OTP2YubiPrefix.php b/modules/authYubiKey/lib/Auth/Process/OTP2YubiPrefix.php
index 1c37c8c03..a3d2ad409 100644
--- a/modules/authYubiKey/lib/Auth/Process/OTP2YubiPrefix.php
+++ b/modules/authYubiKey/lib/Auth/Process/OTP2YubiPrefix.php
@@ -42,7 +42,7 @@
  *      );
  *
  */
-class sspmod_authYubiKey_Auth_Process_OTP2YubiPrefix extends SimpleSAML_Auth_ProcessingFilter {
+class sspmod_authYubiKey_Auth_Process_OTP2YubiPrefix extends \SimpleSAML\Auth\ProcessingFilter {
 
 
 	/**
diff --git a/modules/authYubiKey/lib/Auth/Source/YubiKey.php b/modules/authYubiKey/lib/Auth/Source/YubiKey.php
index 1bdd98dd4..fdfddf309 100644
--- a/modules/authYubiKey/lib/Auth/Source/YubiKey.php
+++ b/modules/authYubiKey/lib/Auth/Source/YubiKey.php
@@ -40,7 +40,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_authYubiKey_Auth_Source_YubiKey extends SimpleSAML_Auth_Source
+class sspmod_authYubiKey_Auth_Source_YubiKey extends \SimpleSAML\Auth\Source
 {
     /**
      * The string used to identify our states.
@@ -103,7 +103,7 @@ class sspmod_authYubiKey_Auth_Source_YubiKey extends SimpleSAML_Auth_Source
         // We are going to need the authId in order to retrieve this authentication source later
         $state[self::AUTHID] = $this->authId;
 
-        $id = \SimpleSAML_Auth_State::saveState($state, self::STAGEID);
+        $id = \SimpleSAML\Auth\State::saveState($state, self::STAGEID);
         $url = \SimpleSAML\Module::getModuleURL('authYubiKey/yubikeylogin.php');
         \SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('AuthState' => $id));
     }
@@ -127,11 +127,11 @@ class sspmod_authYubiKey_Auth_Source_YubiKey extends SimpleSAML_Auth_Source
         assert(is_string($otp));
 
         /* Retrieve the authentication state. */
-        $state = \SimpleSAML_Auth_State::loadState($authStateId, self::STAGEID);
+        $state = \SimpleSAML\Auth\State::loadState($authStateId, self::STAGEID);
 
         /* Find authentication source. */
         assert(array_key_exists(self::AUTHID, $state));
-        $source = \SimpleSAML_Auth_Source::getById($state[self::AUTHID]);
+        $source = \SimpleSAML\Auth\Source::getById($state[self::AUTHID]);
         if ($source === null) {
             throw new Exception('Could not find authentication source with id '.$state[self::AUTHID]);
         }
@@ -155,7 +155,7 @@ class sspmod_authYubiKey_Auth_Source_YubiKey extends SimpleSAML_Auth_Source
         }
 
         $state['Attributes'] = $attributes;
-        \SimpleSAML_Auth_Source::completeAuth($state);
+        \SimpleSAML\Auth\Source::completeAuth($state);
     }
 
     /**
diff --git a/modules/authfacebook/lib/Auth/Source/Facebook.php b/modules/authfacebook/lib/Auth/Source/Facebook.php
index 179b3b269..aeaff9cb0 100644
--- a/modules/authfacebook/lib/Auth/Source/Facebook.php
+++ b/modules/authfacebook/lib/Auth/Source/Facebook.php
@@ -6,9 +6,9 @@
  * @author Andreas Ã…kre Solberg, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source {
-
 
+class sspmod_authfacebook_Auth_Source_Facebook extends \SimpleSAML\Auth\Source
+{
 	/**
 	 * The string used to identify our states.
 	 */
@@ -86,14 +86,14 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source {
 
 		// We are going to need the authId in order to retrieve this authentication source later
 		$state[self::AUTHID] = $this->authId;
-		SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
+		\SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
 		
 		$facebook = new sspmod_authfacebook_Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state);
 		$facebook->destroySession();
 
-		$linkback = SimpleSAML\Module::getModuleURL('authfacebook/linkback.php');
+		$linkback = \SimpleSAML\Module::getModuleURL('authfacebook/linkback.php');
 		$url = $facebook->getLoginUrl(array('redirect_uri' => $linkback, 'scope' => $this->req_perms));
-		SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
+		\SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
 
 		\SimpleSAML\Utils\HTTP::redirectTrustedURL($url);
 	}
diff --git a/modules/authfacebook/lib/Facebook.php b/modules/authfacebook/lib/Facebook.php
index 42153933c..c64eb5b73 100644
--- a/modules/authfacebook/lib/Facebook.php
+++ b/modules/authfacebook/lib/Facebook.php
@@ -149,7 +149,7 @@ class sspmod_authfacebook_Facebook extends BaseFacebook
 
   protected function establishCSRFTokenState() {
      if ($this->state === null) {
-          $this->state = SimpleSAML_Auth_State::getStateId($this->ssp_state);
+          $this->state = \SimpleSAML\Auth\State::getStateId($this->ssp_state);
           $this->setPersistentData('state', $this->state);
      }
   }
diff --git a/modules/authfacebook/www/linkback.php b/modules/authfacebook/www/linkback.php
index bf1ee49e1..b440bc46d 100644
--- a/modules/authfacebook/www/linkback.php
+++ b/modules/authfacebook/www/linkback.php
@@ -6,34 +6,34 @@
 
 // For backwards compatability look for AuthState first
 if (array_key_exists('AuthState', $_REQUEST) && !empty($_REQUEST['AuthState'])) {
-    $state = SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], sspmod_authfacebook_Auth_Source_Facebook::STAGE_INIT);
+    $state = \SimpleSAML\Auth\State::loadState($_REQUEST['AuthState'], sspmod_authfacebook_Auth_Source_Facebook::STAGE_INIT);
 } elseif (array_key_exists('state', $_REQUEST) && !empty($_REQUEST['state'])) {
-    $state = SimpleSAML_Auth_State::loadState($_REQUEST['state'], sspmod_authfacebook_Auth_Source_Facebook::STAGE_INIT);
+    $state = \SimpleSAML\Auth\State::loadState($_REQUEST['state'], sspmod_authfacebook_Auth_Source_Facebook::STAGE_INIT);
 } else {
     throw new \SimpleSAML\Error\BadRequest('Missing state parameter on facebook linkback endpoint.');
 }
 
 // Find authentication source
 if (!array_key_exists(sspmod_authfacebook_Auth_Source_Facebook::AUTHID, $state)) {
-	throw new \SimpleSAML\Error\BadRequest('No data in state for ' . sspmod_authfacebook_Auth_Source_Facebook::AUTHID);
+    throw new \SimpleSAML\Error\BadRequest('No data in state for ' . sspmod_authfacebook_Auth_Source_Facebook::AUTHID);
 }
 $sourceId = $state[sspmod_authfacebook_Auth_Source_Facebook::AUTHID];
 
-$source = SimpleSAML_Auth_Source::getById($sourceId);
-if ($source === NULL) {
-	throw new \SimpleSAML\Error\BadRequest('Could not find authentication source with id ' . var_export($sourceId, TRUE));
+$source = \SimpleSAML\Auth\Source::getById($sourceId);
+if ($source === null) {
+    throw new \SimpleSAML\Error\BadRequest('Could not find authentication source with id ' . var_export($sourceId, TRUE));
 }
 
 try {
-	if (isset($_REQUEST['error_reason']) && $_REQUEST['error_reason'] == 'user_denied') {
-		throw new \SimpleSAML\Error\UserAborted();
-	}
+    if (isset($_REQUEST['error_reason']) && $_REQUEST['error_reason'] == 'user_denied') {
+        throw new \SimpleSAML\Error\UserAborted();
+    }
 
-	$source->finalStep($state);
+    $source->finalStep($state);
 } catch (\SimpleSAML\Error\Exception $e) {
-	SimpleSAML_Auth_State::throwException($state, $e);
-} catch (Exception $e) {
-	SimpleSAML_Auth_State::throwException($state, new \SimpleSAML\Error\AuthSource($sourceId, 'Error on facebook linkback endpoint.', $e));
+    \SimpleSAML\Auth\State::throwException($state, $e);
+} catch (\Exception $e) {
+    \SimpleSAML\Auth\State::throwException($state, new \SimpleSAML\Error\AuthSource($sourceId, 'Error on facebook linkback endpoint.', $e));
 }
 
-SimpleSAML_Auth_Source::completeAuth($state);
+\SimpleSAML\Auth\Source::completeAuth($state);
diff --git a/modules/authlinkedin/lib/Auth/Source/LinkedIn.php b/modules/authlinkedin/lib/Auth/Source/LinkedIn.php
index ff961df0c..c6bebd095 100644
--- a/modules/authlinkedin/lib/Auth/Source/LinkedIn.php
+++ b/modules/authlinkedin/lib/Auth/Source/LinkedIn.php
@@ -8,7 +8,7 @@ require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/oauth/lib
  * @author Brook Schofield, TERENA.
  * @package SimpleSAMLphp
  */
-class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source 
+class sspmod_authlinkedin_Auth_Source_LinkedIn extends \SimpleSAML\Auth\Source 
 {
 
     /**
@@ -72,7 +72,7 @@ class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source
         // We are going to need the authId in order to retrieve this authentication source later
         $state[self::AUTHID] = $this->authId;
 
-        $stateID = SimpleSAML_Auth_State::getStateId($state);
+        $stateID = \SimpleSAML\Auth\State::getStateId($state);
         SimpleSAML\Logger::debug('authlinkedin auth state id = ' . $stateID);
 
         $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
@@ -91,7 +91,7 @@ class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source
         $state['authlinkedin:requestToken'] = $requestToken;
 
         // Update the state
-        SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
+        \SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
 
         // Authorize the request token
         $consumer->getAuthorizeRequest('https://www.linkedin.com/uas/oauth/authenticate', $requestToken);
diff --git a/modules/authlinkedin/www/linkback.php b/modules/authlinkedin/www/linkback.php
index ee6731f1e..e4694e755 100644
--- a/modules/authlinkedin/www/linkback.php
+++ b/modules/authlinkedin/www/linkback.php
@@ -5,27 +5,27 @@
  */
 
 if (!array_key_exists('stateid', $_REQUEST)) {
-    throw new Exception('Lost OAuth Client State');
+    throw new \Exception('Lost OAuth Client State');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['stateid'], sspmod_authlinkedin_Auth_Source_LinkedIn::STAGE_INIT);
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['stateid'], sspmod_authlinkedin_Auth_Source_LinkedIn::STAGE_INIT);
 
 // http://developer.linkedin.com/docs/DOC-1008#2_Redirect_the_User_to_our_Authorization_Server
 if (array_key_exists('oauth_verifier', $_REQUEST)) {
-	$state['authlinkedin:oauth_verifier'] = $_REQUEST['oauth_verifier'];
+    $state['authlinkedin:oauth_verifier'] = $_REQUEST['oauth_verifier'];
 } else {
-	throw new Exception('OAuth verifier not returned.');;
+    throw new Exception('OAuth verifier not returned.');;
 }
 
 // Find authentication source
 assert(array_key_exists(sspmod_authlinkedin_Auth_Source_LinkedIn::AUTHID, $state));
 $sourceId = $state[sspmod_authlinkedin_Auth_Source_LinkedIn::AUTHID];
 
-$source = SimpleSAML_Auth_Source::getById($sourceId);
-if ($source === NULL) {
-	throw new Exception('Could not find authentication source with id ' . $sourceId);
+$source = \SimpleSAML\Auth\Source::getById($sourceId);
+if ($source === null) {
+    throw new \Exception('Could not find authentication source with id ' . $sourceId);
 }
 
 $source->finalStep($state);
 
-SimpleSAML_Auth_Source::completeAuth($state);
+\SimpleSAML\Auth\Source::completeAuth($state);
 
diff --git a/modules/authorize/lib/Auth/Process/Authorize.php b/modules/authorize/lib/Auth/Process/Authorize.php
index 68c5ad009..15127f776 100644
--- a/modules/authorize/lib/Auth/Process/Authorize.php
+++ b/modules/authorize/lib/Auth/Process/Authorize.php
@@ -7,7 +7,7 @@
  * @author Ernesto Revilla, Yaco Sistemas SL., Ryan Panning
  * @package SimpleSAMLphp
  */
-class sspmod_authorize_Auth_Process_Authorize extends SimpleSAML_Auth_ProcessingFilter {
+class sspmod_authorize_Auth_Process_Authorize extends \SimpleSAML\Auth\ProcessingFilter {
 
 	/**
 	 * Flag to deny/unauthorize the user a attribute filter IS found
@@ -124,9 +124,9 @@ class sspmod_authorize_Auth_Process_Authorize extends SimpleSAML_Auth_Processing
 	 */
 	protected function unauthorized(&$request) {
 		// Save state and redirect to 403 page
-		$id = SimpleSAML_Auth_State::saveState($request,
+		$id = \SimpleSAML\Auth\State::saveState($request,
 			'authorize:Authorize');
-		$url = SimpleSAML\Module::getModuleURL(
+		$url = \SimpleSAML\Module::getModuleURL(
 			'authorize/authorize_403.php');
 		\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
 	}
diff --git a/modules/authorize/www/authorize_403.php b/modules/authorize/www/authorize_403.php
index cf352e77e..158fe11a9 100644
--- a/modules/authorize/www/authorize_403.php
+++ b/modules/authorize/www/authorize_403.php
@@ -8,7 +8,7 @@
 if (!array_key_exists('StateId', $_REQUEST)) {
     throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
-$state = \SimpleSAML_Auth_State::loadState($_REQUEST['StateId'], 'authorize:Authorize');
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['StateId'], 'authorize:Authorize');
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 $t = new \SimpleSAML\XHTML\Template($globalConfig, 'authorize:authorize_403.php');
diff --git a/modules/authtwitter/lib/Auth/Source/Twitter.php b/modules/authtwitter/lib/Auth/Source/Twitter.php
index 9278f0eff..d58a7c530 100644
--- a/modules/authtwitter/lib/Auth/Source/Twitter.php
+++ b/modules/authtwitter/lib/Auth/Source/Twitter.php
@@ -8,7 +8,7 @@ require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/oauth/lib
  * @author Andreas Ã…kre Solberg, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_authtwitter_Auth_Source_Twitter extends SimpleSAML_Auth_Source
+class sspmod_authtwitter_Auth_Source_Twitter extends \SimpleSAML\Auth\Source
 {
 	/**
 	 * The string used to identify our states.
@@ -75,7 +75,7 @@ class sspmod_authtwitter_Auth_Source_Twitter extends SimpleSAML_Auth_Source
 		// We are going to need the authId in order to retrieve this authentication source later
 		$state[self::AUTHID] = $this->authId;
 		
-		$stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
+		$stateID = \SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
 		
 		$consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
 		// Get the request token
@@ -85,7 +85,7 @@ class sspmod_authtwitter_Auth_Source_Twitter extends SimpleSAML_Auth_Source
 			$requestToken->key . "] with the secret [" . $requestToken->secret . "]");
 
 		$state['authtwitter:authdata:requestToken'] = $requestToken;
-		SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
+		\SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
 
 		// Authorize the request token
 		$url = 'https://api.twitter.com/oauth/authenticate';
diff --git a/modules/authtwitter/www/linkback.php b/modules/authtwitter/www/linkback.php
index a616e4a9d..d24408ebe 100644
--- a/modules/authtwitter/www/linkback.php
+++ b/modules/authtwitter/www/linkback.php
@@ -5,31 +5,31 @@
  */
 
 if (!array_key_exists('AuthState', $_REQUEST) || empty($_REQUEST['AuthState'])) {
-	throw new \SimpleSAML\Error\BadRequest('Missing state parameter on twitter linkback endpoint.');
+    throw new \SimpleSAML\Error\BadRequest('Missing state parameter on twitter linkback endpoint.');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], sspmod_authtwitter_Auth_Source_Twitter::STAGE_INIT);
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['AuthState'], sspmod_authtwitter_Auth_Source_Twitter::STAGE_INIT);
 
 // Find authentication source
 if (!array_key_exists(sspmod_authtwitter_Auth_Source_Twitter::AUTHID, $state)) {
-	throw new \SimpleSAML\Error\BadRequest('No data in state for ' . sspmod_authtwitter_Auth_Source_Twitter::AUTHID);
+    throw new \SimpleSAML\Error\BadRequest('No data in state for ' . sspmod_authtwitter_Auth_Source_Twitter::AUTHID);
 }
 $sourceId = $state[sspmod_authtwitter_Auth_Source_Twitter::AUTHID];
 
-$source = SimpleSAML_Auth_Source::getById($sourceId);
-if ($source === NULL) {
-	throw new \SimpleSAML\Error\BadRequest('Could not find authentication source with id ' . var_export($sourceId, TRUE));
+$source = \SimpleSAML\Auth\Source::getById($sourceId);
+if ($source === null) {
+    throw new \SimpleSAML\Error\BadRequest('Could not find authentication source with id ' . var_export($sourceId, TRUE));
 }
 
 try {
-	if (array_key_exists('denied', $_REQUEST)) {
-		throw new \SimpleSAML\Error\UserAborted();
-	}
+    if (array_key_exists('denied', $_REQUEST)) {
+        throw new \SimpleSAML\Error\UserAborted();
+    }
 
-	$source->finalStep($state);
+    $source->finalStep($state);
 } catch (\SimpleSAML\Error\Exception $e) {
-	SimpleSAML_Auth_State::throwException($state, $e);
-} catch (Exception $e) {
-	SimpleSAML_Auth_State::throwException($state, new \SimpleSAML\Error\AuthSource($sourceId, 'Error on authtwitter linkback endpoint.', $e));
+    \SimpleSAML\Auth\State::throwException($state, $e);
+} catch (\Exception $e) {
+    \SimpleSAML\Auth\State::throwException($state, new \SimpleSAML\Error\AuthSource($sourceId, 'Error on authtwitter linkback endpoint.', $e));
 }
 
-SimpleSAML_Auth_Source::completeAuth($state);
+\SimpleSAML\Auth\Source::completeAuth($state);
diff --git a/modules/authwindowslive/lib/Auth/Source/LiveID.php b/modules/authwindowslive/lib/Auth/Source/LiveID.php
index 39fbfd159..1e3ef2045 100644
--- a/modules/authwindowslive/lib/Auth/Source/LiveID.php
+++ b/modules/authwindowslive/lib/Auth/Source/LiveID.php
@@ -7,7 +7,7 @@
  * @author Guy Halse, TENET.
  * @package SimpleSAMLphp
  */
-class sspmod_authwindowslive_Auth_Source_LiveID extends SimpleSAML_Auth_Source
+class sspmod_authwindowslive_Auth_Source_LiveID extends \SimpleSAML\Auth\Source
 {
 
     /**
@@ -66,7 +66,7 @@ class sspmod_authwindowslive_Auth_Source_LiveID extends SimpleSAML_Auth_Source
         // we are going to need the authId in order to retrieve this authentication source later
         $state[self::AUTHID] = $this->authId;
 
-        $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
+        $stateID = \SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
 
         SimpleSAML\Logger::debug('authwindowslive auth state id = ' . $stateID);
 
diff --git a/modules/authwindowslive/www/linkback.php b/modules/authwindowslive/www/linkback.php
index a002e22e4..8b407d7ac 100644
--- a/modules/authwindowslive/www/linkback.php
+++ b/modules/authwindowslive/www/linkback.php
@@ -5,9 +5,9 @@
  */
 
 if (!array_key_exists('state', $_REQUEST)) {
-    throw new Exception('Lost OAuth Client State');
+    throw new \Exception('Lost OAuth Client State');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['state'], sspmod_authwindowslive_Auth_Source_LiveID::STAGE_INIT);
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['state'], sspmod_authwindowslive_Auth_Source_LiveID::STAGE_INIT);
 
 // http://msdn.microsoft.com/en-us/library/ff749771.aspx
 if (array_key_exists('code', $_REQUEST)) {
@@ -25,22 +25,22 @@ if (array_key_exists('code', $_REQUEST)) {
     // redirect them to their original page so they can choose another auth mechanism
     if ($_REQUEST['error'] === 'user_denied') {
         $e = new \SimpleSAML\Error\UserAborted();
-        SimpleSAML_Auth_State::throwException($state, $e);
+        \SimpleSAML\Auth\State::throwException($state, $e);
     }
 
     // error
-    throw new Exception('Authentication failed: ['.$_REQUEST['error'].'] '.$_REQUEST['error_description']);
+    throw new \Exception('Authentication failed: ['.$_REQUEST['error'].'] '.$_REQUEST['error_description']);
 }
 
 // find authentication source
 assert(array_key_exists(sspmod_authwindowslive_Auth_Source_LiveID::AUTHID, $state));
 $sourceId = $state[sspmod_authwindowslive_Auth_Source_LiveID::AUTHID];
 
-$source = SimpleSAML_Auth_Source::getById($sourceId);
+$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);
 }
 
 $source->finalStep($state);
 
-SimpleSAML_Auth_Source::completeAuth($state);
+\SimpleSAML\Auth\Source::completeAuth($state);
diff --git a/modules/cas/lib/Auth/Source/CAS.php b/modules/cas/lib/Auth/Source/CAS.php
index 78fc07403..9195bd89a 100644
--- a/modules/cas/lib/Auth/Source/CAS.php
+++ b/modules/cas/lib/Auth/Source/CAS.php
@@ -9,7 +9,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_cas_Auth_Source_CAS extends SimpleSAML_Auth_Source
+class sspmod_cas_Auth_Source_CAS extends \SimpleSAML\Auth\Source
 {
     /**
      * The string used to identify our states.
@@ -182,15 +182,15 @@ class sspmod_cas_Auth_Source_CAS extends SimpleSAML_Auth_Source
     public function finalStep(&$state)
     {
         $ticket = $state['cas:ticket'];
-        $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
-        $service =  SimpleSAML\Module::getModuleURL('cas/linkback.php', array('stateID' => $stateID));
+        $stateID = \SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
+        $service =  \SimpleSAML\Module::getModuleURL('cas/linkback.php', array('stateID' => $stateID));
         list($username, $casattributes) = $this->casValidation($ticket, $service);
         $ldapattributes = array();
 
         $config = \SimpleSAML\Configuration::loadFromArray($this->_ldapConfig,
             'Authentication source ' . var_export($this->authId, true));
         if ($this->_ldapConfig['servers']) {
-            $ldap = new SimpleSAML_Auth_LDAP(
+            $ldap = new \SimpleSAML\Auth\LDAP(
                 $config->getString('servers'),
                 $config->getBoolean('enable_tls', false),
                 $config->getBoolean('debug', false),
@@ -203,7 +203,7 @@ class sspmod_cas_Auth_Source_CAS extends SimpleSAML_Auth_Source
         $attributes = array_merge_recursive($casattributes, $ldapattributes);
         $state['Attributes'] = $attributes;
 
-        SimpleSAML_Auth_Source::completeAuth($state);
+        \SimpleSAML\Auth\Source::completeAuth($state);
     }
 
 
@@ -219,7 +219,7 @@ class sspmod_cas_Auth_Source_CAS extends SimpleSAML_Auth_Source
         // We are going to need the authId in order to retrieve this authentication source later
         $state[self::AUTHID] = $this->authId;
 
-        $stateID = SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
+        $stateID = \SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
 
         $serviceUrl = SimpleSAML\Module::getModuleURL('cas/linkback.php', array('stateID' => $stateID));
 
@@ -245,7 +245,7 @@ class sspmod_cas_Auth_Source_CAS extends SimpleSAML_Auth_Source
         assert(is_array($state));
         $logoutUrl = $this->_casConfig['logout'];
 
-        SimpleSAML_Auth_State::deleteState($state);
+        \SimpleSAML\Auth\State::deleteState($state);
         // we want cas to log us out
         \SimpleSAML\Utils\HTTP::redirectTrustedURL($logoutUrl);
     }
diff --git a/modules/cas/www/linkback.php b/modules/cas/www/linkback.php
index db7dc5d50..3b1699d9e 100644
--- a/modules/cas/www/linkback.php
+++ b/modules/cas/www/linkback.php
@@ -7,7 +7,7 @@
 if (!isset($_GET['stateID'])) {
     throw new \SimpleSAML\Error\BadRequest('Missing stateID parameter.');
 }
-$state = SimpleSAML_Auth_State::loadState($_GET['stateID'], sspmod_cas_Auth_Source_CAS::STAGE_INIT);
+$state = \SimpleSAML\Auth\State::loadState($_GET['stateID'], sspmod_cas_Auth_Source_CAS::STAGE_INIT);
 
 if (!isset($_GET['ticket'])) {
     throw new \SimpleSAML\Error\BadRequest('Missing ticket parameter.');
@@ -18,7 +18,7 @@ $state['cas:ticket'] = (string)$_GET['ticket'];
 assert(array_key_exists(sspmod_cas_Auth_Source_CAS::AUTHID, $state));
 $sourceId = $state[sspmod_cas_Auth_Source_CAS::AUTHID];
 
-$source = SimpleSAML_Auth_Source::getById($sourceId);
+$source = \SimpleSAML\Auth\Source::getById($sourceId);
 if ($source === null) {
     throw new Exception('Could not find authentication source with id ' . $sourceId);
 }
diff --git a/modules/cdc/lib/Auth/Process/CDC.php b/modules/cdc/lib/Auth/Process/CDC.php
index 036267580..d3f1eb0e8 100644
--- a/modules/cdc/lib/Auth/Process/CDC.php
+++ b/modules/cdc/lib/Auth/Process/CDC.php
@@ -5,7 +5,7 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_cdc_Auth_Process_CDC extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_cdc_Auth_Process_CDC extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * Our CDC domain.
@@ -58,9 +58,9 @@ class sspmod_cdc_Auth_Process_CDC extends SimpleSAML_Auth_ProcessingFilter
         }
 
         // Save state and build request
-        $id = SimpleSAML_Auth_State::saveState($state, 'cdc:resume');
+        $id = \SimpleSAML\Auth\State::saveState($state, 'cdc:resume');
 
-        $returnTo = SimpleSAML\Module::getModuleURL('cdc/resume.php', array('domain' => $this->domain));
+        $returnTo = \SimpleSAML\Module::getModuleURL('cdc/resume.php', array('domain' => $this->domain));
 
         $params = array(
             'id' => $id,
diff --git a/modules/cdc/www/resume.php b/modules/cdc/www/resume.php
index 76da69dd7..903e13fb4 100644
--- a/modules/cdc/www/resume.php
+++ b/modules/cdc/www/resume.php
@@ -16,6 +16,6 @@ if ($response === null) {
 if (!isset($response['id'])) {
     throw new \SimpleSAML\Error\BadRequest('CDCResponse without id.');
 }
-$state = SimpleSAML_Auth_State::loadState($response['id'], 'cdc:resume');
+$state = \SimpleSAML\Auth\State::loadState($response['id'], 'cdc:resume');
 
-SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+\SimpleSAML\Auth\ProcessingChain::resumeProcessing($state);
diff --git a/modules/consent/lib/Auth/Process/Consent.php b/modules/consent/lib/Auth/Process/Consent.php
index 6cf65a241..9b0fdd110 100644
--- a/modules/consent/lib/Auth/Process/Consent.php
+++ b/modules/consent/lib/Auth/Process/Consent.php
@@ -9,7 +9,7 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_consent_Auth_Process_Consent extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * Button to receive focus
@@ -335,7 +335,7 @@ class sspmod_consent_Auth_Process_Consent extends SimpleSAML_Auth_ProcessingFilt
         }
 
         // Save state and redirect
-        $id = SimpleSAML_Auth_State::saveState($state, 'consent:request');
+        $id = \SimpleSAML\Auth\State::saveState($state, 'consent:request');
         $url = SimpleSAML\Module::getModuleURL('consent/getconsent.php');
         \SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
     }
diff --git a/modules/consent/www/getconsent.php b/modules/consent/www/getconsent.php
index 4c863a3b7..9265b071b 100644
--- a/modules/consent/www/getconsent.php
+++ b/modules/consent/www/getconsent.php
@@ -30,7 +30,7 @@ if (!array_key_exists('StateId', $_REQUEST)) {
 }
 
 $id = $_REQUEST['StateId'];
-$state = SimpleSAML_Auth_State::loadState($id, 'consent:request');
+$state = \SimpleSAML\Auth\State::loadState($id, 'consent:request');
 
 if (array_key_exists('core:SP', $state)) {
     $spentityid = $state['core:SP'];
@@ -78,7 +78,7 @@ if (array_key_exists('yes', $_REQUEST)) {
         }
     }
 
-    \SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+    \SimpleSAML\Auth\ProcessingChain::resumeProcessing($state);
 }
 
 // Prepare attributes for presentation
diff --git a/modules/consent/www/logout.php b/modules/consent/www/logout.php
index 84eca697c..50d551926 100644
--- a/modules/consent/www/logout.php
+++ b/modules/consent/www/logout.php
@@ -8,7 +8,7 @@
 if (!array_key_exists('StateId', $_GET)) {
     throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
-$state = \SimpleSAML_Auth_State::loadState($_GET['StateId'], 'consent:request');
+$state = \SimpleSAML\Auth\State::loadState($_GET['StateId'], 'consent:request');
 
 $state['Responder'] = array('sspmod_consent_Logout', 'postLogout');
 
diff --git a/modules/consent/www/noconsent.php b/modules/consent/www/noconsent.php
index 225f8b215..dcf09d60e 100644
--- a/modules/consent/www/noconsent.php
+++ b/modules/consent/www/noconsent.php
@@ -13,7 +13,7 @@ if (!array_key_exists('StateId', $_REQUEST)) {
 }
 
 $id = $_REQUEST['StateId'];
-$state = \SimpleSAML_Auth_State::loadState($id, 'consent:request');
+$state = \SimpleSAML\Auth\State::loadState($id, 'consent:request');
 
 $resumeFrom = \SimpleSAML\Module::getModuleURL(
     'consent/getconsent.php',
diff --git a/modules/consentAdmin/www/consentAdmin.php b/modules/consentAdmin/www/consentAdmin.php
index d9a200151..4ff6031be 100644
--- a/modules/consentAdmin/www/consentAdmin.php
+++ b/modules/consentAdmin/www/consentAdmin.php
@@ -29,7 +29,7 @@ function driveProcessingChain(
     /*
      * Create a new processing chain
      */
-    $pc = new SimpleSAML_Auth_ProcessingChain($idp_metadata, $sp_metadata, 'idp');
+    $pc = new \SimpleSAML\Auth\ProcessingChain($idp_metadata, $sp_metadata, 'idp');
 
     /*
      * Construct the state.
diff --git a/modules/core/lib/Auth/Process/AttributeAdd.php b/modules/core/lib/Auth/Process/AttributeAdd.php
index 63aa03fb2..1eaaf331a 100644
--- a/modules/core/lib/Auth/Process/AttributeAdd.php
+++ b/modules/core/lib/Auth/Process/AttributeAdd.php
@@ -8,7 +8,7 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_AttributeAdd extends SimpleSAML_Auth_ProcessingFilter {
+class sspmod_core_Auth_Process_AttributeAdd extends \SimpleSAML\Auth\ProcessingFilter {
 
 	/**
 	 * Flag which indicates wheter this filter should append new values or replace old values.
diff --git a/modules/core/lib/Auth/Process/AttributeAlter.php b/modules/core/lib/Auth/Process/AttributeAlter.php
index d6daf9623..1f6743405 100644
--- a/modules/core/lib/Auth/Process/AttributeAlter.php
+++ b/modules/core/lib/Auth/Process/AttributeAlter.php
@@ -9,7 +9,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_core_Auth_Process_AttributeAlter extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * Should the pattern found be replaced?
diff --git a/modules/core/lib/Auth/Process/AttributeCopy.php b/modules/core/lib/Auth/Process/AttributeCopy.php
index e2412a45c..0f2e7b2fe 100644
--- a/modules/core/lib/Auth/Process/AttributeCopy.php
+++ b/modules/core/lib/Auth/Process/AttributeCopy.php
@@ -15,8 +15,9 @@
  *         ),
  *
  */
-class sspmod_core_Auth_Process_AttributeCopy extends SimpleSAML_Auth_ProcessingFilter {
 
+class sspmod_core_Auth_Process_AttributeCopy extends \SimpleSAML\Auth\ProcessingFilter
+{
 	/**
 	 * Assosiative array with the mappings of attribute names.
 	 */
diff --git a/modules/core/lib/Auth/Process/AttributeLimit.php b/modules/core/lib/Auth/Process/AttributeLimit.php
index 865b38353..cffe4f8c0 100644
--- a/modules/core/lib/Auth/Process/AttributeLimit.php
+++ b/modules/core/lib/Auth/Process/AttributeLimit.php
@@ -6,8 +6,9 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_AttributeLimit extends SimpleSAML_Auth_ProcessingFilter {
 
+class sspmod_core_Auth_Process_AttributeLimit extends \SimpleSAML\Auth\ProcessingFilter
+{
 	/**
 	 * List of attributes which this filter will allow through.
 	 */
diff --git a/modules/core/lib/Auth/Process/AttributeMap.php b/modules/core/lib/Auth/Process/AttributeMap.php
index ccd7addf1..29135c2ee 100644
--- a/modules/core/lib/Auth/Process/AttributeMap.php
+++ b/modules/core/lib/Auth/Process/AttributeMap.php
@@ -1,15 +1,14 @@
 <?php
 
-
 /**
  * Attribute filter for renaming attributes.
  *
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_AttributeMap extends SimpleSAML_Auth_ProcessingFilter
-{
 
+class sspmod_core_Auth_Process_AttributeMap extends \SimpleSAML\Auth\ProcessingFilter
+{
     /**
      * Associative array with the mappings of attribute names.
      */
diff --git a/modules/core/lib/Auth/Process/AttributeRealm.php b/modules/core/lib/Auth/Process/AttributeRealm.php
index 86c8be1b2..bf2a8cfad 100644
--- a/modules/core/lib/Auth/Process/AttributeRealm.php
+++ b/modules/core/lib/Auth/Process/AttributeRealm.php
@@ -8,8 +8,9 @@
  * @package SimpleSAMLphp
  * @deprecated Use ScopeFromAttribute instead.
  */
-class sspmod_core_Auth_Process_AttributeRealm extends SimpleSAML_Auth_ProcessingFilter {
 
+class sspmod_core_Auth_Process_AttributeRealm extends \SimpleSAML\Auth\ProcessingFilter
+{
     private $attributename = 'realm';
 
     /**
diff --git a/modules/core/lib/Auth/Process/AttributeValueMap.php b/modules/core/lib/Auth/Process/AttributeValueMap.php
index a83fb582a..293bc9b13 100644
--- a/modules/core/lib/Auth/Process/AttributeValueMap.php
+++ b/modules/core/lib/Auth/Process/AttributeValueMap.php
@@ -8,9 +8,9 @@ namespace SimpleSAML\Module\core\Auth\Process;
  * @author Martin van Es, m7
  * @package SimpleSAMLphp
  */
-class AttributeValueMap extends \SimpleSAML_Auth_ProcessingFilter
-{
 
+class AttributeValueMap extends \SimpleSAML\Auth\ProcessingFilter
+{
     /**
     * The name of the attribute we should assign values to (ie: the target attribute).
     */
diff --git a/modules/core/lib/Auth/Process/Cardinality.php b/modules/core/lib/Auth/Process/Cardinality.php
index 59fdc392b..2960e86fe 100644
--- a/modules/core/lib/Auth/Process/Cardinality.php
+++ b/modules/core/lib/Auth/Process/Cardinality.php
@@ -8,7 +8,8 @@ use SimpleSAML\Utils\HTTPAdapter;
  * @author Guy Halse, http://orcid.org/0000-0002-9388-8592
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_Cardinality extends SimpleSAML_Auth_ProcessingFilter
+
+class sspmod_core_Auth_Process_Cardinality extends \SimpleSAML\Auth\ProcessingFilter
 {
     /** @var array Associative array with the mappings of attribute names. */
     private $cardinality = array();
@@ -163,8 +164,8 @@ class sspmod_core_Auth_Process_Cardinality extends SimpleSAML_Auth_ProcessingFil
 
         /* abort if we found a problematic attribute */
         if (array_key_exists('core:cardinality:errorAttributes', $request)) {
-            $id = SimpleSAML_Auth_State::saveState($request, 'core:cardinality');
-            $url = SimpleSAML\Module::getModuleURL('core/cardinality_error.php');
+            $id = \SimpleSAML\Auth\State::saveState($request, 'core:cardinality');
+            $url = \SimpleSAML\Module::getModuleURL('core/cardinality_error.php');
             $this->http->redirectTrustedURL($url, array('StateId' => $id));
             return;
         }
diff --git a/modules/core/lib/Auth/Process/CardinalitySingle.php b/modules/core/lib/Auth/Process/CardinalitySingle.php
index 173d95c5c..dc8672b68 100644
--- a/modules/core/lib/Auth/Process/CardinalitySingle.php
+++ b/modules/core/lib/Auth/Process/CardinalitySingle.php
@@ -11,7 +11,8 @@ use SimpleSAML\Utils\HttpAdapter;
  * @author Guy Halse, http://orcid.org/0000-0002-9388-8592
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_CardinalitySingle extends SimpleSAML_Auth_ProcessingFilter
+
+class sspmod_core_Auth_Process_CardinalitySingle extends \SimpleSAML\Auth\ProcessingFilter
 {
     /** @var array Attributes that should be single-valued or we generate an error */
     private $singleValued = array();
@@ -108,7 +109,7 @@ class sspmod_core_Auth_Process_CardinalitySingle extends SimpleSAML_Auth_Process
 
         /* abort if we found a problematic attribute */
         if (array_key_exists('core:cardinality:errorAttributes', $request)) {
-            $id = SimpleSAML_Auth_State::saveState($request, 'core:cardinality');
+            $id = \SimpleSAML\Auth\State::saveState($request, 'core:cardinality');
             $url = SimpleSAML\Module::getModuleURL('core/cardinality_error.php');
             $this->http->redirectTrustedURL($url, array('StateId' => $id));
             return;
diff --git a/modules/core/lib/Auth/Process/ExtendIdPSession.php b/modules/core/lib/Auth/Process/ExtendIdPSession.php
index 43780fe99..6526115dc 100644
--- a/modules/core/lib/Auth/Process/ExtendIdPSession.php
+++ b/modules/core/lib/Auth/Process/ExtendIdPSession.php
@@ -3,8 +3,9 @@
 /**
  * Extend IdP session and cookies.
 */
-class sspmod_core_Auth_Process_ExtendIdPSession extends SimpleSAML_Auth_ProcessingFilter {
 
+class sspmod_core_Auth_Process_ExtendIdPSession extends \SimpleSAML\Auth\ProcessingFilter
+{
 	public function process(&$state) {
 		assert(is_array($state));
 
diff --git a/modules/core/lib/Auth/Process/GenerateGroups.php b/modules/core/lib/Auth/Process/GenerateGroups.php
index 17b896e5f..d4ff3c338 100644
--- a/modules/core/lib/Auth/Process/GenerateGroups.php
+++ b/modules/core/lib/Auth/Process/GenerateGroups.php
@@ -6,9 +6,9 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_GenerateGroups extends SimpleSAML_Auth_ProcessingFilter {
-
 
+class sspmod_core_Auth_Process_GenerateGroups extends \SimpleSAML\Auth\ProcessingFilter
+{
 	/**
 	 * The attributes we should generate groups from.
 	 */
diff --git a/modules/core/lib/Auth/Process/LanguageAdaptor.php b/modules/core/lib/Auth/Process/LanguageAdaptor.php
index 4a1b38140..c02228dd7 100644
--- a/modules/core/lib/Auth/Process/LanguageAdaptor.php
+++ b/modules/core/lib/Auth/Process/LanguageAdaptor.php
@@ -6,8 +6,9 @@
  * @author Andreas Ã…kre Solberg, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_LanguageAdaptor extends SimpleSAML_Auth_ProcessingFilter {
 
+class sspmod_core_Auth_Process_LanguageAdaptor extends \SimpleSAML\Auth\ProcessingFilter
+{
 	private $langattr = 'preferredLanguage';
 
 
diff --git a/modules/core/lib/Auth/Process/PHP.php b/modules/core/lib/Auth/Process/PHP.php
index 2fb3d5352..97cca71a0 100644
--- a/modules/core/lib/Auth/Process/PHP.php
+++ b/modules/core/lib/Auth/Process/PHP.php
@@ -6,7 +6,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_core_Auth_Process_PHP extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_core_Auth_Process_PHP extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * The PHP code that should be run.
diff --git a/modules/core/lib/Auth/Process/ScopeAttribute.php b/modules/core/lib/Auth/Process/ScopeAttribute.php
index 251ef0917..7684b18d6 100644
--- a/modules/core/lib/Auth/Process/ScopeAttribute.php
+++ b/modules/core/lib/Auth/Process/ScopeAttribute.php
@@ -5,7 +5,8 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_ScopeAttribute extends SimpleSAML_Auth_ProcessingFilter
+
+class sspmod_core_Auth_Process_ScopeAttribute extends \SimpleSAML\Auth\ProcessingFilter
 {
 	/**
 	 * The attribute we extract the scope from.
diff --git a/modules/core/lib/Auth/Process/ScopeFromAttribute.php b/modules/core/lib/Auth/Process/ScopeFromAttribute.php
index 098856f99..735c30e1c 100644
--- a/modules/core/lib/Auth/Process/ScopeFromAttribute.php
+++ b/modules/core/lib/Auth/Process/ScopeFromAttribute.php
@@ -16,7 +16,9 @@
  * to add a virtual 'scope' attribute from the eduPersonPrincipalName
  * attribute.
  */
-class sspmod_core_Auth_Process_ScopeFromAttribute extends SimpleSAML_Auth_ProcessingFilter {
+
+class sspmod_core_Auth_Process_ScopeFromAttribute extends \SimpleSAML\Auth\ProcessingFilter
+{
 	/**
 	 * The attribute where the scope is taken from
 	 *
diff --git a/modules/core/lib/Auth/Process/StatisticsWithAttribute.php b/modules/core/lib/Auth/Process/StatisticsWithAttribute.php
index 800558cbd..d75b474fc 100644
--- a/modules/core/lib/Auth/Process/StatisticsWithAttribute.php
+++ b/modules/core/lib/Auth/Process/StatisticsWithAttribute.php
@@ -6,7 +6,8 @@
  * @author Andreas Ã…kre Solberg, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_StatisticsWithAttribute extends SimpleSAML_Auth_ProcessingFilter
+
+class sspmod_core_Auth_Process_StatisticsWithAttribute extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * The attribute to log
diff --git a/modules/core/lib/Auth/Process/TargetedID.php b/modules/core/lib/Auth/Process/TargetedID.php
index 3b70f02aa..69888dc84 100644
--- a/modules/core/lib/Auth/Process/TargetedID.php
+++ b/modules/core/lib/Auth/Process/TargetedID.php
@@ -28,9 +28,9 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_TargetedID extends SimpleSAML_Auth_ProcessingFilter {
-
 
+class sspmod_core_Auth_Process_TargetedID extends \SimpleSAML\Auth\ProcessingFilter
+{
 	/**
 	 * The attribute we should generate the targeted id from, or NULL if we should use the
 	 * UserID.
diff --git a/modules/core/lib/Auth/Process/WarnShortSSOInterval.php b/modules/core/lib/Auth/Process/WarnShortSSOInterval.php
index d8ae6fa0a..74c7b5dd0 100644
--- a/modules/core/lib/Auth/Process/WarnShortSSOInterval.php
+++ b/modules/core/lib/Auth/Process/WarnShortSSOInterval.php
@@ -5,8 +5,9 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_core_Auth_Process_WarnShortSSOInterval extends SimpleSAML_Auth_ProcessingFilter {
 
+class sspmod_core_Auth_Process_WarnShortSSOInterval extends \SimpleSAML\Auth\ProcessingFilter
+{
 	/**
 	 * Process a authentication response.
 	 *
@@ -44,8 +45,8 @@ class sspmod_core_Auth_Process_WarnShortSSOInterval extends SimpleSAML_Auth_Proc
 			var_export($entityId, TRUE));
 
 		// Save state and redirect
-		$id = SimpleSAML_Auth_State::saveState($state, 'core:short_sso_interval');
-		$url = SimpleSAML\Module::getModuleURL('core/short_sso_interval.php');
+		$id = \SimpleSAML\Auth\State::saveState($state, 'core:short_sso_interval');
+		$url = \SimpleSAML\Module::getModuleURL('core/short_sso_interval.php');
 		\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
 	}
 
diff --git a/modules/core/lib/Auth/UserPassBase.php b/modules/core/lib/Auth/UserPassBase.php
index 47ce27467..ec63c8ffa 100644
--- a/modules/core/lib/Auth/UserPassBase.php
+++ b/modules/core/lib/Auth/UserPassBase.php
@@ -10,7 +10,7 @@
  * @package SimpleSAMLphp
  */
 
-abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source
+abstract class sspmod_core_Auth_UserPassBase extends \SimpleSAML\Auth\Source
 {
 	/**
 	 * The string used to identify our states.
@@ -203,7 +203,7 @@ abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source
 	  }
 
 		/* Save the $state-array, so that we can restore it after a redirect. */
-		$id = SimpleSAML_Auth_State::saveState($state, self::STAGEID);
+		$id = \SimpleSAML\Auth\State::saveState($state, self::STAGEID);
 
 		/*
 		 * Redirect to the login form. We include the identifier of the saved
@@ -251,11 +251,11 @@ abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source
 		assert(is_string($password));
 
 		/* Here we retrieve the state array we saved in the authenticate-function. */
-		$state = SimpleSAML_Auth_State::loadState($authStateId, self::STAGEID);
+		$state = \SimpleSAML\Auth\State::loadState($authStateId, self::STAGEID);
 
 		/* Retrieve the authentication source we are executing. */
 		assert(array_key_exists(self::AUTHID, $state));
-		$source = SimpleSAML_Auth_Source::getById($state[self::AUTHID]);
+		$source = \SimpleSAML\Auth\Source::getById($state[self::AUTHID]);
 		if ($source === NULL) {
 			throw new Exception('Could not find authentication source with id ' . $state[self::AUTHID]);
 		}
@@ -280,7 +280,7 @@ abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source
 		$state['Attributes'] = $attributes;
 
 		/* Return control to SimpleSAMLphp after successful authentication. */
-		SimpleSAML_Auth_Source::completeAuth($state);
+		\SimpleSAML\Auth\Source::completeAuth($state);
 	}
 
 }
diff --git a/modules/core/lib/Auth/UserPassOrgBase.php b/modules/core/lib/Auth/UserPassOrgBase.php
index 487cef1d7..e3207ee37 100644
--- a/modules/core/lib/Auth/UserPassOrgBase.php
+++ b/modules/core/lib/Auth/UserPassOrgBase.php
@@ -12,7 +12,7 @@
  * @package SimpleSAMLphp
  */
 
-abstract class sspmod_core_Auth_UserPassOrgBase extends SimpleSAML_Auth_Source
+abstract class sspmod_core_Auth_UserPassOrgBase extends \SimpleSAML\Auth\Source
 {
 	/**
 	 * The string used to identify our states.
@@ -152,7 +152,7 @@ abstract class sspmod_core_Auth_UserPassOrgBase extends SimpleSAML_Auth_Source
 		// We are going to need the authId in order to retrieve this authentication source later
 		$state[self::AUTHID] = $this->authId;
 
-		$id = SimpleSAML_Auth_State::saveState($state, self::STAGEID);
+		$id = \SimpleSAML\Auth\State::saveState($state, self::STAGEID);
 
 		$url = SimpleSAML\Module::getModuleURL('core/loginuserpassorg.php');
 		$params = array('AuthState' => $id);
@@ -209,11 +209,11 @@ abstract class sspmod_core_Auth_UserPassOrgBase extends SimpleSAML_Auth_Source
 		assert(is_string($organization));
 
 		/* Retrieve the authentication state. */
-		$state = SimpleSAML_Auth_State::loadState($authStateId, self::STAGEID);
+		$state = \SimpleSAML\Auth\State::loadState($authStateId, self::STAGEID);
 
 		/* Find authentication source. */
 		assert(array_key_exists(self::AUTHID, $state));
-		$source = SimpleSAML_Auth_Source::getById($state[self::AUTHID]);
+		$source = \SimpleSAML\Auth\Source::getById($state[self::AUTHID]);
 		if ($source === NULL) {
 			throw new Exception('Could not find authentication source with id ' . $state[self::AUTHID]);
 		}
@@ -240,7 +240,7 @@ abstract class sspmod_core_Auth_UserPassOrgBase extends SimpleSAML_Auth_Source
 		$state['PersistentAuthData'][] = self::ORGID;
 
 		$state['Attributes'] = $attributes;
-		SimpleSAML_Auth_Source::completeAuth($state);
+		\SimpleSAML\Auth\Source::completeAuth($state);
 	}
 
 
@@ -257,11 +257,11 @@ abstract class sspmod_core_Auth_UserPassOrgBase extends SimpleSAML_Auth_Source
 		assert(is_string($authStateId));
 
 		/* Retrieve the authentication state. */
-		$state = SimpleSAML_Auth_State::loadState($authStateId, self::STAGEID);
+		$state = \SimpleSAML\Auth\State::loadState($authStateId, self::STAGEID);
 
 		/* Find authentication source. */
 		assert(array_key_exists(self::AUTHID, $state));
-		$source = SimpleSAML_Auth_Source::getById($state[self::AUTHID]);
+		$source = \SimpleSAML\Auth\Source::getById($state[self::AUTHID]);
 		if ($source === NULL) {
 			throw new Exception('Could not find authentication source with id ' . $state[self::AUTHID]);
 		}
diff --git a/modules/core/www/authenticate.php b/modules/core/www/authenticate.php
index 47a922044..df978a8f1 100644
--- a/modules/core/www/authenticate.php
+++ b/modules/core/www/authenticate.php
@@ -5,7 +5,7 @@ $config = \SimpleSAML\Configuration::getInstance();
 if (!array_key_exists('as', $_REQUEST)) {
     $t = new \SimpleSAML\XHTML\Template($config, 'core:authsource_list.tpl.php');
 
-    $t->data['sources'] = \SimpleSAML_Auth_Source::getSources();
+    $t->data['sources'] = \SimpleSAML\Auth\Source::getSources();
     $t->show();
     exit();
 }
@@ -17,12 +17,12 @@ if (array_key_exists('logout', $_REQUEST)) {
     $as->logout($config->getBasePath().'logout.php');
 }
 
-if (array_key_exists(\SimpleSAML_Auth_State::EXCEPTION_PARAM, $_REQUEST)) {
+if (array_key_exists(\SimpleSAML\Auth\State::EXCEPTION_PARAM, $_REQUEST)) {
     // This is just a simple example of an error
 
-    $state = \SimpleSAML_Auth_State::loadExceptionState();
-    assert(array_key_exists(\SimpleSAML_Auth_State::EXCEPTION_DATA, $state));
-    $e = $state[\SimpleSAML_Auth_State::EXCEPTION_DATA];
+    $state = \SimpleSAML\Auth\State::loadExceptionState();
+    assert(array_key_exists(\SimpleSAML\Auth\State::EXCEPTION_DATA, $state));
+    $e = $state[\SimpleSAML\Auth\State::EXCEPTION_DATA];
 
     throw $e;
 }
diff --git a/modules/core/www/cardinality_error.php b/modules/core/www/cardinality_error.php
index 9236c9452..c73a4fee6 100644
--- a/modules/core/www/cardinality_error.php
+++ b/modules/core/www/cardinality_error.php
@@ -10,7 +10,7 @@ if (!array_key_exists('StateId', $_REQUEST)) {
     throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = \SimpleSAML_Auth_State::loadState($id, 'core:cardinality');
+$state = \SimpleSAML\Auth\State::loadState($id, 'core:cardinality');
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
 \SimpleSAML\Logger::stats('core:cardinality:error '.$state['Destination']['entityid'].' '.$state['saml:sp:IdP'].
diff --git a/modules/core/www/idp/logout-iframe-done.php b/modules/core/www/idp/logout-iframe-done.php
index cefeb701a..b99870ca3 100644
--- a/modules/core/www/idp/logout-iframe-done.php
+++ b/modules/core/www/idp/logout-iframe-done.php
@@ -3,7 +3,7 @@
 if (!isset($_REQUEST['id'])) {
     throw new \SimpleSAML\Error\BadRequest('Missing required parameter: id');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['id'], 'core:Logout-IFrame');
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['id'], 'core:Logout-IFrame');
 $idp = SimpleSAML_IdP::getByState($state);
 
 $associations = $idp->getAssociations();
diff --git a/modules/core/www/idp/logout-iframe.php b/modules/core/www/idp/logout-iframe.php
index 332b86d63..4916c1199 100644
--- a/modules/core/www/idp/logout-iframe.php
+++ b/modules/core/www/idp/logout-iframe.php
@@ -18,7 +18,7 @@ if ($type !== 'embed') {
     \SimpleSAML_Stats::log('core:idp:logout-iframe:page', array('type' => $type));
 }
 
-$state = \SimpleSAML_Auth_State::loadState($_REQUEST['id'], 'core:Logout-IFrame');
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['id'], 'core:Logout-IFrame');
 $idp = \SimpleSAML_IdP::getByState($state);
 $mdh = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
@@ -112,7 +112,7 @@ foreach ($state['core:Logout-IFrame:Associations'] as $association) {
     }
 }
 
-$id = \SimpleSAML_Auth_State::saveState($state, 'core:Logout-IFrame');
+$id = \SimpleSAML\Auth\State::saveState($state, 'core:Logout-IFrame');
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 
 $template_id = 'core:logout-iframe.php';
diff --git a/modules/core/www/idp/resumelogout.php b/modules/core/www/idp/resumelogout.php
index 6a142ad57..497e369b8 100644
--- a/modules/core/www/idp/resumelogout.php
+++ b/modules/core/www/idp/resumelogout.php
@@ -3,7 +3,7 @@
 if (!isset($_REQUEST['id'])) {
     throw new \SimpleSAML\Error\BadRequest('Missing id-parameter.');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['id'], 'core:Logout:afterbridge');
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['id'], 'core:Logout:afterbridge');
 $idp = SimpleSAML_IdP::getByState($state);
 
 $assocId = $state['core:TerminatedAssocId'];
diff --git a/modules/core/www/loginuserpass.php b/modules/core/www/loginuserpass.php
index 169ef792e..51cd91b63 100644
--- a/modules/core/www/loginuserpass.php
+++ b/modules/core/www/loginuserpass.php
@@ -14,9 +14,9 @@ if (!array_key_exists('AuthState', $_REQUEST)) {
 	throw new \SimpleSAML\Error\BadRequest('Missing AuthState parameter.');
 }
 $authStateId = $_REQUEST['AuthState'];
-$state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_core_Auth_UserPassBase::STAGEID);
+$state = \SimpleSAML\Auth\State::loadState($authStateId, sspmod_core_Auth_UserPassBase::STAGEID);
 
-$source = SimpleSAML_Auth_Source::getById($state[sspmod_core_Auth_UserPassBase::AUTHID]);
+$source = \SimpleSAML\Auth\Source::getById($state[sspmod_core_Auth_UserPassBase::AUTHID]);
 if ($source === NULL) {
 	throw new Exception('Could not find authentication source with id ' . $state[sspmod_core_Auth_UserPassBase::AUTHID]);
 }
@@ -59,7 +59,7 @@ if (!empty($_REQUEST['username']) || !empty($password)) {
     if ($source->isRememberMeEnabled()) {
         if (array_key_exists('remember_me', $_REQUEST) && $_REQUEST['remember_me'] === 'Yes') {
             $state['RememberMe'] = TRUE;
-            $authStateId = SimpleSAML_Auth_State::saveState($state, sspmod_core_Auth_UserPassBase::STAGEID);
+            $authStateId = \SimpleSAML\Auth\State::saveState($state, sspmod_core_Auth_UserPassBase::STAGEID);
         }
     }
 
diff --git a/modules/core/www/loginuserpassorg.php b/modules/core/www/loginuserpassorg.php
index 172e61611..037ce592c 100644
--- a/modules/core/www/loginuserpassorg.php
+++ b/modules/core/www/loginuserpassorg.php
@@ -14,9 +14,9 @@ if (!array_key_exists('AuthState', $_REQUEST)) {
 	throw new \SimpleSAML\Error\BadRequest('Missing AuthState parameter.');
 }
 $authStateId = $_REQUEST['AuthState'];
-$state = \SimpleSAML_Auth_State::loadState($authStateId, sspmod_core_Auth_UserPassOrgBase::STAGEID);
+$state = \SimpleSAML\Auth\State::loadState($authStateId, sspmod_core_Auth_UserPassOrgBase::STAGEID);
 
-$source = \SimpleSAML_Auth_Source::getById($state[sspmod_core_Auth_UserPassOrgBase::AUTHID]);
+$source = \SimpleSAML\Auth\Source::getById($state[sspmod_core_Auth_UserPassOrgBase::AUTHID]);
 if ($source === NULL) {
 	throw new Exception('Could not find authentication source with id ' . $state[sspmod_core_Auth_UserPassOrgBase::AUTHID]);
 }
diff --git a/modules/core/www/short_sso_interval.php b/modules/core/www/short_sso_interval.php
index 7c44447e8..7618d9c97 100644
--- a/modules/core/www/short_sso_interval.php
+++ b/modules/core/www/short_sso_interval.php
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Show a warning to an user about the SP requesting SSO a short time after
  * doing it previously.
@@ -10,12 +11,12 @@ if (!array_key_exists('StateId', $_REQUEST)) {
 	throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = \SimpleSAML_Auth_State::loadState($id, 'core:short_sso_interval');
+$state = \SimpleSAML\Auth\State::loadState($id, 'core:short_sso_interval');
 $session = \SimpleSAML\Session::getSessionFromRequest();
 
 if (array_key_exists('continue', $_REQUEST)) {
 	// The user has pressed the continue/retry-button
-	\SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+	\SimpleSAML\Auth\ProcessingChain::resumeProcessing($state);
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
diff --git a/modules/exampleauth/lib/Auth/Process/RedirectTest.php b/modules/exampleauth/lib/Auth/Process/RedirectTest.php
index 7e3e93ee0..fb81a8971 100644
--- a/modules/exampleauth/lib/Auth/Process/RedirectTest.php
+++ b/modules/exampleauth/lib/Auth/Process/RedirectTest.php
@@ -4,9 +4,9 @@
  * A simple processing filter for testing that redirection works as it should.
  *
  */
-class sspmod_exampleauth_Auth_Process_RedirectTest extends SimpleSAML_Auth_ProcessingFilter {
-
 
+class sspmod_exampleauth_Auth_Process_RedirectTest extends \SimpleSAML\Auth\ProcessingFilter
+{
 	/**
 	 * Initialize processing of the redirect test.
 	 *
@@ -20,9 +20,8 @@ class sspmod_exampleauth_Auth_Process_RedirectTest extends SimpleSAML_Auth_Proce
 		$state['Attributes']['RedirectTest1'] = array('OK');
 
 		// Save state and redirect
-		$id = SimpleSAML_Auth_State::saveState($state, 'exampleauth:redirectfilter-test');
-		$url = SimpleSAML\Module::getModuleURL('exampleauth/redirecttest.php');
+		$id = \SimpleSAML\Auth\State::saveState($state, 'exampleauth:redirectfilter-test');
+		$url = \SimpleSAML\Module::getModuleURL('exampleauth/redirecttest.php');
 		\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
 	}
-
 }
diff --git a/modules/exampleauth/lib/Auth/Source/External.php b/modules/exampleauth/lib/Auth/Source/External.php
index f4bec9cc3..2ab694298 100644
--- a/modules/exampleauth/lib/Auth/Source/External.php
+++ b/modules/exampleauth/lib/Auth/Source/External.php
@@ -20,7 +20,13 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_exampleauth_Auth_Source_External extends SimpleSAML_Auth_Source {
+
+class sspmod_exampleauth_Auth_Source_External extends \SimpleSAML\Auth\Source
+{
+        /**
+         * The key of the AuthId field in the state.
+         */
+        const AUTHID = 'sspmod_exampleauth_Auth_Source_External.AuthId';
 
 	/**
 	 * Constructor for this authentication source.
@@ -113,7 +119,7 @@ class sspmod_exampleauth_Auth_Source_External extends SimpleSAML_Auth_Source {
 		 * First we add the identifier of this authentication source
 		 * to the state array, so that we know where to resume.
 		 */
-		$state['exampleauth:AuthID'] = $this->authId;
+		$state['exampleauth:AuthID'] = self::AUTHID;
 
 
 		/*
@@ -129,14 +135,14 @@ class sspmod_exampleauth_Auth_Source_External extends SimpleSAML_Auth_Source {
 		 * and restores it in another location, and thus bypasses steps in
 		 * the authentication process.
 		 */
-		$stateId = SimpleSAML_Auth_State::saveState($state, 'exampleauth:External');
+		$stateId = \SimpleSAML\Auth\State::saveState($state, 'exampleauth:External');
 
 		/*
 		 * Now we generate a URL the user should return to after authentication.
 		 * We assume that whatever authentication page we send the user to has an
 		 * option to return the user to a specific page afterwards.
 		 */
-		$returnTo = SimpleSAML\Module::getModuleURL('exampleauth/resume.php', array(
+		$returnTo = \SimpleSAML\Module::getModuleURL('exampleauth/resume.php', array(
 			'State' => $stateId,
 		));
 
@@ -188,13 +194,13 @@ class sspmod_exampleauth_Auth_Source_External extends SimpleSAML_Auth_Source {
 		 * Once again, note the second parameter to the loadState function. This must
 		 * match the string we used in the saveState-call above.
 		 */
-		$state = SimpleSAML_Auth_State::loadState($_REQUEST['State'], 'exampleauth:External');
+		$state = \SimpleSAML\Auth\State::loadState($_REQUEST['State'], 'exampleauth:External');
 
 		/*
 		 * Now we have the $state-array, and can use it to locate the authentication
 		 * source.
 		 */
-		$source = SimpleSAML_Auth_Source::getById($state['exampleauth:AuthID']);
+		$source = \SimpleSAML\Auth\Source::getById($state['exampleauth:AuthID']);
 		if ($source === NULL) {
 			/*
 			 * The only way this should fail is if we remove or rename the authentication source
@@ -235,7 +241,7 @@ class sspmod_exampleauth_Auth_Source_External extends SimpleSAML_Auth_Source {
 		 */
 
 		$state['Attributes'] = $attributes;
-		SimpleSAML_Auth_Source::completeAuth($state);
+		\SimpleSAML\Auth\Source::completeAuth($state);
 
 		/*
 		 * The completeAuth-function never returns, so we never get this far.
diff --git a/modules/exampleauth/lib/Auth/Source/Static.php b/modules/exampleauth/lib/Auth/Source/Static.php
index 8c5eba057..33d63eb1a 100644
--- a/modules/exampleauth/lib/Auth/Source/Static.php
+++ b/modules/exampleauth/lib/Auth/Source/Static.php
@@ -9,9 +9,9 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_exampleauth_Auth_Source_Static extends SimpleSAML_Auth_Source {
-
 
+class sspmod_exampleauth_Auth_Source_Static extends \SimpleSAML\Auth\Source
+{
 	/**
 	 * The attributes we return.
 	 */
diff --git a/modules/exampleauth/lib/Auth/Source/UserPass.php b/modules/exampleauth/lib/Auth/Source/UserPass.php
index 96d2abe2c..8be6d76d7 100644
--- a/modules/exampleauth/lib/Auth/Source/UserPass.php
+++ b/modules/exampleauth/lib/Auth/Source/UserPass.php
@@ -9,9 +9,9 @@
  * @author Olav Morken, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_exampleauth_Auth_Source_UserPass extends sspmod_core_Auth_UserPassBase {
-
 
+class sspmod_exampleauth_Auth_Source_UserPass extends sspmod_core_Auth_UserPassBase
+{
 	/**
 	 * Our users, stored in an associative array. The key of the array is "<username>:<password>",
 	 * while the value of each element is a new array with the attributes for each user.
diff --git a/modules/exampleauth/www/authpage.php b/modules/exampleauth/www/authpage.php
index 73fcb131e..5f176ec4f 100644
--- a/modules/exampleauth/www/authpage.php
+++ b/modules/exampleauth/www/authpage.php
@@ -29,7 +29,7 @@ $returnTo = \SimpleSAML\Utils\HTTP::checkURLAllowed($_REQUEST['ReturnTo']);
 if (!preg_match('@State=(.*)@', $returnTo, $matches)) {
 	die('Invalid ReturnTo URL for this example.');
 }
-SimpleSAML_Auth_State::loadState(urldecode($matches[1]), 'exampleauth:External');
+\SimpleSAML\Auth\State::loadState(urldecode($matches[1]), 'exampleauth:External');
 
 /*
  * The loadState-function will not return if the second parameter does not
diff --git a/modules/exampleauth/www/redirecttest.php b/modules/exampleauth/www/redirecttest.php
index d56fa26a6..103d262af 100644
--- a/modules/exampleauth/www/redirecttest.php
+++ b/modules/exampleauth/www/redirecttest.php
@@ -10,8 +10,8 @@
 if (!array_key_exists('StateId', $_REQUEST)) {
     throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['StateId'], 'exampleauth:redirectfilter-test');
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['StateId'], 'exampleauth:redirectfilter-test');
 
 $state['Attributes']['RedirectTest2'] = array('OK');
 
-SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+\SimpleSAML\Auth\ProcessingChain::resumeProcessing($state);
diff --git a/modules/exampleauth/www/resume.php b/modules/exampleauth/www/resume.php
index 08d66dd3f..e7ff5f8a6 100644
--- a/modules/exampleauth/www/resume.php
+++ b/modules/exampleauth/www/resume.php
@@ -8,4 +8,5 @@
  *
  * @package SimpleSAMLphp
  */
+
 sspmod_exampleauth_Auth_Source_External::resume();
diff --git a/modules/expirycheck/lib/Auth/Process/ExpiryDate.php b/modules/expirycheck/lib/Auth/Process/ExpiryDate.php
index c315169fa..858047bbc 100644
--- a/modules/expirycheck/lib/Auth/Process/ExpiryDate.php
+++ b/modules/expirycheck/lib/Auth/Process/ExpiryDate.php
@@ -20,7 +20,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_expirycheck_Auth_Process_ExpiryDate extends SimpleSAML_Auth_ProcessingFilter {
+class sspmod_expirycheck_Auth_Process_ExpiryDate extends \SimpleSAML\Auth\ProcessingFilter {
 
 	private $warndaysbefore = 0;
 	private $netid_attr = NULL;
@@ -132,7 +132,7 @@ class sspmod_expirycheck_Auth_Process_ExpiryDate extends SimpleSAML_Auth_Process
 			// Save state and redirect
 			$state['expireOnDate'] = date($this->date_format, $expireOnDate);
 			$state['netId'] = $netId;
-			$id = SimpleSAML_Auth_State::saveState($state, 'expirywarning:about2expire');
+			$id = \SimpleSAML\Auth\State::saveState($state, 'expirywarning:about2expire');
 			$url = SimpleSAML\Module::getModuleURL('expirycheck/about2expire.php');
 			\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
 		}
@@ -144,7 +144,7 @@ class sspmod_expirycheck_Auth_Process_ExpiryDate extends SimpleSAML_Auth_Process
 			/* Save state and redirect. */
 			$state['expireOnDate'] = date($this->date_format, $expireOnDate);
 			$state['netId'] = $netId;
-			$id = SimpleSAML_Auth_State::saveState($state, 'expirywarning:expired');
+			$id = \SimpleSAML\Auth\State::saveState($state, 'expirywarning:expired');
 			$url = SimpleSAML\Module::getModuleURL('expirycheck/expired.php');
 			\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
 
diff --git a/modules/expirycheck/www/about2expire.php b/modules/expirycheck/www/about2expire.php
index 99c134614..56e2fdc13 100644
--- a/modules/expirycheck/www/about2expire.php
+++ b/modules/expirycheck/www/about2expire.php
@@ -12,11 +12,11 @@ if (!array_key_exists('StateId', $_REQUEST)) {
     throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = \SimpleSAML_Auth_State::loadState($id, 'expirywarning:about2expire');
+$state = \SimpleSAML\Auth\State::loadState($id, 'expirywarning:about2expire');
 
 if (array_key_exists('yes', $_REQUEST)) {
     // The user has pressed the yes-button
-    \SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+    \SimpleSAML\Auth\ProcessingChain::resumeProcessing($state);
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
diff --git a/modules/expirycheck/www/expired.php b/modules/expirycheck/www/expired.php
index 27470b7f0..2d3d3b3e8 100644
--- a/modules/expirycheck/www/expired.php
+++ b/modules/expirycheck/www/expired.php
@@ -11,7 +11,7 @@
 if (!array_key_exists('StateId', $_REQUEST)) {
     throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
-$state = \SimpleSAML_Auth_State::loadState($_REQUEST['StateId'], 'expirywarning:expired');
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['StateId'], 'expirywarning:expired');
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 
diff --git a/modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php b/modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php
index e788d2689..eeb39071a 100644
--- a/modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php
+++ b/modules/ldap/lib/Auth/Process/AttributeAddFromLDAP.php
@@ -150,7 +150,7 @@ class sspmod_ldap_Auth_Process_AttributeAddFromLDAP extends sspmod_ldap_Auth_Pro
             $arrSearch[] = '%'.$attr.'%';
 
             if (strlen($val[0]) > 0) {
-                $arrReplace[] = SimpleSAML_Auth_LDAP::escape_filter_value($val[0]);
+                $arrReplace[] = \SimpleSAML\Auth\LDAP::escape_filter_value($val[0]);
             } else {
                 $arrReplace[] = '';
             }
diff --git a/modules/ldap/lib/Auth/Process/BaseFilter.php b/modules/ldap/lib/Auth/Process/BaseFilter.php
index c0834ea0a..c4fb9120e 100644
--- a/modules/ldap/lib/Auth/Process/BaseFilter.php
+++ b/modules/ldap/lib/Auth/Process/BaseFilter.php
@@ -13,7 +13,7 @@
  * @package SimpleSAMLphp
  */
 
-abstract class sspmod_ldap_Auth_Process_BaseFilter extends SimpleSAML_Auth_ProcessingFilter
+abstract class sspmod_ldap_Auth_Process_BaseFilter extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * List of attribute "alias's" linked to the real attribute
@@ -48,7 +48,7 @@ abstract class sspmod_ldap_Auth_Process_BaseFilter extends SimpleSAML_Auth_Proce
      * Instance, object of the ldap connection. Stored here to
      * be access later during processing.
      *
-     * @var sspmod_ldap_LdapConnection
+     * @var \SimpleSAML\Auth\Ldap
      */
     private $ldap;
 
@@ -254,7 +254,7 @@ abstract class sspmod_ldap_Auth_Process_BaseFilter extends SimpleSAML_Auth_Proce
      * rather than setting in the constructor to avoid unnecessarily
      * connecting to LDAP when it might not be needed.
      *
-     * @return sspmod_ldap_LdapConnection
+     * @return \SimpleSAML\Auth\Ldap
      */
     protected function getLdap()
     {
@@ -287,7 +287,7 @@ abstract class sspmod_ldap_Auth_Process_BaseFilter extends SimpleSAML_Auth_Proce
         );
 
         // Connect to the LDAP server to be queried during processing
-        $this->ldap = new SimpleSAML_Auth_LDAP($hostname, $enable_tls, $debug, $timeout, $port, $referrals);
+        $this->ldap = new \SimpleSAML\Auth\LDAP($hostname, $enable_tls, $debug, $timeout, $port, $referrals);
         $this->ldap->bind($username, $password);
 
         // All done
diff --git a/modules/ldap/lib/ConfigHelper.php b/modules/ldap/lib/ConfigHelper.php
index 2d199a868..e1f0fb64b 100644
--- a/modules/ldap/lib/ConfigHelper.php
+++ b/modules/ldap/lib/ConfigHelper.php
@@ -189,7 +189,7 @@ class sspmod_ldap_ConfigHelper
             throw new \SimpleSAML\Error\Error('WRONGUSERPASS');
         }
 
-        $ldap = new SimpleSAML_Auth_LDAP($this->hostname, $this->enableTLS, $this->debug, $this->timeout, $this->port, $this->referrals);
+        $ldap = new \SimpleSAML\Auth\LDAP($this->hostname, $this->enableTLS, $this->debug, $this->timeout, $this->port, $this->referrals);
 
         if (!$this->searchEnable) {
             $ldapusername = addcslashes($username, ',+"\\<>;*');
@@ -255,7 +255,7 @@ class sspmod_ldap_ConfigHelper
      */
     public function searchfordn($attribute, $value, $allowZeroHits)
     {
-        $ldap = new SimpleSAML_Auth_LDAP($this->hostname,
+        $ldap = new \SimpleSAML\Auth\LDAP($this->hostname,
             $this->enableTLS,
             $this->debug,
             $this->timeout,
@@ -282,7 +282,7 @@ class sspmod_ldap_ConfigHelper
             $attributes = $this->attributes;
         }
 
-        $ldap = new SimpleSAML_Auth_LDAP($this->hostname,
+        $ldap = new \SimpleSAML\Auth\LDAP($this->hostname,
             $this->enableTLS,
             $this->debug,
             $this->timeout,
diff --git a/modules/multiauth/lib/Auth/Source/MultiAuth.php b/modules/multiauth/lib/Auth/Source/MultiAuth.php
index f026f8c5e..1a46678d3 100644
--- a/modules/multiauth/lib/Auth/Source/MultiAuth.php
+++ b/modules/multiauth/lib/Auth/Source/MultiAuth.php
@@ -8,7 +8,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source
+class sspmod_multiauth_Auth_Source_MultiAuth extends \SimpleSAML\Auth\Source
 {
 	/**
 	 * The key of the AuthId field in the state.
@@ -108,7 +108,7 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source
 		$state[self::SOURCESID] = $this->sources;
 
 		/* Save the $state array, so that we can restore if after a redirect */
-		$id = SimpleSAML_Auth_State::saveState($state, self::STAGEID);
+		$id = \SimpleSAML\Auth\State::saveState($state, self::STAGEID);
 
 		/* Redirect to the select source page. We include the identifier of the
 		saved state array as a parameter to the login form */
@@ -142,7 +142,7 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source
 		assert(is_string($authId));
 		assert(is_array($state));
 
-		$as = SimpleSAML_Auth_Source::getById($authId);
+		$as = \SimpleSAML\Auth\Source::getById($authId);
 		$valid_sources = array_map(
 			function($src) {
 				return $src['source'];
@@ -160,12 +160,12 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source
 		try {
 			$as->authenticate($state);
 		} catch (\SimpleSAML\Error\Exception $e) {
-			SimpleSAML_Auth_State::throwException($state, $e);
-		} catch (Exception $e) {
+			\SimpleSAML\Auth\State::throwException($state, $e);
+		} catch (\Exception $e) {
 			$e = new \SimpleSAML\Error\UnserializableException($e);
-			SimpleSAML_Auth_State::throwException($state, $e);
+			\SimpleSAML\Auth\State::throwException($state, $e);
 		}
-		SimpleSAML_Auth_Source::completeAuth($state);
+		\SimpleSAML\Auth\Source::completeAuth($state);
 	}
 
 	/**
@@ -183,9 +183,9 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source
 		$session = \SimpleSAML\Session::getSessionFromRequest();
 		$authId = $session->getData(self::SESSION_SOURCE, $this->authId);
 
-		$source = SimpleSAML_Auth_Source::getById($authId);
+		$source = \SimpleSAML\Auth\Source::getById($authId);
 		if ($source === NULL) {
-			throw new Exception('Invalid authentication source during logout: ' . $source);
+			throw new \Exception('Invalid authentication source during logout: ' . $source);
 		}
 		/* Then, do the logout on it */
 		$source->logout($state);
diff --git a/modules/multiauth/www/selectsource.php b/modules/multiauth/www/selectsource.php
index 00ccff26b..d04e556ea 100644
--- a/modules/multiauth/www/selectsource.php
+++ b/modules/multiauth/www/selectsource.php
@@ -15,11 +15,11 @@ if (!array_key_exists('AuthState', $_REQUEST)) {
 	throw new \SimpleSAML\Error\BadRequest('Missing AuthState parameter.');
 }
 $authStateId = $_REQUEST['AuthState'];
-$state = \SimpleSAML_Auth_State::loadState($authStateId, sspmod_multiauth_Auth_Source_MultiAuth::STAGEID);
+$state = \SimpleSAML\Auth\State::loadState($authStateId, sspmod_multiauth_Auth_Source_MultiAuth::STAGEID);
 
-if (array_key_exists("SimpleSAML_Auth_Source.id", $state)) {
-	$authId = $state["SimpleSAML_Auth_Source.id"];
-	$as = \SimpleSAML_Auth_Source::getById($authId);
+if (array_key_exists("\SimpleSAML\Auth\Source.id", $state)) {
+	$authId = $state["\SimpleSAML\Auth\Source.id"];
+	$as = \SimpleSAML\Auth\Source::getById($authId);
 } else {
 	$as = NULL;
 }
diff --git a/modules/negotiate/docs/negotiate.md b/modules/negotiate/docs/negotiate.md
index a57044de9..968d56eaf 100644
--- a/modules/negotiate/docs/negotiate.md
+++ b/modules/negotiate/docs/negotiate.md
@@ -196,23 +196,23 @@ One can add this bit of code to the template in the fallback AuthN
 module:
 
 // This should be placed in your www script
-$nego_session = FALSE;
-$nego_perm = FALSE;
-$nego_retry = NULL;
+$nego_session = false;
+$nego_perm = false;
+$nego_retry = null;
 if (array_key_exists('negotiate:authId', $state)) {
-    $nego = SimpleSAML_Auth_Source::getById($state['negotiate:authId']);
+    $nego = \SimpleSAML\Auth\Source::getById($state['negotiate:authId']);
     $mask = $nego->checkMask();
     $disabled = $nego->spDisabledInMetadata($spMetadata);
     $session_disabled = $session->getData('negotiate:disable', 'session');
     if ($mask and !$disabled) {
         if(array_key_exists('NEGOTIATE_AUTOLOGIN_DISABLE_PERMANENT', $_COOKIE) &&
            $_COOKIE['NEGOTIATE_AUTOLOGIN_DISABLE_PERMANENT'] == 'True') {
-            $nego_perm = TRUE;
+            $nego_perm = true;
         } elseif ($session_disabled) {
-            $retryState = SimpleSAML_Auth_State::cloneState($state);
-            unset($retryState[SimpleSAML_Auth_State::ID]);
-            $nego_retry = SimpleSAML_Auth_State::saveState($retryState, 'sspmod_negotiate_Auth_Source_Negotiate.StageId');
-            $nego_session = TRUE;
+            $retryState = \SimpleSAML\Auth\State::cloneState($state);
+            unset($retryState[\SimpleSAML\Auth\State::ID]);
+            $nego_retry = \SimpleSAML\Auth\State::saveState($retryState, 'sspmod_negotiate_Auth_Source_Negotiate.StageId');
+            $nego_session = true;
         }
     }
 }
diff --git a/modules/negotiate/lib/Auth/Source/Negotiate.php b/modules/negotiate/lib/Auth/Source/Negotiate.php
index 37cdfc614..d144e2855 100644
--- a/modules/negotiate/lib/Auth/Source/Negotiate.php
+++ b/modules/negotiate/lib/Auth/Source/Negotiate.php
@@ -7,7 +7,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_negotiate_Auth_Source_Negotiate extends SimpleSAML_Auth_Source
+class sspmod_negotiate_Auth_Source_Negotiate extends \SimpleSAML\Auth\Source
 {
     // Constants used in the module
     const STAGEID = 'sspmod_negotiate_Auth_Source_Negotiate.StageId';
@@ -118,7 +118,7 @@ class sspmod_negotiate_Auth_Source_Negotiate extends SimpleSAML_Auth_Source
         SimpleSAML\Logger::debug('Negotiate - authenticate(): looking for Negotiate');
         if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
             SimpleSAML\Logger::debug('Negotiate - authenticate(): Negotiate found');
-            $this->ldap = new SimpleSAML_Auth_LDAP(
+            $this->ldap = new \SimpleSAML\Auth\LDAP(
                 $this->hostname,
                 $this->enableTLS,
                 $this->debugLDAP,
@@ -157,7 +157,7 @@ class sspmod_negotiate_Auth_Source_Negotiate extends SimpleSAML_Auth_Source
                         'negotiate:backend' => null,
                     );
                     SimpleSAML\Logger::info('Negotiate - authenticate(): '.$user.' authorized.');
-                    SimpleSAML_Auth_Source::completeAuth($state);
+                    \SimpleSAML\Auth\Source::completeAuth($state);
                     // Never reached.
                     assert(false);
                 }
@@ -170,7 +170,7 @@ class sspmod_negotiate_Auth_Source_Negotiate extends SimpleSAML_Auth_Source
             SimpleSAML\Logger::debug('Negotiate - authenticate(): Sending Negotiate.');
             // Save the $state array, so that we can restore if after a redirect
             SimpleSAML\Logger::debug('Negotiate - fallback: '.$state['LogoutState']['negotiate:backend']);
-            $id = SimpleSAML_Auth_State::saveState($state, self::STAGEID);
+            $id = \SimpleSAML\Auth\State::saveState($state, self::STAGEID);
             $params = array('AuthState' => $id);
 
             $this->sendNegotiate($params);
@@ -271,15 +271,15 @@ EOF;
         if ($authId === null) {
             throw new \SimpleSAML\Error\Error(array(500, "Unable to determine auth source."));
         }
-        $source = \SimpleSAML_Auth_Source::getById($authId);
+        $source = \SimpleSAML\Auth\Source::getById($authId);
 
         try {
             $source->authenticate($state);
         } catch (\SimpleSAML\Error\Exception $e) {
-            \SimpleSAML_Auth_State::throwException($state, $e);
+            \SimpleSAML\Auth\State::throwException($state, $e);
         } catch (\Exception $e) {
             $e = new \SimpleSAML\Error\UnserializableException($e);
-            SimpleSAML_Auth_State::throwException($state, $e);
+            \SimpleSAML\Auth\State::throwException($state, $e);
         }
         // fallBack never returns after loginCompleted()
         SimpleSAML\Logger::debug('Negotiate: backend returned');
@@ -357,7 +357,7 @@ EOF;
             $session->setData('negotiate:disable', 'session', true, 24 * 60 * 60);
             parent::logout($state);
         } else {
-            $source = SimpleSAML_Auth_Source::getById($authId);
+            $source = \SimpleSAML\Auth\Source::getById($authId);
             $source->logout($state);
         }
     }
diff --git a/modules/negotiate/www/backend.php b/modules/negotiate/www/backend.php
index 5fa2619a4..7c97aa4b9 100644
--- a/modules/negotiate/www/backend.php
+++ b/modules/negotiate/www/backend.php
@@ -8,8 +8,8 @@
  * @package SimpleSAMLphp
  */
 
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], sspmod_negotiate_Auth_Source_Negotiate::STAGEID);
-SimpleSAML\Logger::debug('backend - fallback: '.$state['LogoutState']['negotiate:backend']);
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['AuthState'], sspmod_negotiate_Auth_Source_Negotiate::STAGEID);
+\SimpleSAML\Logger::debug('backend - fallback: '.$state['LogoutState']['negotiate:backend']);
 
 sspmod_negotiate_Auth_Source_Negotiate::fallBack($state);
 
diff --git a/modules/negotiate/www/retry.php b/modules/negotiate/www/retry.php
index ee792df4d..046963c59 100644
--- a/modules/negotiate/www/retry.php
+++ b/modules/negotiate/www/retry.php
@@ -8,14 +8,14 @@
  *
  */
 
-$state = \SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], sspmod_negotiate_Auth_Source_Negotiate::STAGEID);
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['AuthState'], sspmod_negotiate_Auth_Source_Negotiate::STAGEID);
 
 $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 $idpid = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted', 'metaindex');
 $idpmeta = $metadata->getMetaData($idpid, 'saml20-idp-hosted');
 
 if (isset($idpmeta['auth'])) {
-    $source = \SimpleSAML_Auth_Source::getById($idpmeta['auth']);
+    $source = \SimpleSAML\Auth\Source::getById($idpmeta['auth']);
     if ($source === null) {
         throw new \SimpleSAML\Error\BadRequest('Invalid AuthId "' . $idpmeta['auth'] . '" - not found.');
     }
diff --git a/modules/oauth/www/registry.edit.php b/modules/oauth/www/registry.edit.php
index 1e750d2ed..3331667cb 100644
--- a/modules/oauth/www/registry.edit.php
+++ b/modules/oauth/www/registry.edit.php
@@ -17,7 +17,7 @@ if ($session->isValid($authsource)) {
 		throw new Exception('User ID is missing');
 	$userid = $attributes[$useridattr][0];
 } else {
-	$as = \SimpleSAML_Auth_Source::getById($authsource);
+	$as = \SimpleSAML\Auth\Source::getById($authsource);
 	$as->initLogin(\SimpleSAML\Utils\HTTP::getSelfURL());
 }
 
diff --git a/modules/oauth/www/registry.php b/modules/oauth/www/registry.php
index c13ce18a4..54ff396e1 100644
--- a/modules/oauth/www/registry.php
+++ b/modules/oauth/www/registry.php
@@ -17,7 +17,7 @@ if ($session->isValid($authsource)) {
 		throw new Exception('User ID is missing');
 	$userid = $attributes[$useridattr][0];
 } else {
-	$as = \SimpleSAML_Auth_Source::getById($authsource);
+	$as = \SimpleSAML\Auth\Source::getById($authsource);
 	$as->initLogin(\SimpleSAML\Utils\HTTP::getSelfURL());
 }
 
diff --git a/modules/preprodwarning/lib/Auth/Process/Warning.php b/modules/preprodwarning/lib/Auth/Process/Warning.php
index 9ece3fa4b..ffeb13320 100644
--- a/modules/preprodwarning/lib/Auth/Process/Warning.php
+++ b/modules/preprodwarning/lib/Auth/Process/Warning.php
@@ -5,10 +5,9 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_preprodwarning_Auth_Process_Warning extends SimpleSAML_Auth_ProcessingFilter {
-
-
 
+class sspmod_preprodwarning_Auth_Process_Warning extends \SimpleSAML\Auth\ProcessingFilter
+{
 	/**
 	 * Process a authentication response.
 	 *
@@ -26,11 +25,8 @@ class sspmod_preprodwarning_Auth_Process_Warning extends SimpleSAML_Auth_Process
 		}
 
 		// Save state and redirect.
-		$id = SimpleSAML_Auth_State::saveState($state, 'warning:request');
-		$url = SimpleSAML\Module::getModuleURL('preprodwarning/showwarning.php');
+		$id = \SimpleSAML\Auth\State::saveState($state, 'warning:request');
+		$url = \SimpleSAML\Module::getModuleURL('preprodwarning/showwarning.php');
 		\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
 	}
-	
-
-
 }
diff --git a/modules/preprodwarning/www/showwarning.php b/modules/preprodwarning/www/showwarning.php
index 47235c1d8..41eff2055 100644
--- a/modules/preprodwarning/www/showwarning.php
+++ b/modules/preprodwarning/www/showwarning.php
@@ -13,11 +13,11 @@ if (!array_key_exists('StateId', $_REQUEST)) {
     throw new \SimpleSAML\Error\BadRequest('Missing required StateId query parameter.');
 }
 $id = $_REQUEST['StateId'];
-$state = \SimpleSAML_Auth_State::loadState($id, 'warning:request');
+$state = \SimpleSAML\Auth\State::loadState($id, 'warning:request');
 
 if (array_key_exists('yes', $_REQUEST)) {
     // The user has pressed the yes-button
-    \SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+    \SimpleSAML\Auth\ProcessingChain::resumeProcessing($state);
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
diff --git a/modules/saml/hooks/hook_metadata_hosted.php b/modules/saml/hooks/hook_metadata_hosted.php
index f94d19ff7..d27f5246d 100644
--- a/modules/saml/hooks/hook_metadata_hosted.php
+++ b/modules/saml/hooks/hook_metadata_hosted.php
@@ -10,7 +10,7 @@ function saml_hook_metadata_hosted(&$metadataHosted)
 {
     assert(is_array($metadataHosted));
 
-    $sources = SimpleSAML_Auth_Source::getSourcesOfType('saml:SP');
+    $sources = \SimpleSAML\Auth\Source::getSourcesOfType('saml:SP');
 
     foreach ($sources as $source) {
         $metadata = $source->getMetadata();
diff --git a/modules/saml/lib/Auth/Process/AuthnContextClassRef.php b/modules/saml/lib/Auth/Process/AuthnContextClassRef.php
index 371004b6a..afb701cb4 100644
--- a/modules/saml/lib/Auth/Process/AuthnContextClassRef.php
+++ b/modules/saml/lib/Auth/Process/AuthnContextClassRef.php
@@ -6,7 +6,7 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_saml_Auth_Process_AuthnContextClassRef extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_saml_Auth_Process_AuthnContextClassRef extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * The URI we should set as the AuthnContextClassRef in the login response.
diff --git a/modules/saml/lib/Auth/Process/ExpectedAuthnContextClassRef.php b/modules/saml/lib/Auth/Process/ExpectedAuthnContextClassRef.php
index be3ae00aa..1569c6d3d 100644
--- a/modules/saml/lib/Auth/Process/ExpectedAuthnContextClassRef.php
+++ b/modules/saml/lib/Auth/Process/ExpectedAuthnContextClassRef.php
@@ -16,7 +16,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_saml_Auth_Process_ExpectedAuthnContextClassRef extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_saml_Auth_Process_ExpectedAuthnContextClassRef extends \SimpleSAML\Auth\ProcessingFilter
 {
 
     /**
@@ -89,13 +89,13 @@ class sspmod_saml_Auth_Process_ExpectedAuthnContextClassRef extends SimpleSAML_A
      */
     protected function unauthorized(&$request)
     {
-        SimpleSAML\Logger::error(
+        \SimpleSAML\Logger::error(
             'ExpectedAuthnContextClassRef: Invalid authentication context: '.$this->AuthnContextClassRef.
             '. Accepted values are: '.var_export($this->accepted, true)
         );
 
-        $id = SimpleSAML_Auth_State::saveState($request, 'saml:ExpectedAuthnContextClassRef:unauthorized');
-        $url = SimpleSAML\Module::getModuleURL(
+        $id = \SimpleSAML\Auth\State::saveState($request, 'saml:ExpectedAuthnContextClassRef:unauthorized');
+        $url = \SimpleSAML\Module::getModuleURL(
             'saml/sp/wrong_authncontextclassref.php'
         );
         \SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
diff --git a/modules/saml/lib/Auth/Process/FilterScopes.php b/modules/saml/lib/Auth/Process/FilterScopes.php
index 15aa9fbb2..7b972e625 100644
--- a/modules/saml/lib/Auth/Process/FilterScopes.php
+++ b/modules/saml/lib/Auth/Process/FilterScopes.php
@@ -11,7 +11,7 @@ use SimpleSAML\Logger;
  * @author Jaime Pérez Crespo, UNINETT AS <jaime.perez@uninett.no>
  * @package SimpleSAMLphp
  */
-class FilterScopes extends \SimpleSAML_Auth_ProcessingFilter
+class FilterScopes extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * Stores any pre-configured scoped attributes which come from the filter configuration.
diff --git a/modules/saml/lib/Auth/Process/NameIDAttribute.php b/modules/saml/lib/Auth/Process/NameIDAttribute.php
index 865456dcd..f141bd792 100644
--- a/modules/saml/lib/Auth/Process/NameIDAttribute.php
+++ b/modules/saml/lib/Auth/Process/NameIDAttribute.php
@@ -6,7 +6,7 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_saml_Auth_Process_NameIDAttribute extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_saml_Auth_Process_NameIDAttribute extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * The attribute we should save the NameID in.
diff --git a/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php b/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php
index abc0590ae..84a717fdc 100644
--- a/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php
+++ b/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php
@@ -6,7 +6,7 @@
  * @package SimpleSAMLphp
  */
 
-class sspmod_saml_Auth_Process_PersistentNameID2TargetedID extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_saml_Auth_Process_PersistentNameID2TargetedID extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * The attribute we should save the NameID in.
diff --git a/modules/saml/lib/Auth/Source/SP.php b/modules/saml/lib/Auth/Source/SP.php
index b1a59d31d..7aa29e2e3 100644
--- a/modules/saml/lib/Auth/Source/SP.php
+++ b/modules/saml/lib/Auth/Source/SP.php
@@ -1,6 +1,9 @@
 <?php
 
-class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
+use SimpleSAML\Auth\Source;
+use SimpleSAML\Auth\State;
+
+class sspmod_saml_Auth_Source_SP extends Source
 {
     /**
      * The entity ID of this SP.
@@ -147,7 +150,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
         $ar = new \SimpleSAML\XML\Shib13\AuthnRequest();
         $ar->setIssuer($this->entityId);
 
-        $id = SimpleSAML_Auth_State::saveState($state, 'saml:sp:sso');
+        $id = State::saveState($state, 'saml:sp:sso');
         $ar->setRelayState($id);
 
         $useArtifact = $idpMetadata->getBoolean('saml1.useartifact', null);
@@ -177,7 +180,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
     private function startSSO2(\SimpleSAML\Configuration $idpMetadata, array $state)
     {
         if (isset($state['saml:ProxyCount']) && $state['saml:ProxyCount'] < 0) {
-            SimpleSAML_Auth_State::throwException(
+            State::throwException(
                 $state,
                 new \SimpleSAML\Module\saml\Error\ProxyCountExceeded(\SAML2\Constants::STATUS_RESPONDER)
             );
@@ -187,8 +190,8 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
 
         $ar->setAssertionConsumerServiceURL(SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/' . $this->authId));
 
-        if (isset($state['SimpleSAML_Auth_Source.ReturnURL'])) {
-            $ar->setRelayState($state['SimpleSAML_Auth_Source.ReturnURL']);
+        if (isset($state['\SimpleSAML\Auth\Source.ReturnURL'])) {
+            $ar->setRelayState($state['\SimpleSAML\Auth\Source.ReturnURL']);
         }
 
         if (isset($state['saml:AuthnContextClassRef'])) {
@@ -270,7 +273,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
         // save IdP entity ID as part of the state
         $state['ExpectedIssuer'] = $idpMetadata->getString('entityid');
 
-        $id = SimpleSAML_Auth_State::saveState($state, 'saml:sp:sso', true);
+        $id = State::saveState($state, 'saml:sp:sso', true);
         $ar->setId($id);
 
         SimpleSAML\Logger::debug('Sending SAML 2 AuthnRequest to ' .
@@ -344,7 +347,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
      */
     private function startDisco(array $state)
     {
-        $id = SimpleSAML_Auth_State::saveState($state, 'saml:sp:sso');
+        $id = State::saveState($state, 'saml:sp:sso');
 
         $discoURL = $this->discoURL;
         if ($discoURL === null) {
@@ -535,7 +538,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
         }
 
         // save the state WITHOUT a restart URL, so that we don't try an IdP-initiated login if something goes wrong
-        $id = SimpleSAML_Auth_State::saveState($state, 'saml:proxy:invalid_idp', true);
+        $id = State::saveState($state, 'saml:proxy:invalid_idp', true);
         $url = SimpleSAML\Module::getModuleURL('saml/proxy/invalid_session.php');
         SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('AuthState' => $id));
         assert(false);
@@ -574,7 +577,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
         // Update session state
         $session = \SimpleSAML\Session::getSessionFromRequest();
         $authId = $state['saml:sp:AuthId'];
-        $session->doLogin($authId, SimpleSAML_Auth_State::getPersistentAuthData($state));
+        $session->doLogin($authId, State::getPersistentAuthData($state));
 
         // resume the login process
         call_user_func($state['ReturnCallback'], $state);
@@ -599,7 +602,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
             $state['Responder'] = $state['saml:proxy:reauthLogout:PrevResponder'];
         }
 
-        $sp = SimpleSAML_Auth_Source::getById($state['saml:sp:AuthId'], 'sspmod_saml_Auth_Source_SP');
+        $sp = Source::getById($state['saml:sp:AuthId'], 'sspmod_saml_Auth_Source_SP');
         /** @var sspmod_saml_Auth_Source_SP $authSource */
         SimpleSAML\Logger::debug('Proxy: logging in again.');
         $sp->authenticate($state);
@@ -618,7 +621,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
         assert(array_key_exists('saml:logout:NameID', $state));
         assert(array_key_exists('saml:logout:SessionIndex', $state));
 
-        $id = SimpleSAML_Auth_State::saveState($state, 'saml:slosent');
+        $id = State::saveState($state, 'saml:slosent');
 
         $idp = $state['saml:logout:IdP'];
         $nameId = $state['saml:logout:NameID'];
@@ -717,7 +720,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
             $authProcState['saml:sp:SessionIndex'] = $state['saml:sp:SessionIndex'];
         }
 
-        $pc = new SimpleSAML_Auth_ProcessingChain($idpMetadataArray, $spMetadataArray, 'sp');
+        $pc = new \SimpleSAML\Auth\ProcessingChain($idpMetadataArray, $spMetadataArray, 'sp');
         $pc->processState($authProcState);
 
         self::onProcessingCompleted($authProcState);
@@ -756,7 +759,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
         assert(is_string($redirectTo));
 
         $session = \SimpleSAML\Session::getSessionFromRequest();
-        $session->doLogin($authId, SimpleSAML_Auth_State::getPersistentAuthData($state));
+        $session->doLogin($authId, State::getPersistentAuthData($state));
 
         \SimpleSAML\Utils\HTTP::redirectUntrustedURL($redirectTo);
     }
@@ -776,7 +779,7 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
         $state = $authProcState['saml:sp:State'];
 
         $sourceId = $state['saml:sp:AuthId'];
-        $source = SimpleSAML_Auth_Source::getById($sourceId);
+        $source = Source::getById($sourceId);
         if ($source === null) {
             throw new Exception('Could not find authentication source with id ' . $sourceId);
         }
@@ -795,6 +798,6 @@ class sspmod_saml_Auth_Source_SP extends SimpleSAML_Auth_Source
             self::handleUnsolicitedAuth($sourceId, $state, $redirectTo);
         }
 
-        SimpleSAML_Auth_Source::completeAuth($state);
+        Source::completeAuth($state);
     }
 }
diff --git a/modules/saml/lib/BaseNameIDGenerator.php b/modules/saml/lib/BaseNameIDGenerator.php
index cea1c2196..d4981fcc3 100644
--- a/modules/saml/lib/BaseNameIDGenerator.php
+++ b/modules/saml/lib/BaseNameIDGenerator.php
@@ -5,7 +5,7 @@
  *
  * @package SimpleSAMLphp
  */
-abstract class sspmod_saml_BaseNameIDGenerator extends SimpleSAML_Auth_ProcessingFilter
+abstract class sspmod_saml_BaseNameIDGenerator extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * What NameQualifier should be used.
diff --git a/modules/saml/lib/IdP/SAML1.php b/modules/saml/lib/IdP/SAML1.php
index 2f5d81b29..9a11c4de6 100644
--- a/modules/saml/lib/IdP/SAML1.php
+++ b/modules/saml/lib/IdP/SAML1.php
@@ -124,7 +124,7 @@ class sspmod_saml_IdP_SAML1
         $state = array(
             'Responder' => array('sspmod_saml_IdP_SAML1', 'sendResponse'),
             'SPMetadata' => $spMetadata->toArray(),
-            SimpleSAML_Auth_State::RESTART => $sessionLostURL,
+            \SimpleSAML\Auth\State::RESTART => $sessionLostURL,
             'saml:shire' => $shire,
             'saml:target' => $target,
             'saml:AuthnRequestReceivedAt' => microtime(true),
diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php
index 6e7084773..ef3a53427 100644
--- a/modules/saml/lib/IdP/SAML2.php
+++ b/modules/saml/lib/IdP/SAML2.php
@@ -412,8 +412,8 @@ class sspmod_saml_IdP_SAML2
 
         $state = array(
             'Responder'                                   => array('sspmod_saml_IdP_SAML2', 'sendResponse'),
-            SimpleSAML_Auth_State::EXCEPTION_HANDLER_FUNC => array('sspmod_saml_IdP_SAML2', 'handleAuthError'),
-            SimpleSAML_Auth_State::RESTART                => $sessionLostURL,
+            \SimpleSAML\Auth\State::EXCEPTION_HANDLER_FUNC => array('sspmod_saml_IdP_SAML2', 'handleAuthError'),
+            \SimpleSAML\Auth\State::RESTART                => $sessionLostURL,
 
             'SPMetadata'                  => $spMetadata->toArray(),
             'saml:RelayState'             => $relayState,
diff --git a/modules/saml/www/proxy/invalid_session.php b/modules/saml/www/proxy/invalid_session.php
index 4ce213bdf..934373a5a 100644
--- a/modules/saml/www/proxy/invalid_session.php
+++ b/modules/saml/www/proxy/invalid_session.php
@@ -16,10 +16,10 @@ if (!array_key_exists('AuthState', $_REQUEST)) {
 
 try {
     // try to get the state
-    $state = \SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], 'saml:proxy:invalid_idp');
+    $state = \SimpleSAML\Auth\State::loadState($_REQUEST['AuthState'], 'saml:proxy:invalid_idp');
 } catch (\Exception $e) {
     // the user probably hit the back button after starting the logout, try to recover the state with another stage
-    $state = \SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], 'core:Logout:afterbridge');
+    $state = \SimpleSAML\Auth\State::loadState($_REQUEST['AuthState'], 'core:Logout:afterbridge');
 
     // success! Try to continue with reauthentication, since we no longer have a valid session here
     $idp = \SimpleSAML_IdP::getById($state['core:IdP']);
@@ -28,7 +28,7 @@ try {
 
 if (isset($_POST['cancel'])) {
     // the user does not want to logout, cancel login
-    \SimpleSAML_Auth_State::throwException(
+    \SimpleSAML\Auth\State::throwException(
         $state,
         new \SimpleSAML\Module\saml\Error\NoAvailableIDP(
             \SAML2\Constants::STATUS_RESPONDER,
@@ -39,7 +39,7 @@ if (isset($_POST['cancel'])) {
 
 if (isset($_POST['continue'])) {
     // log the user out before being able to login again
-    $as = \SimpleSAML_Auth_Source::getById($state['saml:sp:AuthId'], 'sspmod_saml_Auth_Source_SP');
+    $as = \SimpleSAML\Auth\Source::getById($state['saml:sp:AuthId'], 'sspmod_saml_Auth_Source_SP');
     /** @var \sspmod_saml_Auth_Source_SP $as */
     $as->reauthLogout($state);
 }
diff --git a/modules/saml/www/sp/discoresp.php b/modules/saml/www/sp/discoresp.php
index 3c83ff167..7c7bb68a5 100644
--- a/modules/saml/www/sp/discoresp.php
+++ b/modules/saml/www/sp/discoresp.php
@@ -11,13 +11,13 @@ if (!array_key_exists('AuthID', $_REQUEST)) {
 if (!array_key_exists('idpentityid', $_REQUEST)) {
     throw new \SimpleSAML\Error\BadRequest('Missing idpentityid to discovery service response handler');
 }
-$state = SimpleSAML_Auth_State::loadState($_REQUEST['AuthID'], 'saml:sp:sso');
+$state = \SimpleSAML\Auth\State::loadState($_REQUEST['AuthID'], 'saml:sp:sso');
 
 // Find authentication source
 assert(array_key_exists('saml:sp:AuthId', $state));
 $sourceId = $state['saml:sp:AuthId'];
 
-$source = SimpleSAML_Auth_Source::getById($sourceId);
+$source = \SimpleSAML\Auth\Source::getById($sourceId);
 if ($source === null) {
     throw new Exception('Could not find authentication source with id ' . $sourceId);
 }
diff --git a/modules/saml/www/sp/metadata.php b/modules/saml/www/sp/metadata.php
index 10766a65d..eb78a0dfc 100644
--- a/modules/saml/www/sp/metadata.php
+++ b/modules/saml/www/sp/metadata.php
@@ -9,7 +9,7 @@ if ($config->getBoolean('admin.protectmetadata', false)) {
     \SimpleSAML\Utils\Auth::requireAdmin();
 }
 $sourceId = substr($_SERVER['PATH_INFO'], 1);
-$source = \SimpleSAML_Auth_Source::getById($sourceId);
+$source = \SimpleSAML\Auth\Source::getById($sourceId);
 if ($source === null) {
     throw new \SimpleSAML\Error\AuthSource($sourceId, 'Could not find authentication source.');
 }
diff --git a/modules/saml/www/sp/saml1-acs.php b/modules/saml/www/sp/saml1-acs.php
index 9d8897441..7d7dbc0c5 100644
--- a/modules/saml/www/sp/saml1-acs.php
+++ b/modules/saml/www/sp/saml1-acs.php
@@ -21,7 +21,7 @@ if ($end === false) {
 }
 $sourceId = substr($sourceId, 1, $end - 1);
 
-$source = SimpleSAML_Auth_Source::getById($sourceId, 'sspmod_saml_Auth_Source_SP');
+$source = \SimpleSAML\Auth\Source::getById($sourceId, 'sspmod_saml_Auth_Source_SP');
 
 SimpleSAML\Logger::debug('Received SAML1 response');
 
@@ -35,7 +35,7 @@ if (preg_match('@^https?://@i', $target)) {
         'saml:sp:RelayState' => \SimpleSAML\Utils\HTTP::checkURLAllowed($target),
     );
 } else {
-    $state = SimpleSAML_Auth_State::loadState($_REQUEST['TARGET'], 'saml:sp:sso');
+    $state = \SimpleSAML\Auth\State::loadState($_REQUEST['TARGET'], 'saml:sp:sso');
 
     // Check that the authentication source is correct.
     assert(array_key_exists('saml:sp:AuthId', $state));
diff --git a/modules/saml/www/sp/saml2-acs.php b/modules/saml/www/sp/saml2-acs.php
index 4c8a328a1..2bb3b9fe3 100644
--- a/modules/saml/www/sp/saml2-acs.php
+++ b/modules/saml/www/sp/saml2-acs.php
@@ -9,7 +9,7 @@ if (!array_key_exists('PATH_INFO', $_SERVER)) {
 }
 
 $sourceId = substr($_SERVER['PATH_INFO'], 1);
-$source = SimpleSAML_Auth_Source::getById($sourceId, 'sspmod_saml_Auth_Source_SP');
+$source = \SimpleSAML\Auth\Source::getById($sourceId, 'sspmod_saml_Auth_Source_SP');
 $spMetadata = $source->getMetadata();
 
 try {
@@ -77,7 +77,7 @@ $stateId = $response->getInResponseTo();
 if (!empty($stateId)) {
     // this should be a response to a request we sent earlier
     try {
-        $state = SimpleSAML_Auth_State::loadState($stateId, 'saml:sp:sso');
+        $state = \SimpleSAML\Auth\State::loadState($stateId, 'saml:sp:sso');
     } catch (Exception $e) {
         // something went wrong,
         SimpleSAML\Logger::warning('Could not load state specified by InResponseTo: '.$e->getMessage().
@@ -130,7 +130,7 @@ try {
 } catch (sspmod_saml_Error $e) {
     // the status of the response wasn't "success"
     $e = $e->toException();
-    SimpleSAML_Auth_State::throwException($state, $e);
+    \SimpleSAML\Auth\State::throwException($state, $e);
 }
 
 
@@ -148,7 +148,7 @@ foreach ($assertions as $assertion) {
         $aID = $assertion->getId();
         if ($store->get('saml.AssertionReceived', $aID) !== null) {
             $e = new \SimpleSAML\Error\Exception('Received duplicate assertion.');
-            SimpleSAML_Auth_State::throwException($state, $e);
+            \SimpleSAML\Auth\State::throwException($state, $e);
         }
 
         $notOnOrAfter = $assertion->getNotOnOrAfter();
@@ -185,7 +185,7 @@ foreach ($assertions as $assertion) {
 
 if (!$foundAuthnStatement) {
     $e = new \SimpleSAML\Error\Exception('No AuthnStatement found in assertion(s).');
-    SimpleSAML_Auth_State::throwException($state, $e);
+    \SimpleSAML\Auth\State::throwException($state, $e);
 }
 
 if ($expire !== null) {
@@ -247,8 +247,8 @@ $state['saml:sp:prevAuth'] = array(
     'id'     => $response->getId(),
     'issuer' => $idp,
 );
-if (isset($state['SimpleSAML_Auth_Source.ReturnURL'])) {
-    $state['saml:sp:prevAuth']['redirect'] = $state['SimpleSAML_Auth_Source.ReturnURL'];
+if (isset($state['\SimpleSAML\Auth\Source.ReturnURL'])) {
+    $state['saml:sp:prevAuth']['redirect'] = $state['\SimpleSAML\Auth\Source.ReturnURL'];
 } elseif (isset($state['saml:sp:RelayState'])) {
     $state['saml:sp:prevAuth']['redirect'] = $state['saml:sp:RelayState'];
 }
diff --git a/modules/saml/www/sp/saml2-logout.php b/modules/saml/www/sp/saml2-logout.php
index f6e2f0e9d..5b1da5e55 100644
--- a/modules/saml/www/sp/saml2-logout.php
+++ b/modules/saml/www/sp/saml2-logout.php
@@ -12,7 +12,7 @@ if (!array_key_exists('PATH_INFO', $_SERVER)) {
 
 $sourceId = substr($_SERVER['PATH_INFO'], 1);
 
-$source = SimpleSAML_Auth_Source::getById($sourceId);
+$source = \SimpleSAML\Auth\Source::getById($sourceId);
 if ($source === null) {
     throw new \Exception('Could not find authentication source with id ' . $sourceId);
 }
@@ -61,17 +61,17 @@ if ($message instanceof \SAML2\LogoutResponse) {
     }
 
     if (!$message->isSuccess()) {
-        SimpleSAML\Logger::warning('Unsuccessful logout. Status was: ' . sspmod_saml_Message::getResponseError($message));
+        \SimpleSAML\Logger::warning('Unsuccessful logout. Status was: ' . sspmod_saml_Message::getResponseError($message));
     }
 
-    $state = SimpleSAML_Auth_State::loadState($relayState, 'saml:slosent');
+    $state = \SimpleSAML\Auth\State::loadState($relayState, 'saml:slosent');
     $state['saml:sp:LogoutStatus'] = $message->getStatus();
-    SimpleSAML_Auth_Source::completeLogout($state);
+    \SimpleSAML\Auth\Source::completeLogout($state);
 
 } elseif ($message instanceof \SAML2\LogoutRequest) {
 
-    SimpleSAML\Logger::debug('module/saml2/sp/logout: Request from ' . $idpEntityId);
-    SimpleSAML\Logger::stats('saml20-idp-SLO idpinit ' . $spEntityId . ' ' . $idpEntityId);
+    \SimpleSAML\Logger::debug('module/saml2/sp/logout: Request from ' . $idpEntityId);
+    \SimpleSAML\Logger::stats('saml20-idp-SLO idpinit ' . $spEntityId . ' ' . $idpEntityId);
 
     if ($message->isNameIdEncrypted()) {
         try {
@@ -86,11 +86,11 @@ if ($message instanceof \SAML2\LogoutResponse) {
         foreach ($keys as $i => $key) {
             try {
                 $message->decryptNameId($key, $blacklist);
-                SimpleSAML\Logger::debug('Decryption with key #' . $i . ' succeeded.');
+                \SimpleSAML\Logger::debug('Decryption with key #' . $i . ' succeeded.');
                 $lastException = null;
                 break;
             } catch (\Exception $e) {
-                SimpleSAML\Logger::debug('Decryption with key #' . $i . ' failed with exception: ' . $e->getMessage());
+                \SimpleSAML\Logger::debug('Decryption with key #' . $i . ' failed with exception: ' . $e->getMessage());
                 $lastException = $e;
             }
         }
@@ -115,7 +115,7 @@ if ($message instanceof \SAML2\LogoutResponse) {
     $lr->setInResponseTo($message->getId());
 
     if ($numLoggedOut < count($sessionIndexes)) {
-        SimpleSAML\Logger::warning('Logged out of ' . $numLoggedOut  . ' of ' . count($sessionIndexes) . ' sessions.');
+        \SimpleSAML\Logger::warning('Logged out of ' . $numLoggedOut  . ' of ' . count($sessionIndexes) . ' sessions.');
     }
 
     $dst = $idpMetadata->getEndpointPrioritizedByBinding('SingleLogoutService', array(
diff --git a/modules/smartattributes/lib/Auth/Process/SmartID.php b/modules/smartattributes/lib/Auth/Process/SmartID.php
index 4d3f0a30d..cf0b7036c 100644
--- a/modules/smartattributes/lib/Auth/Process/SmartID.php
+++ b/modules/smartattributes/lib/Auth/Process/SmartID.php
@@ -1,6 +1,6 @@
 <?php
 
-class sspmod_smartattributes_Auth_Process_SmartID extends SimpleSAML_Auth_ProcessingFilter
+class sspmod_smartattributes_Auth_Process_SmartID extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * Which attributes to use as identifiers?
diff --git a/modules/smartattributes/lib/Auth/Process/SmartName.php b/modules/smartattributes/lib/Auth/Process/SmartName.php
index 23e71fd85..b41e6aabc 100644
--- a/modules/smartattributes/lib/Auth/Process/SmartName.php
+++ b/modules/smartattributes/lib/Auth/Process/SmartName.php
@@ -6,7 +6,8 @@
  * @author Andreas Ã…kre Solberg, UNINETT AS.
  * @package SimpleSAMLphp
  */
-class sspmod_smartattributes_Auth_Process_SmartName extends SimpleSAML_Auth_ProcessingFilter
+
+class sspmod_smartattributes_Auth_Process_SmartName extends \SimpleSAML\Auth\ProcessingFilter
 {
     /**
      * Attributes which should be added/appended.
diff --git a/tests/lib/SimpleSAML/Auth/SourceTest.php b/tests/lib/SimpleSAML/Auth/SourceTest.php
index 0cbf1e849..e51781d72 100644
--- a/tests/lib/SimpleSAML/Auth/SourceTest.php
+++ b/tests/lib/SimpleSAML/Auth/SourceTest.php
@@ -6,13 +6,14 @@ use SimpleSAML\Auth\SourceFactory;
 use SimpleSAML\Test\Utils\ClearStateTestCase;
 
 /**
- * Tests for SimpleSAML_Auth_Source
+ * Tests for \SimpleSAML\Auth\Source
  */
+
 class SourceTest extends ClearStateTestCase
 {
     public function testParseAuthSource()
     {
-        $class = new \ReflectionClass('SimpleSAML_Auth_Source');
+        $class = new \ReflectionClass('\SimpleSAML\Auth\Source');
         $method = $class->getMethod('parseAuthSource');
         $method->setAccessible(true);
 
@@ -26,7 +27,7 @@ class SourceTest extends ClearStateTestCase
     }
 }
 
-class TestAuthSource extends \SimpleSAML_Auth_Source
+class TestAuthSource extends \SimpleSAML\Auth\Source
 {
     public function authenticate(&$state)
     {
diff --git a/tests/lib/SimpleSAML/Auth/StateTest.php b/tests/lib/SimpleSAML/Auth/StateTest.php
index 0edb0b20e..b9bc2b5c4 100644
--- a/tests/lib/SimpleSAML/Auth/StateTest.php
+++ b/tests/lib/SimpleSAML/Auth/StateTest.php
@@ -3,12 +3,10 @@
 use PHPUnit\Framework\TestCase;
 
 /**
- * Tests for SimpleSAML_Auth_State
+ * Tests for \SimpleSAML\Auth\State
  */
 class Auth_StateTest extends TestCase
 {
-
-
     /**
      * Test the getPersistentAuthData() function.
      */
@@ -29,7 +27,7 @@ class Auth_StateTest extends TestCase
         $expected = $mandatory;
         $this->assertEquals(
             $expected,
-            SimpleSAML_Auth_State::getPersistentAuthData($state),
+            \SimpleSAML\Auth\State::getPersistentAuthData($state),
             'Mandatory state attributes did not survive as expected'.print_r($expected, true)
         );
 
@@ -39,7 +37,7 @@ class Auth_StateTest extends TestCase
         $expected = $state;
         $this->assertEquals(
             $expected,
-            SimpleSAML_Auth_State::getPersistentAuthData($state),
+            \SimpleSAML\Auth\State::getPersistentAuthData($state),
             'Some error occurred with missing mandatory parameters'
         );
 
@@ -52,7 +50,7 @@ class Auth_StateTest extends TestCase
         $expected = $mandatory;
         $this->assertEquals(
             $expected,
-            SimpleSAML_Auth_State::getPersistentAuthData($state),
+            \SimpleSAML\Auth\State::getPersistentAuthData($state),
             'Additional parameters survived'
         );
 
@@ -64,7 +62,7 @@ class Auth_StateTest extends TestCase
         unset($expected['PersistentAuthData']);
         $this->assertEquals(
             $expected,
-            SimpleSAML_Auth_State::getPersistentAuthData($state),
+            \SimpleSAML\Auth\State::getPersistentAuthData($state),
             'Some error occurred with additional, persistent parameters'
         );
 
@@ -75,7 +73,7 @@ class Auth_StateTest extends TestCase
         unset($expected['PersistentAuthData']);
         $this->assertEquals(
             $expected,
-            SimpleSAML_Auth_State::getPersistentAuthData($state),
+            \SimpleSAML\Auth\State::getPersistentAuthData($state),
             'Some error occurred with additional, persistent parameters, and no mandatory ones'
         );
     }
diff --git a/tests/lib/SimpleSAML/ModuleTest.php b/tests/lib/SimpleSAML/ModuleTest.php
index bf5efbc7e..8cb330896 100644
--- a/tests/lib/SimpleSAML/ModuleTest.php
+++ b/tests/lib/SimpleSAML/ModuleTest.php
@@ -112,8 +112,8 @@ class ModuleTest extends TestCase
         // test for valid subclasses
         $this->assertEquals('sspmod_core_Auth_Process_PHP', Module::resolveClass(
             'core:PHP',
-            'Auth_Process',
-            'SimpleSAML_Auth_ProcessingFilter'
+            'Auth\Process',
+            '\SimpleSAML\Auth\ProcessingFilter'
         ));
     }
 }
-- 
GitLab