Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace remaining non-namespaced classes #869

Merged
merged 14 commits into from Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions bin/importPdoMetadata.php
Expand Up @@ -3,14 +3,14 @@
$baseDir = dirname(dirname(__FILE__));

require_once $baseDir.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'_autoload.php';
require_once SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php';
require_once \SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php';

# Iterate through configured metadata sources and ensure
# that a PDO source exists.
foreach ($config['metadata.sources'] as $s) {
# If pdo is configured, create the new handler and add in the metadata sets.
if ($s['type'] === "pdo") {
$mdshp = new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($s);
$mdshp = new \SimpleSAML\Metadata\MetaDataStorageHandlerPdo($s);
$mdshp->initDatabase();

foreach (glob("metadata/*.php") as $filename) {
Expand Down
4 changes: 2 additions & 2 deletions bin/initMDSPdo.php
Expand Up @@ -6,7 +6,7 @@

// Add library autoloader and configuration
require_once $baseDir.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'_autoload.php';
require_once SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php';
require_once \SimpleSAML\Utils\Config::getConfigDir().DIRECTORY_SEPARATOR.'config.php';

echo "Initializing Metadata Database...".PHP_EOL;

Expand All @@ -15,7 +15,7 @@
foreach ($config['metadata.sources'] as $source) {
# If pdo is configured, create the new handler and initialize the DB.
if ($source['type'] === "pdo") {
$metadataStorageHandler = new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($source);
$metadataStorageHandler = new \SimpleSAML\Metadata\MetaDataStorageHandlerPdo($source);
$result = $metadataStorageHandler->initDatabase();

if ($result === false) {
Expand Down
6 changes: 3 additions & 3 deletions bin/memcacheSync.php
Expand Up @@ -26,14 +26,14 @@

// Initialize the configuration
$configdir = SimpleSAML\Utils\Config::getConfigDir();
SimpleSAML_Configuration::setConfigDir($configdir);
\SimpleSAML\Configuration::setConfigDir($configdir);

// Things we should warn the user about
$warnServerDown = 0;
$warnBigSlab = 0;

// We use the stats interface to determine which servers exists
$stats = SimpleSAML_Memcache::getRawStats();
$stats = \SimpleSAML\Memcache::getRawStats();

$keys = array();
foreach ($stats as $group) {
Expand Down Expand Up @@ -61,7 +61,7 @@
$skipped = 0;
$sync = 0;
foreach ($keys as $key) {
$res = SimpleSAML_Memcache::get($key);
$res = \SimpleSAML\Memcache::get($key);
if ($res === null) {
$skipped += 1;
} else {
Expand Down
8 changes: 4 additions & 4 deletions config-templates/config.php
Expand Up @@ -231,11 +231,11 @@
'errorreporting' => true,

/*
* Custom error show function called from SimpleSAML_Error_Error::show.
* Custom error show function called from SimpleSAML\Error\Error::show.
* See docs/simplesamlphp-errorhandling.txt for function code example.
*
* Example:
* 'errors.show_function' => array('sspmod_example_Error_Show', 'show'),
* 'errors.show_function' => array('SimpleSAML\Module\example\Error', 'show'),
*/


Expand Down Expand Up @@ -563,7 +563,7 @@
* See docs/simplesamlphp-advancedfeatures.txt for function code example.
*
* Example:
* 'session.check_function' => array('sspmod_example_Util', 'checkSession'),
* 'session.check_function' => array('\SimpleSAML\Module\example\Util', 'checkSession'),
*/


Expand Down Expand Up @@ -740,7 +740,7 @@
* the default language for the user.
*
* Example:
* 'language.get_language_function' => array('sspmod_example_Template', 'getLanguage'),
* 'language.get_language_function' => array('\SimpleSAML\Module\example\Template', 'getLanguage'),
*/

/*
Expand Down
4 changes: 2 additions & 2 deletions docs/simplesamlphp-advancedfeatures.md
Expand Up @@ -127,7 +127,7 @@ Example code for the function with GeoIP country check:
}

if ($init) {
$session->setData($data_type, $data_key, $remote_addr, SimpleSAML_Session::DATA_TIMEOUT_SESSION_END);
$session->setData($data_type, $data_key, $remote_addr, \SimpleSAML\Session::DATA_TIMEOUT_SESSION_END);
return;
}

Expand All @@ -147,7 +147,7 @@ Example code for the function with GeoIP country check:

if ($country_a === $country_b) {
if ($stored_remote_addr !== $remote_addr) {
$session->setData($data_type, $data_key, $remote_addr, SimpleSAML_Session::DATA_TIMEOUT_SESSION_END);
$session->setData($data_type, $data_key, $remote_addr, \SimpleSAML\Session::DATA_TIMEOUT_SESSION_END);
}

return TRUE;
Expand Down
10 changes: 5 additions & 5 deletions docs/simplesamlphp-authproc.md
Expand Up @@ -61,7 +61,7 @@ The configuration of *Auth Proc Filters* is a list of filters with priority as *

This configuration will execute *Auth Proc Filters* one by one, with the priority value in increasing order. When *Auth Proc Filters* is configured in multiple places, in example both globally, in the hosted IdP and remote SP metadata, then the list is interleaved sorted by priority.

The most important parameter of each item on the list is the *class* of the *Auth Proc Filter*. The syntax of the class is `modulename:classname`. As an example the class definition `core:AttributeLimit` will be expanded to look for the class `sspmod_core_Auth_Process_AttributeLimit`. The location of this class file *must* then be: `modules/core/lib/Auth/Process/AttributeLimit.php`.
The most important parameter of each item on the list is the *class* of the *Auth Proc Filter*. The syntax of the class is `modulename:classname`. As an example the class definition `core:AttributeLimit` will be expanded to look for the class `\SimpleSAML\Module\core\Auth\Process\AttributeLimit`. The location of this class file *must* then be: `modules/core/lib/Auth/Process/AttributeLimit.php`.

You will see that a bunch of useful filters is included in the `core` module. In addition the `consent` module that is included in the SimpleSAMLphp distribution implements a filter. Beyond that, you are encouraged to create your own filters and share with the community. If you have created a cool *Auth Proc Filter* that does something useful, let us know, and we may share it on the [SimpleSAMLphp web site][].

Expand Down Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions docs/simplesamlphp-authsource.md
@@ -1,8 +1,8 @@
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.
All authentication sources are located in the `lib/Auth/Source/` directory in a module, and the class name is `\SimpleSAML\Module\<module>\Auth\Source\<name>`.
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.
Expand All @@ -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.
Expand All @@ -36,13 +36,13 @@ Username/password authentication
--------------------------------

Since username/password authentication is quite a common operation, a base class has been created for this.
This is the `sspmod_core_Auth_UserPassBase` class, which is can be found as `modules/core/lib/Auth/UserPassBase.php`.
This is the `\SimpleSAML\Module\core\Auth\UserPassBase` class, which is can be found as `modules/core/lib/Auth/UserPassBase.php`.

The only function you need to implement is the `login($username, $password)`-function.
This function receives the username and password the user entered, and is expected to return the attributes of that user.
If the username or password is incorrect, it should throw an error saying so:

throw new SimpleSAML_Error_Error('WRONGUSERPASS');
throw new \impleSAML\Error\Error('WRONGUSERPASS');

"[Implementing custom username/password authentication](./simplesamlphp-customauth)" describes how to implement username/password authentication using that base class.

Expand All @@ -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.
Expand All @@ -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.

-
Expand All @@ -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**:
Expand Down
22 changes: 11 additions & 11 deletions docs/simplesamlphp-customauth.md
Expand Up @@ -40,10 +40,10 @@ To begin with, we will create a very simple authentication source, where the use
Create the file `modules/mymodule/lib/Auth/Source/MyAuth.php` with the following contents:

<?php
class sspmod_mymodule_Auth_Source_MyAuth extends sspmod_core_Auth_UserPassBase {
class MyAuth extends \SimpleSAML\Module\core\Auth\UserPassBase {
protected function login($username, $password) {
if ($username !== 'theusername' || $password !== 'thepassword') {
throw new SimpleSAML_Error_Error('WRONGUSERPASS');
throw new \SimpleSAML\Error\Error('WRONGUSERPASS');
}
return array(
'uid' => array('theusername'),
Expand All @@ -55,16 +55,16 @@ Create the file `modules/mymodule/lib/Auth/Source/MyAuth.php` with the following

Some things to note:

- The classname is `sspmod_mymodule_Auth_Source_MyAuth`.
- The classname is `\SimpleSAML\Module\mymodule\Auth\Source\MyAuth`.
This tells SimpleSAMLphp to look for the class in `modules/mymodule/lib/Auth/Source/MyAuth.php`.

- Our authentication source subclassese `sspmod_core_Auth_UserPassBase`.
- Our authentication source subclassese `\SimpleSAML\Module\core\Auth\UserPassBase`.
This is a helper-class that implements much of the common code needed for username/password authentication.

- The `login` function receives the username and password the user enters.
It is expected to authenticate the user.
If the username or password is correct, it must return a set of attributes for the user.
Otherwise, it must throw the `SimpleSAML_Error_Error('WRONGUSERPASS');` exception.
Otherwise, it must throw the `\SimpleSAML\Error\Error('WRONGUSERPASS');` exception.

- Attributes are returned as an associative array of `name => values` pairs.
All attributes can have multiple values, so the values are always stored in an array.
Expand Down Expand Up @@ -97,7 +97,7 @@ You can add it to the beginning of the list, so that the file looks something li
The instance name is used to refer to this authentication source in other configuration files.

The first element of the configuration of the authentication source must be `'mymodule:MyAuth'`.
This tells SimpleSAMLphp to look for the `sspmod_mymodule_Auth_Source_MyAuth` class.
This tells SimpleSAMLphp to look for the `\SimpleSAML\Module\mymodule\Auth\Source\MyAuth` class.


Testing our authentication source
Expand Down Expand Up @@ -168,7 +168,7 @@ We can then use the properties in the `login` function.
The complete class file should look like this:

<?php
class sspmod_mymodule_Auth_Source_MyAuth extends sspmod_core_Auth_UserPassBase {
class MyAuth extends \SimpleSAML\Module\core\Auth\UserPassBase {

private $username;
private $password;
Expand All @@ -187,7 +187,7 @@ The complete class file should look like this:

protected function login($username, $password) {
if ($username !== $this->username || $password !== $this->password) {
throw new SimpleSAML_Error_Error('WRONGUSERPASS');
throw new \SimpleSAML\Error\Error('WRONGUSERPASS');
}
return array(
'uid' => array($this->username),
Expand Down Expand Up @@ -245,7 +245,7 @@ A SSHA password is created like this:
The class follows:

<?php
class sspmod_mymodule_Auth_Source_MyAuth extends sspmod_core_Auth_UserPassBase {
class MyAuth extends \SimpleSAML\Module\core\Auth\UserPassBase {

/* The database DSN.
* See the documentation for the various database drivers for information about the syntax:
Expand Down Expand Up @@ -323,14 +323,14 @@ The class follows:
if (!$row) {
/* User not found. */
SimpleSAML\Logger::warning('MyAuth: Could not find user ' . var_export($username, TRUE) . '.');
throw new SimpleSAML_Error_Error('WRONGUSERPASS');
throw new \SimpleSAML\Error\Error('WRONGUSERPASS');
}

/* Check the password. */
if (!$this->checkPassword($row['password_hash'], $password)) {
/* Invalid password. */
SimpleSAML\Logger::warning('MyAuth: Wrong password for user ' . var_export($username, TRUE) . '.');
throw new SimpleSAML_Error_Error('WRONGUSERPASS');
throw new \SimpleSAML\Error\Error('WRONGUSERPASS');
}

/* Create the attribute array of the user. */
Expand Down
6 changes: 3 additions & 3 deletions docs/simplesamlphp-database.md
Expand Up @@ -20,12 +20,12 @@ Getting Started
---------------
If you are just using the already configured database, which would normally be the case, all you need to do is get the global instance of the Database class.

$db = SimpleSAML\Database::getInstance();
$db = \SimpleSAML\Database::getInstance();

If there is a requirement to connect to an alternate database server (ex. authenticating users that exist on a different SQL server or database) you can specify an alternate configuration.

$config = new SimpleSAML_Configuration($myconfigarray, "mymodule/lib/Auth/Source/myauth.php");
$db = SimpleSAML\Database::getInstance($config);
$config = new \SimpleSAML\Configuration($myconfigarray, "mymodule/lib/Auth/Source/myauth.php");
$db = \SimpleSAML\Database::getInstance($config);

That will create a new instance of the database, separate from the global instance, specific to the configuration defined in $myconfigarray. If you are going to specify an alternate config, your configuration array must contain the same keys that exist in the master config (database.dsn, database.username, database.password, database.prefix, etc).

Expand Down