From 53e918b08a4be67d93458978a12a2e6024bbcef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Pe=CC=81rez=20Crespo?= <jaime.perez@uninett.no> Date: Thu, 7 Sep 2017 12:48:07 +0200 Subject: [PATCH] Migrate SimpleSAML_Auth_Simple to use namespaces. It can now be used with \SimpleSAML\Auth\Simple, although the old name still works too. --- docs/simplesamlphp-scoping.md | 2 +- docs/simplesamlphp-sp-api.md | 8 ++--- docs/simplesamlphp-sp-migration.md | 4 +-- docs/simplesamlphp-sp.md | 2 +- lib/SimpleSAML/Auth/Simple.php | 53 ++++++++++++++++------------- modules/multiauth/docs/multiauth.md | 2 +- modules/saml/docs/sp.md | 4 +-- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/docs/simplesamlphp-scoping.md b/docs/simplesamlphp-scoping.md index 4f1ff8710..3124122ed 100644 --- a/docs/simplesamlphp-scoping.md +++ b/docs/simplesamlphp-scoping.md @@ -88,7 +88,7 @@ The list of authenticating authorities (the AuthenticatingAuthority element) can be retrieved as an array from the authentication data. # Get the authentication source. - $as = new SimpleSAML_Auth_Simple(); + $as = new \SimpleSAML\Auth\Simple(); # Get the AuthenticatingAuthority $aa = $as->getAuthData('saml:AuthenticatingAuthority'); diff --git a/docs/simplesamlphp-sp-api.md b/docs/simplesamlphp-sp-api.md index fae5b14c8..2de1b509a 100644 --- a/docs/simplesamlphp-sp-api.md +++ b/docs/simplesamlphp-sp-api.md @@ -3,15 +3,15 @@ SimpleSAMLphp SP API reference <!-- {{TOC}} --> -This document describes the SimpleSAML_Auth_Simple API. +This document describes the \SimpleSAML\Auth\Simple API. This is the preferred API for integrating SimpleSAMLphp with other applications. Constructor ----------- - new SimpleSAML_Auth_Simple(string $authSource) + new \SimpleSAML\Auth\Simple(string $authSource) -The constructor initializes a SimpleSAML_Auth_Simple object. +The constructor initializes a \SimpleSAML\Auth\Simple object. ### Parameters @@ -20,7 +20,7 @@ This authentication source must exist in `config/authsources.php`. ### Example - $auth = new SimpleSAML_Auth_Simple('default-sp'); + $auth = new \SimpleSAML\Auth\Simple('default-sp'); `isAuthenticated` diff --git a/docs/simplesamlphp-sp-migration.md b/docs/simplesamlphp-sp-migration.md index ff6f3e1ee..ae3303cf8 100644 --- a/docs/simplesamlphp-sp-migration.md +++ b/docs/simplesamlphp-sp-migration.md @@ -132,7 +132,7 @@ This API is designed to handle the common operations. This is a quick overview of the API: /* Get a reference to our authentication source. */ - $as = new SimpleSAML_Auth_Simple('default-sp'); + $as = new \SimpleSAML\Auth\Simple('default-sp'); /* Require the user to be authentcated. */ $as->requireAuth(); @@ -159,7 +159,7 @@ Generally, if you have: you should replace it with this single line: - $as = new SimpleSAML_Auth_Simple('default-sp'); + $as = new \SimpleSAML\Auth\Simple('default-sp'); #### Requiring authentication diff --git a/docs/simplesamlphp-sp.md b/docs/simplesamlphp-sp.md index 3cc6d65cf..c7de105c2 100644 --- a/docs/simplesamlphp-sp.md +++ b/docs/simplesamlphp-sp.md @@ -168,7 +168,7 @@ We start off with loading a file which registers the SimpleSAMLphp classes with We select our authentication source: - $as = new SimpleSAML_Auth_Simple('default-sp'); + $as = new \SimpleSAML\Auth\Simple('default-sp'); We then require authentication: diff --git a/lib/SimpleSAML/Auth/Simple.php b/lib/SimpleSAML/Auth/Simple.php index 723c8667c..16e8c32e6 100644 --- a/lib/SimpleSAML/Auth/Simple.php +++ b/lib/SimpleSAML/Auth/Simple.php @@ -1,12 +1,19 @@ <?php +namespace SimpleSAML\Auth; + +use \SimpleSAML_Auth_Source as Source; +use \SimpleSAML_Auth_State as State; +use \SimpleSAML\Module; +use \SimpleSAML_Session as Session; +use \SimpleSAML\Utils\HTTP; /** * Helper class for simple authentication applications. * * @package SimpleSAMLphp */ -class SimpleSAML_Auth_Simple +class Simple { /** @@ -33,15 +40,15 @@ class SimpleSAML_Auth_Simple /** * Retrieve the implementing authentication source. * - * @return SimpleSAML_Auth_Source The authentication source. + * @return \SimpleSAML_Auth_Source The authentication source. * - * @throws SimpleSAML_Error_AuthSource If the requested auth source is unknown. + * @throws \SimpleSAML_Error_AuthSource If the requested auth source is unknown. */ public function getAuthSource() { - $as = SimpleSAML_Auth_Source::getById($this->authSource); + $as = Source::getById($this->authSource); if ($as === null) { - throw new SimpleSAML_Error_AuthSource($this->authSource, 'Unknown authentication source.'); + throw new \SimpleSAML_Error_AuthSource($this->authSource, 'Unknown authentication source.'); } return $as; } @@ -57,7 +64,7 @@ class SimpleSAML_Auth_Simple */ public function isAuthenticated() { - $session = SimpleSAML_Session::getSessionFromRequest(); + $session = Session::getSessionFromRequest(); return $session->isValid($this->authSource); } @@ -79,7 +86,7 @@ class SimpleSAML_Auth_Simple public function requireAuth(array $params = array()) { - $session = SimpleSAML_Session::getSessionFromRequest(); + $session = Session::getSessionFromRequest(); if ($session->isValid($this->authSource)) { // Already authenticated @@ -119,12 +126,12 @@ class SimpleSAML_Auth_Simple if (array_key_exists('ReturnCallback', $params)) { $returnTo = (array) $params['ReturnCallback']; } else { - $returnTo = \SimpleSAML\Utils\HTTP::getSelfURL(); + $returnTo = HTTP::getSelfURL(); } } if (is_string($returnTo) && $keepPost && $_SERVER['REQUEST_METHOD'] === 'POST') { - $returnTo = \SimpleSAML\Utils\HTTP::getPOSTRedirectURL($returnTo, $_POST); + $returnTo = HTTP::getPOSTRedirectURL($returnTo, $_POST); } if (array_key_exists('ErrorURL', $params)) { @@ -134,13 +141,13 @@ class SimpleSAML_Auth_Simple } - if (!isset($params[SimpleSAML_Auth_State::RESTART]) && is_string($returnTo)) { + if (!isset($params[State::RESTART]) && is_string($returnTo)) { /* * A URL to restart the authentication, in case the user bookmarks * something, e.g. the discovery service page. */ $restartURL = $this->getLoginURL($returnTo); - $params[SimpleSAML_Auth_State::RESTART] = $restartURL; + $params[State::RESTART] = $restartURL; } $as = $this->getAuthSource(); @@ -161,7 +168,7 @@ class SimpleSAML_Auth_Simple * - 'ReturnStateParam': The parameter we should return the state in when redirecting. * - 'ReturnStateStage': The stage the state array should be saved with. * - * @param string|array|NULL $params Either the URL the user should be redirected to after logging out, or an array + * @param string|array|null $params Either the URL the user should be redirected to after logging out, or an array * with parameters for the logout. If this parameter is null, we will return to the current page. */ public function logout($params = null) @@ -169,7 +176,7 @@ class SimpleSAML_Auth_Simple assert('is_array($params) || is_string($params) || is_null($params)'); if ($params === null) { - $params = \SimpleSAML\Utils\HTTP::getSelfURL(); + $params = HTTP::getSelfURL(); } if (is_string($params)) { @@ -185,7 +192,7 @@ class SimpleSAML_Auth_Simple assert('isset($params["ReturnStateParam"]) && isset($params["ReturnStateStage"])'); } - $session = SimpleSAML_Session::getSessionFromRequest(); + $session = Session::getSessionFromRequest(); if ($session->isValid($this->authSource)) { $state = $session->getAuthData($this->authSource, 'LogoutState'); if ($state !== null) { @@ -196,7 +203,7 @@ class SimpleSAML_Auth_Simple $params['LogoutCompletedHandler'] = array(get_class(), 'logoutCompleted'); - $as = SimpleSAML_Auth_Source::getById($this->authSource); + $as = Source::getById($this->authSource); if ($as !== null) { $as->logout($params); } @@ -225,7 +232,7 @@ class SimpleSAML_Auth_Simple $params = array(); if (isset($state['ReturnStateParam']) || isset($state['ReturnStateStage'])) { assert('isset($state["ReturnStateParam"]) && isset($state["ReturnStateStage"])'); - $stateID = SimpleSAML_Auth_State::saveState($state, $state['ReturnStateStage']); + $stateID = State::saveState($state, $state['ReturnStateStage']); $params[$state['ReturnStateParam']] = $stateID; } \SimpleSAML\Utils\HTTP::redirectTrustedURL($state['ReturnTo'], $params); @@ -250,7 +257,7 @@ class SimpleSAML_Auth_Simple } // Authenticated - $session = SimpleSAML_Session::getSessionFromRequest(); + $session = Session::getSessionFromRequest(); return $session->getAuthData($this->authSource, 'Attributes'); } @@ -270,7 +277,7 @@ class SimpleSAML_Auth_Simple return null; } - $session = SimpleSAML_Session::getSessionFromRequest(); + $session = Session::getSessionFromRequest(); return $session->getAuthData($this->authSource, $name); } @@ -287,7 +294,7 @@ class SimpleSAML_Auth_Simple return null; } - $session = SimpleSAML_Session::getSessionFromRequest(); + $session = Session::getSessionFromRequest(); return $session->getAuthState($this->authSource); } @@ -305,10 +312,10 @@ class SimpleSAML_Auth_Simple assert('is_null($returnTo) || is_string($returnTo)'); if ($returnTo === null) { - $returnTo = \SimpleSAML\Utils\HTTP::getSelfURL(); + $returnTo = HTTP::getSelfURL(); } - $login = SimpleSAML\Module::getModuleURL('core/as_login.php', array( + $login = Module::getModuleURL('core/as_login.php', array( 'AuthId' => $this->authSource, 'ReturnTo' => $returnTo, )); @@ -330,10 +337,10 @@ class SimpleSAML_Auth_Simple assert('is_null($returnTo) || is_string($returnTo)'); if ($returnTo === null) { - $returnTo = \SimpleSAML\Utils\HTTP::getSelfURL(); + $returnTo = HTTP::getSelfURL(); } - $logout = SimpleSAML\Module::getModuleURL('core/as_logout.php', array( + $logout = Module::getModuleURL('core/as_logout.php', array( 'AuthId' => $this->authSource, 'ReturnTo' => $returnTo, )); diff --git a/modules/multiauth/docs/multiauth.md b/modules/multiauth/docs/multiauth.md index 914f8153b..7b3e0f273 100644 --- a/modules/multiauth/docs/multiauth.md +++ b/modules/multiauth/docs/multiauth.md @@ -106,7 +106,7 @@ don't have redirections during the authentication process. You can also use the multiauth:preselect parameter to the login call: - $as = new SimpleSAML_Auth_Simple('my-multiauth-authsource'); + $as = new \SimpleSAML\Auth\Simple('my-multiauth-authsource'); $as->login(array( 'multiauth:preselect' => 'default-sp', )); diff --git a/modules/saml/docs/sp.md b/modules/saml/docs/sp.md index 31def6f69..f72df230e 100644 --- a/modules/saml/docs/sp.md +++ b/modules/saml/docs/sp.md @@ -481,7 +481,7 @@ Here we will list some examples for this authentication source. ### Requesting a specific authentication method. - $auth = new SimpleSAML_Auth_Simple('default-sp'); + $auth = new \SimpleSAML\Auth\Simple('default-sp'); $auth->login(array( 'saml:AuthnContextClassRef' => 'urn:oasis:names:tc:SAML:2.0:ac:classes:Password', )); @@ -492,7 +492,7 @@ Here we will list some examples for this authentication source. $ce = $dom->createElementNS('http://www.example.com/XFoo', 'xfoo:test', 'Test data!'); $ext[] = new \SAML2\XML\Chunk($ce); - $auth = new SimpleSAML_Auth_Simple('default-sp'); + $auth = new \SimpleSAML\Auth\Simple('default-sp'); $auth->login(array( 'saml:Extensions' => $ext, )); -- GitLab