From 8368e5edbb135d2dd88eb75a1dd2d7d5bf67a513 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Tue, 21 Apr 2015 13:22:22 +0200 Subject: [PATCH] Move SimpleSAML_Utilities::selfURLhost() to SimpleSAML\Utils\HTTP::getSelfURLHost() and deprecate the former. --- .../Metadata/MetaDataStorageHandler.php | 2 +- lib/SimpleSAML/Utilities.php | 10 ++-------- lib/SimpleSAML/Utils/HTTP.php | 17 +++++++++++++++++ www/admin/hostnames.php | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php index 48c3e0470..aa9341608 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php @@ -89,7 +89,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler { $config = SimpleSAML_Configuration::getInstance(); assert($config instanceof SimpleSAML_Configuration); - $baseurl = SimpleSAML_Utilities::selfURLhost() . '/' . + $baseurl = \SimpleSAML\Utils\HTTP::getSelfURLHost() . '/' . $config->getBaseURL(); if ($set == 'saml20-sp-hosted') { diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index df9e6c163..b6aaa95e4 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -37,16 +37,10 @@ class SimpleSAML_Utilities { /** - * Will return https://sp.example.org[:PORT] + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURLHost() instead. */ public static function selfURLhost() { - - $url = self::getBaseURL(); - - $start = strpos($url,'://') + 3; - $length = strcspn($url,'/',$start) + $start; - - return substr($url, 0, $length); + return \SimpleSAML\Utils\HTTP::getSelfURLHost(); } diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index 1a170fccf..1d6828535 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -371,6 +371,23 @@ class HTTP } + /** + * Retrieve a URL containing the protocol, the current host and optionally, the port number. + * + * @return string The current URL without a URL path or query parameters. + * + * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no> + * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> + */ + public static function getSelfURLHost() + { + $url = self::getBaseURL(); + $start = strpos($url, '://') + 3; + $length = strcspn($url, '/', $start) + $start; + return substr($url, 0, $length); + } + + /** * Parse a query string into an array. * diff --git a/www/admin/hostnames.php b/www/admin/hostnames.php index 6839055cc..f8ef96dbd 100644 --- a/www/admin/hostnames.php +++ b/www/admin/hostnames.php @@ -18,7 +18,7 @@ $attributes['SERVER_PORT'] = array($_SERVER['SERVER_PORT']); $attributes['Utilities_getBaseURL()'] = array(\SimpleSAML\Utils\HTTP::getBaseURL()); $attributes['Utilities_getSelfHost()'] = array(\SimpleSAML\Utils\HTTP::getSelfHost()); -$attributes['Utilities_selfURLhost()'] = array(SimpleSAML_Utilities::selfURLhost()); +$attributes['Utilities_selfURLhost()'] = array(\SimpleSAML\Utils\HTTP::getSelfURLHost()); $attributes['Utilities_selfURLNoQuery()'] = array(SimpleSAML_Utilities::selfURLNoQuery()); $attributes['Utilities_getSelfHostWithPath()'] = array(\SimpleSAML\Utils\HTTP::getSelfHostWithPath()); $attributes['Utilities_getFirstPathElement()'] = array(\SimpleSAML\Utils\HTTP::getFirstPathElement()); -- GitLab