diff --git a/lib/SimpleSAML/Stats.php b/lib/SimpleSAML/Stats.php index 3cd010f2ef18e47436ecd38ab45c07d2a23a3f0e..9329310b8f1f58c9e1430773712e5a8087e9b719 100644 --- a/lib/SimpleSAML/Stats.php +++ b/lib/SimpleSAML/Stats.php @@ -1,5 +1,6 @@ <?php +namespace SimpleSAML; /** * Statistics handler class. @@ -8,9 +9,9 @@ * * @package SimpleSAMLphp */ -class SimpleSAML_Stats -{ +class Stats +{ /** * Whether this class is initialized. * @@ -37,7 +38,7 @@ class SimpleSAML_Stats private static function createOutput(\SimpleSAML\Configuration $config) { $cls = $config->getString('class'); - $cls = SimpleSAML\Module::resolveClass($cls, 'Stats_Output', 'SimpleSAML_Stats_Output'); + $cls = SimpleSAML\Module::resolveClass($cls, 'Stats\Output', '\SimpleSAML\Stats\Output'); $output = new $cls($config); return $output; diff --git a/lib/SimpleSAML/Stats/Output.php b/lib/SimpleSAML/Stats/Output.php index fe803e9bf6669fb3ced32c3f3991d8d4c4e366e5..a4a05ed44b0f318d9ec339fc9ac1d6687b10b160 100644 --- a/lib/SimpleSAML/Stats/Output.php +++ b/lib/SimpleSAML/Stats/Output.php @@ -1,14 +1,15 @@ <?php +namespace SimpleSAML\Stats; /** * Interface for statistics outputs. * * @package SimpleSAMLphp */ -abstract class SimpleSAML_Stats_Output -{ +abstract class Output +{ /** * Initialize the output. * diff --git a/modules/consent/lib/Auth/Process/Consent.php b/modules/consent/lib/Auth/Process/Consent.php index 9b0fdd11077fcb0f327472b5e49808f308fada73..342e110f264ad38eef282bc04f46dc5a57de1b56 100644 --- a/modules/consent/lib/Auth/Process/Consent.php +++ b/modules/consent/lib/Auth/Process/Consent.php @@ -1,6 +1,5 @@ <?php - /** * Consent Authentication Processing filter * @@ -9,6 +8,11 @@ * * @package SimpleSAMLphp */ + +use SimpleSAML\Logger; +use SimpleSAML\Stats; +use SimpleSAML\Error; + class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFilter { /** @@ -69,7 +73,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil * @param array $config Configuration information. * @param mixed $reserved For future use. * - * @throws \SimpleSAML\Error\Exception if the configuration is not valid. + * @throws Error\Exception if the configuration is not valid. */ public function __construct($config, $reserved) { @@ -78,7 +82,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil if (array_key_exists('includeValues', $config)) { if (!is_bool($config['includeValues'])) { - throw new \SimpleSAML\Error\Exception( + throw new Error\Exception( 'Consent: includeValues must be boolean. '. var_export($config['includeValues'], true).' given.' ); @@ -88,7 +92,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil if (array_key_exists('checked', $config)) { if (!is_bool($config['checked'])) { - throw new \SimpleSAML\Error\Exception( + throw new Error\Exception( 'Consent: checked must be boolean. '. var_export($config['checked'], true).' given.' ); @@ -98,7 +102,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil if (array_key_exists('focus', $config)) { if (!in_array($config['focus'], array('yes', 'no'), true)) { - throw new \SimpleSAML\Error\Exception( + throw new Error\Exception( 'Consent: focus must be a string with values `yes` or `no`. '. var_export($config['focus'], true).' given.' ); @@ -108,7 +112,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil if (array_key_exists('hiddenAttributes', $config)) { if (!is_array($config['hiddenAttributes'])) { - throw new \SimpleSAML\Error\Exception( + throw new Error\Exception( 'Consent: hiddenAttributes must be an array. '. var_export($config['hiddenAttributes'], true).' given.' ); @@ -118,16 +122,16 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil if (array_key_exists('attributes.exclude', $config)) { if (!is_array($config['attributes.exclude'])) { - throw new \SimpleSAML\Error\Exception( + throw new Error\Exception( 'Consent: attributes.exclude must be an array. '. var_export($config['attributes.exclude'], true).' given.' ); } $this->_noconsentattributes = $config['attributes.exclude']; } elseif (array_key_exists('noconsentattributes', $config)) { - SimpleSAML\Logger::warning("The 'noconsentattributes' option has been deprecated in favour of 'attributes.exclude'."); + Logger::warning("The 'noconsentattributes' option has been deprecated in favour of 'attributes.exclude'."); if (!is_array($config['noconsentattributes'])) { - throw new \SimpleSAML\Error\Exception( + throw new Error\Exception( 'Consent: noconsentattributes must be an array. '. var_export($config['noconsentattributes'], true).' given.' ); @@ -138,8 +142,8 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil if (array_key_exists('store', $config)) { try { $this->_store = sspmod_consent_Store::parseStoreConfig($config['store']); - } catch (Exception $e) { - SimpleSAML\Logger::error( + } catch (\Exception $e) { + Logger::error( 'Consent: Could not create consent storage: '. $e->getMessage() ); @@ -148,7 +152,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil if (array_key_exists('showNoConsentAboutService', $config)) { if (!is_bool($config['showNoConsentAboutService'])) { - throw new \SimpleSAML\Error\Exception('Consent: showNoConsentAboutService must be a boolean.'); + throw new Error\Exception('Consent: showNoConsentAboutService must be a boolean.'); } $this->_showNoConsentAboutService = $config['showNoConsentAboutService']; } @@ -222,7 +226,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil * * @return void * - * @throws \SimpleSAML\Error\NoPassive if the request was passive and consent is needed. + * @throws Error\NoPassive if the request was passive and consent is needed. */ public function process(&$state) { @@ -257,15 +261,15 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil if (isset($state['Source']['consent.disable']) && self::checkDisable($state['Source']['consent.disable'], $spEntityId) ) { - SimpleSAML\Logger::debug('Consent: Consent disabled for entity '.$spEntityId.' with IdP '.$idpEntityId); - SimpleSAML_Stats::log('consent:disabled', $statsData); + Logger::debug('Consent: Consent disabled for entity '.$spEntityId.' with IdP '.$idpEntityId); + Stats::log('consent:disabled', $statsData); return; } if (isset($state['Destination']['consent.disable']) && self::checkDisable($state['Destination']['consent.disable'], $idpEntityId) ) { - SimpleSAML\Logger::debug('Consent: Consent disabled for entity '.$spEntityId.' with IdP '.$idpEntityId); - SimpleSAML_Stats::log('consent:disabled', $statsData); + Logger::debug('Consent: Consent disabled for entity '.$spEntityId.' with IdP '.$idpEntityId); + Stats::log('consent:disabled', $statsData); return; } @@ -281,15 +285,15 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil } } - SimpleSAML\Logger::debug('Consent: userid: '.$state['UserID']); - SimpleSAML\Logger::debug('Consent: source: '.$source); - SimpleSAML\Logger::debug('Consent: destination: '.$destination); + Logger::debug('Consent: userid: '.$state['UserID']); + Logger::debug('Consent: source: '.$source); + Logger::debug('Consent: destination: '.$destination); $userId = self::getHashedUserID($state['UserID'], $source); $targetedId = self::getTargetedID($state['UserID'], $source, $destination); $attributeSet = self::getAttributeHash($attributes, $this->_includeValues); - SimpleSAML\Logger::debug( + Logger::debug( 'Consent: hasConsent() ['.$userId.'|'.$targetedId.'|'. $attributeSet.']' ); @@ -297,26 +301,26 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil try { if ($this->_store->hasConsent($userId, $targetedId, $attributeSet)) { // Consent already given - SimpleSAML\Logger::stats('consent found'); - SimpleSAML_Stats::log('consent:found', $statsData); + Logger::stats('consent found'); + Stats::log('consent:found', $statsData); return; } - SimpleSAML\Logger::stats('consent notfound'); - SimpleSAML_Stats::log('consent:notfound', $statsData); + Logger::stats('consent notfound'); + Stats::log('consent:notfound', $statsData); $state['consent:store'] = $this->_store; $state['consent:store.userId'] = $userId; $state['consent:store.destination'] = $targetedId; $state['consent:store.attributeSet'] = $attributeSet; } catch (Exception $e) { - SimpleSAML\Logger::error('Consent: Error reading from storage: '.$e->getMessage()); - SimpleSAML\Logger::stats('Ccnsent failed'); - SimpleSAML_Stats::log('consent:failed', $statsData); + Logger::error('Consent: Error reading from storage: '.$e->getMessage()); + Logger::stats('Ccnsent failed'); + Stats::log('consent:failed', $statsData); } } else { - SimpleSAML\Logger::stats('consent nostorage'); - SimpleSAML_Stats::log('consent:nostorage', $statsData); + Logger::stats('consent nostorage'); + Stats::log('consent:nostorage', $statsData); } $state['consent:focus'] = $this->_focus; @@ -327,17 +331,17 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil // user interaction necessary. Throw exception on isPassive request if (isset($state['isPassive']) && $state['isPassive'] === true) { - SimpleSAML_Stats::log('consent:nopassive', $statsData); - throw new SimpleSAML\Module\saml\Error\NoPassive( + Stats::log('consent:nopassive', $statsData); + throw new Module\saml\Error\NoPassive( \SAML2\Constants::STATUS_REQUESTER, 'Unable to give consent on passive request.' ); } // Save state and redirect - $id = \SimpleSAML\Auth\State::saveState($state, 'consent:request'); - $url = SimpleSAML\Module::getModuleURL('consent/getconsent.php'); - \SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id)); + $id = Auth\State::saveState($state, 'consent:request'); + $url = Module::getModuleURL('consent/getconsent.php'); + Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id)); } @@ -351,7 +355,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil */ public static function getHashedUserID($userid, $source) { - return hash('sha1', $userid.'|'.SimpleSAML\Utils\Config::getSecretSalt().'|'.$source); + return hash('sha1', $userid.'|'.Utils\Config::getSecretSalt().'|'.$source); } @@ -366,7 +370,7 @@ class sspmod_consent_Auth_Process_Consent extends \SimpleSAML\Auth\ProcessingFil */ public static function getTargetedID($userid, $source, $destination) { - return hash('sha1', $userid.'|'.SimpleSAML\Utils\Config::getSecretSalt().'|'.$source.'|'.$destination); + return hash('sha1', $userid.'|'.Utils\Config::getSecretSalt().'|'.$source.'|'.$destination); } diff --git a/modules/consent/www/getconsent.php b/modules/consent/www/getconsent.php index 9265b071b813bf5eca420170fd44dc207ae60d0c..37a76f34609f842736b9728c184a9070f107709c 100644 --- a/modules/consent/www/getconsent.php +++ b/modules/consent/www/getconsent.php @@ -55,7 +55,7 @@ if (array_key_exists('yes', $_REQUEST)) { if (isset($state['Destination']['entityid'])) { $statsInfo['spEntityID'] = $state['Destination']['entityid']; } - \SimpleSAML_Stats::log('consent:accept', $statsInfo); + \SimpleSAML\Stats::log('consent:accept', $statsInfo); if ( array_key_exists('consent:store', $state) && array_key_exists('saveconsent', $_REQUEST) diff --git a/modules/consent/www/noconsent.php b/modules/consent/www/noconsent.php index dcf09d60ea2bcde65bac63159fe6ce61f9d21d0f..bccaead3b4b14054b6197f6466c427773a2b5d7f 100644 --- a/modules/consent/www/noconsent.php +++ b/modules/consent/www/noconsent.php @@ -37,7 +37,7 @@ $statsInfo = array(); if (isset($state['Destination']['entityid'])) { $statsInfo['spEntityID'] = $state['Destination']['entityid']; } -\SimpleSAML_Stats::log('consent:reject', $statsInfo); +\SimpleSAML\Stats::log('consent:reject', $statsInfo); $globalConfig = \SimpleSAML\Configuration::getInstance(); diff --git a/modules/core/lib/Stats/Output/File.php b/modules/core/lib/Stats/Output/File.php index f67fd5358f1d71c433b32a6decd073689906427e..d2cd70520d65644ade40e4627166f55012f8c2fc 100644 --- a/modules/core/lib/Stats/Output/File.php +++ b/modules/core/lib/Stats/Output/File.php @@ -5,8 +5,9 @@ * * @package SimpleSAMLphp */ -class sspmod_core_Stats_Output_File extends SimpleSAML_Stats_Output { +class sspmod_core_Stats_Output_File extends \SimpleSAML\Stats\Output +{ /** * The log directory. * @var string diff --git a/modules/core/lib/Stats/Output/Log.php b/modules/core/lib/Stats/Output/Log.php index ec26f7b4cd9d1fe88146e24c0ae71f6e3c260ea7..05575058a61536498538a53e41fce656f3a03f8e 100644 --- a/modules/core/lib/Stats/Output/Log.php +++ b/modules/core/lib/Stats/Output/Log.php @@ -5,8 +5,9 @@ * * @package SimpleSAMLphp */ -class sspmod_core_Stats_Output_Log extends SimpleSAML_Stats_Output { +class sspmod_core_Stats_Output_Log extends \SimpleSAML\Stats\Output +{ /** * The logging function we should call. * @var callback @@ -21,9 +22,9 @@ class sspmod_core_Stats_Output_Log extends SimpleSAML_Stats_Output { */ public function __construct(\SimpleSAML\Configuration $config) { $logLevel = $config->getString('level', 'notice'); - $this->logger = array('SimpleSAML\Logger', $logLevel); + $this->logger = array('\SimpleSAML\Logger', $logLevel); if (!is_callable($this->logger)) { - throw new Exception('Invalid log level: ' . var_export($logLevel, TRUE)); + throw new \Exception('Invalid log level: ' . var_export($logLevel, TRUE)); } } @@ -37,5 +38,4 @@ class sspmod_core_Stats_Output_Log extends SimpleSAML_Stats_Output { $str_data = json_encode($data); call_user_func($this->logger, 'EVENT ' . $str_data); } - } diff --git a/modules/core/www/idp/logout-iframe-done.php b/modules/core/www/idp/logout-iframe-done.php index d338b1811b7760b779ac780181f5e9b10b7418b2..a01665a646fe8b83f3185aceaac5654454031c91 100644 --- a/modules/core/www/idp/logout-iframe-done.php +++ b/modules/core/www/idp/logout-iframe-done.php @@ -9,13 +9,13 @@ $idp = \SimpleSAML\IdP::getByState($state); $associations = $idp->getAssociations(); if (!isset($_REQUEST['cancel'])) { - SimpleSAML\Logger::stats('slo-iframe done'); - SimpleSAML_Stats::log('core:idp:logout-iframe:page', array('type' => 'done')); + \SimpleSAML\Logger::stats('slo-iframe done'); + \SimpleSAML\Stats::log('core:idp:logout-iframe:page', array('type' => 'done')); $SPs = $state['core:Logout-IFrame:Associations']; } else { // user skipped global logout - SimpleSAML\Logger::stats('slo-iframe skip'); - SimpleSAML_Stats::log('core:idp:logout-iframe:page', array('type' => 'skip')); + \SimpleSAML\Logger::stats('slo-iframe skip'); + \SimpleSAML\Stats::log('core:idp:logout-iframe:page', array('type' => 'skip')); $SPs = array(); // no SPs should have been logged out $state['core:Failed'] = true; // mark as partial logout } @@ -42,14 +42,14 @@ foreach ($SPs as $assocId => $sp) { if ($sp['core:Logout-IFrame:State'] === 'completed') { $idp->terminateAssociation($assocId); } else { - SimpleSAML\Logger::warning('Unable to terminate association with '.var_export($assocId, true).'.'); + \SimpleSAML\Logger::warning('Unable to terminate association with '.var_export($assocId, true).'.'); if (isset($sp['saml:entityID'])) { $spId = $sp['saml:entityID']; } else { $spId = $assocId; } - SimpleSAML\Logger::stats('slo-iframe-fail '.$spId); - SimpleSAML_Stats::log('core:idp:logout-iframe:spfail', array('sp' => $spId)); + \SimpleSAML\Logger::stats('slo-iframe-fail '.$spId); + \SimpleSAML\Stats::log('core:idp:logout-iframe:spfail', array('sp' => $spId)); $state['core:Failed'] = true; } } diff --git a/modules/core/www/idp/logout-iframe-post.php b/modules/core/www/idp/logout-iframe-post.php index aeb6554c24081bb9aac1b7133d104c939cbaea60..b1e937c009e34c906daa8da98804170b9792f991 100644 --- a/modules/core/www/idp/logout-iframe-post.php +++ b/modules/core/www/idp/logout-iframe-post.php @@ -44,7 +44,7 @@ if ($encryptNameId) { $lr->encryptNameId(sspmod_saml_Message::getEncryptionKey($spMetadata)); } -SimpleSAML_Stats::log('saml:idp:LogoutRequest:sent', array( +\SimpleSAML\Stats::log('saml:idp:LogoutRequest:sent', array( 'spEntityID' => $association['saml:entityID'], 'idpEntityID' => $idpMetadata->getString('entityid'), )); diff --git a/modules/core/www/idp/logout-iframe.php b/modules/core/www/idp/logout-iframe.php index 8cc07f13df3c07803eb505e2f5100534498ff9cd..298ffb053be2120cb134bd7d155fc7c8339bae77 100644 --- a/modules/core/www/idp/logout-iframe.php +++ b/modules/core/www/idp/logout-iframe.php @@ -15,7 +15,7 @@ if (isset($_REQUEST['type'])) { if ($type !== 'embed') { \SimpleSAML\Logger::stats('slo-iframe '.$type); - \SimpleSAML_Stats::log('core:idp:logout-iframe:page', array('type' => $type)); + \SimpleSAML\Stats::log('core:idp:logout-iframe:page', array('type' => $type)); } $state = \SimpleSAML\Auth\State::loadState($_REQUEST['id'], 'core:Logout-IFrame'); diff --git a/modules/saml/lib/IdP/SAML1.php b/modules/saml/lib/IdP/SAML1.php index f7ee616a668cb33b9e78c1f846f223288cae1c61..f306a951f067c6deb9f7a4ccb374de3ef9457e64 100644 --- a/modules/saml/lib/IdP/SAML1.php +++ b/modules/saml/lib/IdP/SAML1.php @@ -49,7 +49,7 @@ class sspmod_saml_IdP_SAML1 if (isset($state['saml:AuthnRequestReceivedAt'])) { $statsData['logintime'] = microtime(true) - $state['saml:AuthnRequestReceivedAt']; } - SimpleSAML_Stats::log('saml:idp:Response', $statsData); + \SimpleSAML\Stats::log('saml:idp:Response', $statsData); // Generate and send response. $ar = new \SimpleSAML\XML\Shib13\AuthnResponse(); @@ -115,7 +115,7 @@ class sspmod_saml_IdP_SAML1 var_export($spEntityId, true) . ': ' . var_export($shire, true)); } - SimpleSAML_Stats::log('saml:idp:AuthnRequest', array( + \SimpleSAML\Stats::log('saml:idp:AuthnRequest', array( 'spEntityID' => $spEntityId, 'protocol' => 'saml1', )); diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php index 1ee1d6e6778533ee650f81478432483ab05b1a00..b5df095ed7a019e276be88b25fa70e19aa52fa8a 100644 --- a/modules/saml/lib/IdP/SAML2.php +++ b/modules/saml/lib/IdP/SAML2.php @@ -79,7 +79,7 @@ class sspmod_saml_IdP_SAML2 if (isset($state['saml:AuthnRequestReceivedAt'])) { $statsData['logintime'] = microtime(true) - $state['saml:AuthnRequestReceivedAt']; } - \SimpleSAML_Stats::log('saml:idp:Response', $statsData); + \SimpleSAML\Stats::log('saml:idp:Response', $statsData); // send the response $binding = \SAML2\Binding::getBinding($protocolBinding); @@ -142,7 +142,7 @@ class sspmod_saml_IdP_SAML2 if (isset($state['saml:AuthnRequestReceivedAt'])) { $statsData['logintime'] = microtime(true) - $state['saml:AuthnRequestReceivedAt']; } - \SimpleSAML_Stats::log('saml:idp:Response:error', $statsData); + \SimpleSAML\Stats::log('saml:idp:Response:error', $statsData); $binding = \SAML2\Binding::getBinding($protocolBinding); $binding->send($ar); @@ -371,7 +371,7 @@ class sspmod_saml_IdP_SAML2 ); } - SimpleSAML_Stats::log('saml:idp:AuthnRequest', array( + \SimpleSAML\Stats::log('saml:idp:AuthnRequest', array( 'spEntityID' => $spEntityId, 'idpEntityID' => $idpMetadata->getString('entityid'), 'forceAuthn' => $forceAuthn, @@ -469,7 +469,7 @@ class sspmod_saml_IdP_SAML2 $idpMetadata = $idp->getConfig(); $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote'); - SimpleSAML_Stats::log('saml:idp:LogoutRequest:sent', array( + \SimpleSAML\Stats::log('saml:idp:LogoutRequest:sent', array( 'spEntityID' => $association['saml:entityID'], 'idpEntityID' => $idpMetadata->getString('entityid'), )); @@ -523,7 +523,7 @@ class sspmod_saml_IdP_SAML2 Logger::debug('Sending logout response to SP '.var_export($spEntityId, true)); } - SimpleSAML_Stats::log('saml:idp:LogoutResponse:sent', array( + \SimpleSAML\Stats::log('saml:idp:LogoutResponse:sent', array( 'spEntityID' => $spEntityId, 'idpEntityID' => $idpMetadata->getString('entityid'), 'partial' => $partial @@ -579,7 +579,7 @@ class sspmod_saml_IdP_SAML2 if (!$message->isSuccess()) { $statsData['error'] = $message->getStatus(); } - SimpleSAML_Stats::log('saml:idp:LogoutResponse:recv', $statsData); + \SimpleSAML\Stats::log('saml:idp:LogoutResponse:recv', $statsData); $relayState = $message->getRelayState(); @@ -595,7 +595,7 @@ class sspmod_saml_IdP_SAML2 $idp->handleLogoutResponse($assocId, $relayState, $logoutError); } elseif ($message instanceof \SAML2\LogoutRequest) { Logger::info('Received SAML 2.0 LogoutRequest from: '.var_export($spEntityId, true)); - SimpleSAML_Stats::log('saml:idp:LogoutRequest:recv', array( + \SimpleSAML\Stats::log('saml:idp:LogoutRequest:recv', array( 'spEntityID' => $spEntityId, 'idpEntityID' => $idpMetadata->getString('entityid'), ));