diff --git a/lib/SimpleSAML/IdP.php b/lib/SimpleSAML/IdP.php index a43b48c3ae05c654eab89d3f91775df060c35aaf..d0b32225776cc49d41a4130a9bc54299b08938f9 100644 --- a/lib/SimpleSAML/IdP.php +++ b/lib/SimpleSAML/IdP.php @@ -427,7 +427,7 @@ class SimpleSAML_IdP /** * Find the logout handler of this IdP. * - * @return SimpleSAML_IdP_LogoutHandler The logout handler class. + * @return \SimpleSAML\IdP\LogoutHandlerInterface The logout handler class. * * @throws SimpleSAML_Error_Exception If we cannot find a logout handler. */ @@ -437,10 +437,10 @@ class SimpleSAML_IdP $logouttype = $this->getConfig()->getString('logouttype', 'traditional'); switch ($logouttype) { case 'traditional': - $handler = 'SimpleSAML_IdP_LogoutTraditional'; + $handler = 'SimpleSAML\IdP\TraditionalLogoutHandler'; break; case 'iframe': - $handler = 'SimpleSAML_IdP_LogoutIFrame'; + $handler = 'SimpleSAML\IdP\IFrameLogoutHandler'; break; default: throw new SimpleSAML_Error_Exception('Unknown logout handler: '.var_export($logouttype, true)); diff --git a/lib/SimpleSAML/IdP/LogoutIFrame.php b/lib/SimpleSAML/IdP/IFrameLogoutHandler.php similarity index 64% rename from lib/SimpleSAML/IdP/LogoutIFrame.php rename to lib/SimpleSAML/IdP/IFrameLogoutHandler.php index b4948a0577f61f389979165e7a616216ad3b60e2..e14e86bd3dabfe8ec75775fb8e129492c9f2efa9 100644 --- a/lib/SimpleSAML/IdP/LogoutIFrame.php +++ b/lib/SimpleSAML/IdP/IFrameLogoutHandler.php @@ -1,18 +1,41 @@ <?php +namespace SimpleSAML\IdP; + +use SimpleSAML\Module; +use SimpleSAML\Utils\HTTP; + /** * Class that handles iframe logout. * * @package SimpleSAMLphp */ -class SimpleSAML_IdP_LogoutIFrame extends SimpleSAML_IdP_LogoutHandler +class IFrameLogoutHandler implements LogoutHandlerInterface { + /** + * The IdP we are logging out from. + * + * @var \SimpleSAML_IdP + */ + private $idp; + + + /** + * LogoutIFrame constructor. + * + * @param \SimpleSAML_IdP $idp The IdP to log out from. + */ + public function __construct(\SimpleSAML_IdP $idp) + { + $this->idp = $idp; + } + /** * Start the logout operation. * - * @param array &$state The logout state. + * @param array &$state The logout state. * @param string|null $assocId The SP we are logging out from. */ public function startLogout(array &$state, $assocId) @@ -26,7 +49,7 @@ class SimpleSAML_IdP_LogoutIFrame extends SimpleSAML_IdP_LogoutHandler } foreach ($associations as $id => &$association) { - $idp = SimpleSAML_IdP::getByState($association); + $idp = \SimpleSAML_IdP::getByState($association); $association['core:Logout-IFrame:Name'] = $idp->getSPName($id); $association['core:Logout-IFrame:State'] = 'onhold'; } @@ -44,14 +67,14 @@ class SimpleSAML_IdP_LogoutIFrame extends SimpleSAML_IdP_LogoutHandler } $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']; } - $url = SimpleSAML\Module::getModuleURL('core/idp/logout-iframe.php', $params); - \SimpleSAML\Utils\HTTP::redirectTrustedURL($url); + $url = Module::getModuleURL('core/idp/logout-iframe.php', $params); + HTTP::redirectTrustedURL($url); } @@ -60,11 +83,11 @@ class SimpleSAML_IdP_LogoutIFrame extends SimpleSAML_IdP_LogoutHandler * * This function will never return. * - * @param string $assocId The association that is terminated. - * @param string|NULL $relayState The RelayState from the start of the logout. - * @param SimpleSAML_Error_Exception|null $error The error that occurred during session termination (if any). + * @param string $assocId The association that is terminated. + * @param string|null $relayState The RelayState from the start of the logout. + * @param \SimpleSAML_Error_Exception|null $error The error that occurred during session termination (if any). */ - public function onResponse($assocId, $relayState, SimpleSAML_Error_Exception $error = null) + public function onResponse($assocId, $relayState, \SimpleSAML_Error_Exception $error = null) { assert('is_string($assocId)'); diff --git a/lib/SimpleSAML/IdP/LogoutHandler.php b/lib/SimpleSAML/IdP/LogoutHandler.php deleted file mode 100644 index a5ba9293e8652bf1db0848de1fa739e28512620e..0000000000000000000000000000000000000000 --- a/lib/SimpleSAML/IdP/LogoutHandler.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - - -/** - * Base class for logout handlers. - * - * @package SimpleSAMLphp - */ -abstract class SimpleSAML_IdP_LogoutHandler -{ - - /** - * The IdP we are logging out from. - * - * @var SimpleSAML_IdP - */ - protected $idp; - - - /** - * Initialize this logout handler. - * - * @param SimpleSAML_IdP $idp The IdP we are logging out from. - */ - public function __construct(SimpleSAML_IdP $idp) - { - $this->idp = $idp; - } - - - /** - * Start a logout operation. - * - * This function must never return. - * - * @param array &$state The logout state. - * @param string|null $assocId The association that started the logout. - */ - abstract public function startLogout(array &$state, $assocId); - - - /** - * Handles responses to our logout requests. - * - * This function will never return. - * - * @param string $assocId The association that is terminated. - * @param string|null $relayState The RelayState from the start of the logout. - * @param SimpleSAML_Error_Exception|null $error The error that occurred during session termination (if any). - */ - public function onResponse($assocId, $relayState, SimpleSAML_Error_Exception $error = null) - { - assert('is_string($assocId)'); - assert('is_string($relayState) || is_null($relayState)'); - // don't do anything by default - } -} diff --git a/lib/SimpleSAML/IdP/LogoutHandlerInterface.php b/lib/SimpleSAML/IdP/LogoutHandlerInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..11589f3d0f56478e114f30b6fbac115fc67a13bb --- /dev/null +++ b/lib/SimpleSAML/IdP/LogoutHandlerInterface.php @@ -0,0 +1,44 @@ +<?php + +namespace SimpleSAML\IdP; + + +/** + * Interface that all logout handlers must implement. + * + * @package SimpleSAMLphp + */ +interface LogoutHandlerInterface +{ + + + /** + * Initialize this logout handler. + * + * @param \SimpleSAML_IdP $idp The IdP we are logging out from. + */ + public function __construct(\SimpleSAML_IdP $idp); + + + /** + * Start a logout operation. + * + * This function must never return. + * + * @param array &$state The logout state. + * @param string|null $assocId The association that started the logout. + */ + public function startLogout(array &$state, $assocId); + + + /** + * Handles responses to our logout requests. + * + * This function will never return. + * + * @param string $assocId The association that is terminated. + * @param string|null $relayState The RelayState from the start of the logout. + * @param \SimpleSAML_Error_Exception|null $error The error that occurred during session termination (if any). + */ + public function onResponse($assocId, $relayState, \SimpleSAML_Error_Exception $error = null); +} diff --git a/lib/SimpleSAML/IdP/LogoutTraditional.php b/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php similarity index 54% rename from lib/SimpleSAML/IdP/LogoutTraditional.php rename to lib/SimpleSAML/IdP/TraditionalLogoutHandler.php index ee7a45f2ebdb6024d8f3cd8bd9f5a62621d1d4a4..534b08873447c2d1aaaec7ba571fc5379ca31503 100644 --- a/lib/SimpleSAML/IdP/LogoutTraditional.php +++ b/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php @@ -1,14 +1,38 @@ <?php +namespace SimpleSAML\IdP; + +use SimpleSAML\Logger; +use SimpleSAML\Utils\HTTP; + /** - * Class which handles traditional logout. + * Class that handles traditional logout. * * @package SimpleSAMLphp */ -class SimpleSAML_IdP_LogoutTraditional extends SimpleSAML_IdP_LogoutHandler +class TraditionalLogoutHandler implements LogoutHandlerInterface { + /** + * The IdP we are logging out from. + * + * @var \SimpleSAML_IdP + */ + private $idp; + + + /** + * TraditionalLogout constructor. + * + * @param \SimpleSAML_IdP $idp The IdP to log out from. + */ + public function __construct(\SimpleSAML_IdP $idp) + { + $this->idp = $idp; + } + + /** * Picks the next SP and issues a logout request. * @@ -23,17 +47,17 @@ class SimpleSAML_IdP_LogoutTraditional extends SimpleSAML_IdP_LogoutHandler $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']; - SimpleSAML\Logger::info('Logging out of '.var_export($id, true).'.'); + Logger::info('Logging out of '.var_export($id, true).'.'); try { - $idp = SimpleSAML_IdP::getByState($association); + $idp = \SimpleSAML_IdP::getByState($association); $url = call_user_func(array($association['Handler'], 'getLogoutURL'), $idp, $association, $relayState); - \SimpleSAML\Utils\HTTP::redirectTrustedURL($url); - } catch (Exception $e) { - SimpleSAML\Logger::warning('Unable to initialize logout to '.var_export($id, true).'.'); + HTTP::redirectTrustedURL($url); + } catch (\Exception $e) { + Logger::warning('Unable to initialize logout to '.var_export($id, true).'.'); $this->idp->terminateAssociation($id); $state['core:Failed'] = true; @@ -67,26 +91,26 @@ class SimpleSAML_IdP_LogoutTraditional extends SimpleSAML_IdP_LogoutHandler * * @param string $assocId The association that is terminated. * @param string|null $relayState The RelayState from the start of the logout. - * @param SimpleSAML_Error_Exception|null $error The error that occurred during session termination (if any). + * @param \SimpleSAML_Error_Exception|null $error The error that occurred during session termination (if any). * - * @throws SimpleSAML_Error_Exception If the RelayState was lost during logout. + * @throws \SimpleSAML_Error_Exception If the RelayState was lost during logout. */ - public function onResponse($assocId, $relayState, SimpleSAML_Error_Exception $error = null) + public function onResponse($assocId, $relayState, \SimpleSAML_Error_Exception $error = null) { assert('is_string($assocId)'); assert('is_string($relayState) || is_null($relayState)'); if ($relayState === null) { - throw new SimpleSAML_Error_Exception('RelayState lost during logout.'); + 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) { - SimpleSAML\Logger::info('Logged out of '.var_export($assocId, true).'.'); + Logger::info('Logged out of '.var_export($assocId, true).'.'); $this->idp->terminateAssociation($assocId); } else { - SimpleSAML\Logger::warning('Error received from '.var_export($assocId, true).' during logout:'); + Logger::warning('Error received from '.var_export($assocId, true).' during logout:'); $error->logWarning(); $state['core:Failed'] = true; } diff --git a/lib/_autoload_modules.php b/lib/_autoload_modules.php index c0d8befa500a2e2ca5b7255e7b9e109889cd0578..5eb8d2fdb86ee2722144c26cc32d3abe29478e6d 100644 --- a/lib/_autoload_modules.php +++ b/lib/_autoload_modules.php @@ -31,6 +31,9 @@ function temporaryLoader($class) 'SimpleSAML_Logger_LoggingHandlerErrorLog' => 'SimpleSAML_Logger_ErrorLogLoggingHandler', 'SimpleSAML_Logger_LoggingHandlerFile' => 'SimpleSAML_Logger_FileLoggingHandler', 'SimpleSAML_Logger_LoggingHandler' => 'SimpleSAML_Logger_LoggingHandlerInterface', + 'SimpleSAML_IdP_LogoutHandler' => 'SimpleSAML_IdP_LogoutHandlerInterface', + 'SimpleSAML_IdP_LogoutIFrame' => 'SimpleSAML_IdP_IFrameLogoutHandler', + 'SimpleSAML_IdP_LogoutTraditional' => 'SimpleSAML_IdP_TraditionalLogoutHandler', ); if (array_key_exists($class, $renamed)) { // the class has been renamed, try to load it and create an alias