From 4b77d2c6f231a399b063b6b22c834739bd50b901 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Tue, 21 Apr 2015 12:09:28 +0200 Subject: [PATCH] Move SimpleSAML_Utilities:::getBaseURL() to SimpleSAML\Utils\HTTP::getBaseURL() and deprecate the former. --- lib/SimpleSAML/Error/Error.php | 2 +- .../MetaDataStorageHandlerFlatFile.php | 2 +- lib/SimpleSAML/Module.php | 2 +- lib/SimpleSAML/Utilities.php | 40 +----------------- lib/SimpleSAML/Utils/HTTP.php | 41 +++++++++++++++++++ modules/adfs/lib/IdP/ADFS.php | 2 +- modules/core/www/frontpage_config.php | 4 +- modules/core/www/frontpage_federation.php | 2 +- www/admin/hostnames.php | 2 +- www/saml2/idp/metadata.php | 4 +- 10 files changed, 53 insertions(+), 48 deletions(-) diff --git a/lib/SimpleSAML/Error/Error.php b/lib/SimpleSAML/Error/Error.php index a422e624e..2c035bc74 100644 --- a/lib/SimpleSAML/Error/Error.php +++ b/lib/SimpleSAML/Error/Error.php @@ -265,7 +265,7 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { if($config->getBoolean('errorreporting', TRUE) && $config->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org') { /* Enable error reporting. */ - $baseurl = SimpleSAML_Utilities::getBaseURL(); + $baseurl = \SimpleSAML\Utils\HTTP::getBaseURL(); $data['errorReportAddress'] = $baseurl . 'errorreport.php'; } diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php index 22688c297..b028bb4f8 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php @@ -116,7 +116,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerFlatFile extends SimpleSAML_Meta private function generateDynamicHostedEntityID($set) { /* Get the configuration. */ - $baseurl = SimpleSAML_Utilities::getBaseURL(); + $baseurl = \SimpleSAML\Utils\HTTP::getBaseURL(); if ($set === 'saml20-idp-hosted') { return $baseurl . 'saml2/idp/metadata.php'; diff --git a/lib/SimpleSAML/Module.php b/lib/SimpleSAML/Module.php index 829fa7b11..45b1ae6f5 100644 --- a/lib/SimpleSAML/Module.php +++ b/lib/SimpleSAML/Module.php @@ -155,7 +155,7 @@ class SimpleSAML_Module { assert('is_string($resource)'); assert('$resource[0] !== "/"'); - $url = SimpleSAML_Utilities::getBaseURL() . 'module.php/' . $resource; + $url = \SimpleSAML\Utils\HTTP::getBaseURL() . 'module.php/' . $resource; if (!empty($parameters)) { $url = \SimpleSAML\Utils\HTTP::addURLParameters($url, $parameters); } diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 81d8a28e8..b592539d6 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -208,46 +208,10 @@ class SimpleSAML_Utilities { /** - * Retrieve and return the absolute base URL for the simpleSAMLphp installation. - * - * For example: https://idp.example.org/simplesaml/ - * - * The URL will always end with a '/'. - * - * @return string The absolute base URL for the simpleSAMLphp installation. + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getBaseURL() instead. */ public static function getBaseURL() { - - $globalConfig = SimpleSAML_Configuration::getInstance(); - $baseURL = $globalConfig->getString('baseurlpath', 'simplesaml/'); - - if (preg_match('#^https?://.*/$#D', $baseURL, $matches)) { - /* full URL in baseurlpath, override local server values */ - return $baseURL; - } elseif ( - (preg_match('#^/?([^/]?.*/)$#D', $baseURL, $matches)) || - (preg_match('#^\*(.*)/$#D', $baseURL, $matches)) || - ($baseURL === '')) { - /* get server values */ - - if (self::getServerHTTPS()) { - $protocol = 'https://'; - } else { - $protocol = 'http://'; - } - - $hostname = self::getServerHost(); - $port = self::getServerPort(); - $path = '/' . $globalConfig->getBaseURL(); - - return $protocol.$hostname.$port.$path; - } else { - throw new SimpleSAML_Error_Exception('Invalid value of \'baseurl\' in '. - 'config.php. Valid format is in the form: '. - '[(http|https)://(hostname|fqdn)[:port]]/[path/to/simplesaml/]. '. - 'It must end with a \'/\'.'); - } - + return \SimpleSAML\Utils\HTTP::getBaseURL(); } diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index 5c504277c..96577ff30 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -207,6 +207,47 @@ class HTTP } + /** + * Retrieve the base URL of the SimpleSAMLphp installation. The URL will always end with a '/'. For example: + * https://idp.example.org/simplesaml/ + * + * @return string The absolute base URL for the simpleSAMLphp installation. + * @throws \SimpleSAML_Error_Exception If 'baseurlpath' has an invalid format. + * + * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> + */ + public static function getBaseURL() + { + $globalConfig = \SimpleSAML_Configuration::getInstance(); + $baseURL = $globalConfig->getString('baseurlpath', 'simplesaml/'); + + if (preg_match('#^https?://.*/$#D', $baseURL, $matches)) { + // full URL in baseurlpath, override local server values + return $baseURL; + } elseif ( + (preg_match('#^/?([^/]?.*/)$#D', $baseURL, $matches)) || + (preg_match('#^\*(.*)/$#D', $baseURL, $matches)) || + ($baseURL === '') + ) { + // get server values + $protocol = 'http'; + $protocol .= (self::getServerHTTPS()) ? 's' : ''; + $protocol .= '://'; + + $hostname = self::getServerHost(); + $port = self::getServerPort(); + $path = '/'.$globalConfig->getBaseURL(); + + return $protocol.$hostname.$port.$path; + } else { + throw new \SimpleSAML_Error_Exception('Invalid value for \'baseurlpath\' in '. + 'config.php. Valid format is in the form: '. + '[(http|https)://(hostname|fqdn)[:port]]/[path/to/simplesaml/]. '. + 'It must end with a \'/\'.'); + } + } + + /** * Parse a query string into an array. * diff --git a/modules/adfs/lib/IdP/ADFS.php b/modules/adfs/lib/IdP/ADFS.php index a96e005ee..610f84baf 100644 --- a/modules/adfs/lib/IdP/ADFS.php +++ b/modules/adfs/lib/IdP/ADFS.php @@ -168,7 +168,7 @@ class sspmod_adfs_IdP_ADFS { // NB:: we don't know from which SP the logout request came from $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler(); $idpMetadata = $idp->getConfig(); - SimpleSAML_Utilities::redirectTrustedURL($idpMetadata->getValue('redirect-after-logout', SimpleSAML_Utilities::getBaseURL())); + SimpleSAML_Utilities::redirectTrustedURL($idpMetadata->getValue('redirect-after-logout', \SimpleSAML\Utils\HTTP::getBaseURL())); } public static function receiveLogoutMessage(SimpleSAML_IdP $idp) { diff --git a/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php index 7e4cc4fe9..e97eb4bb3 100644 --- a/modules/core/www/frontpage_config.php +++ b/modules/core/www/frontpage_config.php @@ -44,12 +44,12 @@ $links_federation = array(); $links_config[] = array( - 'href' => SimpleSAML_Utilities::getBaseURL() . 'admin/hostnames.php', + 'href' => \SimpleSAML\Utils\HTTP::getBaseURL() . 'admin/hostnames.php', 'text' => '{core:frontpage:link_diagnostics}' ); $links_config[] = array( - 'href' => SimpleSAML_Utilities::getBaseURL() . 'admin/phpinfo.php', + 'href' => \SimpleSAML\Utils\HTTP::getBaseURL() . 'admin/phpinfo.php', 'text' => '{core:frontpage:link_phpinfo}' ); diff --git a/modules/core/www/frontpage_federation.php b/modules/core/www/frontpage_federation.php index 5e32a10bd..aab31a56d 100644 --- a/modules/core/www/frontpage_federation.php +++ b/modules/core/www/frontpage_federation.php @@ -37,7 +37,7 @@ if($config->getBoolean('idpdisco.enableremember', FALSE)) { $links_federation[] = array( - 'href' => SimpleSAML_Utilities::getBaseURL() . 'admin/metadata-converter.php', + 'href' => \SimpleSAML\Utils\HTTP::getBaseURL() . 'admin/metadata-converter.php', 'text' => '{core:frontpage:link_xmlconvert}', ); diff --git a/www/admin/hostnames.php b/www/admin/hostnames.php index 93b6180b8..0a520a93a 100644 --- a/www/admin/hostnames.php +++ b/www/admin/hostnames.php @@ -16,7 +16,7 @@ $attributes['HTTPS'] = array($_SERVER['HTTPS']); $attributes['SERVER_PROTOCOL'] = array($_SERVER['SERVER_PROTOCOL']); $attributes['SERVER_PORT'] = array($_SERVER['SERVER_PORT']); -$attributes['Utilities_getBaseURL()'] = array(SimpleSAML_Utilities::getBaseURL()); +$attributes['Utilities_getBaseURL()'] = array(\SimpleSAML\Utils\HTTP::getBaseURL()); $attributes['Utilities_getSelfHost()'] = array(SimpleSAML_Utilities::getSelfHost()); $attributes['Utilities_selfURLhost()'] = array(SimpleSAML_Utilities::selfURLhost()); $attributes['Utilities_selfURLNoQuery()'] = array(SimpleSAML_Utilities::selfURLNoQuery()); diff --git a/www/saml2/idp/metadata.php b/www/saml2/idp/metadata.php index 67d56ca45..6f7377cfe 100644 --- a/www/saml2/idp/metadata.php +++ b/www/saml2/idp/metadata.php @@ -105,7 +105,7 @@ try { /* Artifact sending enabled. */ $metaArray['ArtifactResolutionService'][] = array( 'index' => 0, - 'Location' => SimpleSAML_Utilities::getBaseURL() . 'saml2/idp/ArtifactResolutionService.php', + 'Location' => \SimpleSAML\Utils\HTTP::getBaseURL() . 'saml2/idp/ArtifactResolutionService.php', 'Binding' => SAML2_Const::BINDING_SOAP, ); } @@ -115,7 +115,7 @@ try { array_unshift($metaArray['SingleSignOnService'], array( 'hoksso:ProtocolBinding' => SAML2_Const::BINDING_HTTP_REDIRECT, 'Binding' => SAML2_Const::BINDING_HOK_SSO, - 'Location' => SimpleSAML_Utilities::getBaseURL() . 'saml2/idp/SSOService.php')); + 'Location' => \SimpleSAML\Utils\HTTP::getBaseURL() . 'saml2/idp/SSOService.php')); } $metaArray['NameIDFormat'] = $idpmeta->getString('NameIDFormat', 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'); -- GitLab