From 5a138976f030cf13f4588a03cbeefbf2b9508036 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Thu, 31 May 2018 11:22:35 +0200 Subject: [PATCH] Replace SimpleSAML_AuthMemCookie with namespaced version --- lib/SimpleSAML/AuthMemCookie.php | 19 ++++++++++--------- www/authmemcookie.php | 12 ++++++------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/SimpleSAML/AuthMemCookie.php b/lib/SimpleSAML/AuthMemCookie.php index 17d9071a5..958952041 100644 --- a/lib/SimpleSAML/AuthMemCookie.php +++ b/lib/SimpleSAML/AuthMemCookie.php @@ -1,5 +1,6 @@ <?php +namespace SimpleSAML; /** * This is a helper class for the Auth MemCookie module. @@ -10,17 +11,17 @@ * * @deprecated This class has been deprecated and will be removed in SSP 2.0. Use the memcookie module instead. */ -class SimpleSAML_AuthMemCookie -{ +class AuthMemCookie +{ /** - * @var SimpleSAML_AuthMemCookie This is the singleton instance of this class. + * @var AuthMemCookie This is the singleton instance of this class. */ private static $instance = null; /** - * @var \SimpleSAML\Configuration The configuration for Auth MemCookie. + * @var Configuration The configuration for Auth MemCookie. */ private $amcConfig; @@ -28,12 +29,12 @@ class SimpleSAML_AuthMemCookie /** * This function is used to retrieve the singleton instance of this class. * - * @return SimpleSAML_AuthMemCookie The singleton instance of this class. + * @return AuthMemCookie The singleton instance of this class. */ public static function getInstance() { if (self::$instance === null) { - self::$instance = new SimpleSAML_AuthMemCookie(); + self::$instance = new AuthMemCookie(); } return self::$instance; @@ -46,7 +47,7 @@ class SimpleSAML_AuthMemCookie private function __construct() { // load AuthMemCookie configuration - $this->amcConfig = \SimpleSAML\Configuration::getConfig('authmemcookie.php'); + $this->amcConfig = Configuration::getConfig('authmemcookie.php'); } @@ -71,7 +72,7 @@ class SimpleSAML_AuthMemCookie { $cookieName = $this->amcConfig->getString('cookiename', 'AuthMemCookie'); if (!is_string($cookieName) || strlen($cookieName) === 0) { - throw new Exception( + throw new \Exception( "Configuration option 'cookiename' contains an invalid value. This option should be a string." ); } @@ -119,7 +120,7 @@ class SimpleSAML_AuthMemCookie $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.'); + throw new \Exception('Missing Memcached implementation. You must install either the Memcache or Memcached extension.'); } // Create the Memcache(d) object. diff --git a/www/authmemcookie.php b/www/authmemcookie.php index 672b83762..032c05f4c 100644 --- a/www/authmemcookie.php +++ b/www/authmemcookie.php @@ -24,7 +24,7 @@ try { } // load Auth MemCookie configuration - $amc = SimpleSAML_AuthMemCookie::getInstance(); + $amc = \SimpleSAML\AuthMemCookie::getInstance(); $sourceId = $amc->getAuthSource(); $s = new \SimpleSAML\Auth\Simple($sourceId); @@ -33,7 +33,7 @@ try { $s->requireAuth(); // generate session id and save it in a cookie - $sessionID = SimpleSAML\Utils\Random::generateID(); + $sessionID = \SimpleSAML\Utils\Random::generateID(); $cookieName = $amc->getCookieName(); \SimpleSAML\Utils\HTTP::setCookie($cookieName, $sessionID); @@ -45,7 +45,7 @@ try { // username $usernameAttr = $amc->getUsernameAttr(); if (!array_key_exists($usernameAttr, $attributes)) { - throw new Exception( + throw new \Exception( "The user doesn't have an attribute named '".$usernameAttr. "'. This attribute is expected to contain the username." ); @@ -56,7 +56,7 @@ try { $groupsAttr = $amc->getGroupsAttr(); if ($groupsAttr !== null) { if (!array_key_exists($groupsAttr, $attributes)) { - throw new Exception( + throw new \Exception( "The user doesn't have an attribute named '".$groupsAttr. "'. This attribute is expected to contain the groups the user is a member of." ); @@ -97,10 +97,10 @@ try { // register logout handler $session = \SimpleSAML\Session::getSessionFromRequest(); - $session->registerLogoutHandler($sourceId, 'SimpleSAML_AuthMemCookie', 'logoutHandler'); + $session->registerLogoutHandler($sourceId, '\SimpleSAML\AuthMemCookie', 'logoutHandler'); // redirect the user back to this page to signal that the login is completed \SimpleSAML\Utils\HTTP::redirectTrustedURL(\SimpleSAML\Utils\HTTP::getSelfURL()); -} catch (Exception $e) { +} catch (\Exception $e) { throw new \SimpleSAML\Error\Error('CONFIG', $e); } -- GitLab