From 408e92545577b40bb39512a5c0a2c25b3aa889b3 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Tue, 21 Apr 2015 13:47:14 +0200 Subject: [PATCH] Move SimpleSAML_Utilities::selfURLNoQuery() to SimpleSAML\Utils\HTTP::getSelfURLNoQuery() and deprecate the former. --- lib/SimpleSAML/Error/Error.php | 2 +- lib/SimpleSAML/Utilities.php | 10 ++------- lib/SimpleSAML/Utils/HTTP.php | 26 ++++++++++++++++++++---- lib/SimpleSAML/XHTML/IdPDisco.php | 2 +- modules/adfs/www/idp/metadata.php | 2 +- modules/core/www/authenticate.php | 2 +- modules/discopower/lib/PowerIdPDisco.php | 2 +- modules/oauth/www/authorize.php | 4 ++-- modules/saml/lib/IdP/SAML2.php | 2 +- modules/saml/lib/Message.php | 4 ++-- modules/saml/www/sp/saml2-logout.php | 2 +- www/admin/hostnames.php | 2 +- www/errorreport.php | 2 +- www/saml2/idp/metadata.php | 2 +- www/shib13/idp/metadata.php | 2 +- 15 files changed, 39 insertions(+), 27 deletions(-) diff --git a/lib/SimpleSAML/Error/Error.php b/lib/SimpleSAML/Error/Error.php index 2c035bc74..a276d8f30 100644 --- a/lib/SimpleSAML/Error/Error.php +++ b/lib/SimpleSAML/Error/Error.php @@ -226,7 +226,7 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { 'exceptionTrace' => $etrace, 'reportId' => $reportId, 'trackId' => $session->getTrackID(), - 'url' => SimpleSAML_Utilities::selfURLNoQuery(), + 'url' => \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(), 'version' => $config->getVersion(), 'referer' => $referer, ); diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 44f2ff14c..d96f71a45 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -66,16 +66,10 @@ class SimpleSAML_Utilities { /** - * Will return https://sp.example.org/universities/ruc/baz/simplesaml/saml2/SSOService.php + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfURLNoQuery() instead. */ public static function selfURLNoQuery() { - - $selfURLhost = self::selfURLhost(); - $selfURLhost .= $_SERVER['SCRIPT_NAME']; - if (isset($_SERVER['PATH_INFO'])) { - $selfURLhost .= $_SERVER['PATH_INFO']; - } - return $selfURLhost; + return \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(); } diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index eed837a28..17340a0b8 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -372,16 +372,16 @@ class HTTP /** - * Retrieve the current URL. + * Retrieve the current, complete URL. * - * @return string The current URL. + * @return string The current URL, including query parameters. * * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no> * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> */ public static function getSelfURL() { - $selfURLhost = self::getSelfURLHost(); + $url = self::getSelfURLHost(); $requestURI = $_SERVER['REQUEST_URI']; if ($requestURI[0] !== '/') { // we probably have a URL of the form: http://server/ @@ -389,7 +389,7 @@ class HTTP $requestURI = $matches[1]; } } - return $selfURLhost.$requestURI; + return $url.$requestURI; } @@ -410,6 +410,24 @@ class HTTP } + /** + * Retrieve the current URL without the query parameters. + * + * @return string The current URL, not including query parameters. + * + * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no> + */ + public static function getSelfURLNoQuery() + { + $url = self::getSelfURLHost(); + $url .= $_SERVER['SCRIPT_NAME']; + if (isset($_SERVER['PATH_INFO'])) { + $url .= $_SERVER['PATH_INFO']; + } + return $url; + } + + /** * Parse a query string into an array. * diff --git a/lib/SimpleSAML/XHTML/IdPDisco.php b/lib/SimpleSAML/XHTML/IdPDisco.php index 87e7db3d3..f423ca710 100644 --- a/lib/SimpleSAML/XHTML/IdPDisco.php +++ b/lib/SimpleSAML/XHTML/IdPDisco.php @@ -523,7 +523,7 @@ class SimpleSAML_XHTML_IdPDisco { $t->data['return'] = $this->returnURL; $t->data['returnIDParam'] = $this->returnIdParam; $t->data['entityID'] = $this->spEntityId; - $t->data['urlpattern'] = htmlspecialchars(SimpleSAML_Utilities::selfURLNoQuery()); + $t->data['urlpattern'] = htmlspecialchars(\SimpleSAML\Utils\HTTP::getSelfURLNoQuery()); $t->data['rememberenabled'] = $this->config->getBoolean('idpdisco.enableremember', FALSE); $t->show(); } diff --git a/modules/adfs/www/idp/metadata.php b/modules/adfs/www/idp/metadata.php index e4e58a4f3..3b9515025 100644 --- a/modules/adfs/www/idp/metadata.php +++ b/modules/adfs/www/idp/metadata.php @@ -134,7 +134,7 @@ try { $t->data['available_certs'] = $availableCerts; $t->data['header'] = 'adfs-idp'; - $t->data['metaurl'] = SimpleSAML_Utilities::selfURLNoQuery(); + $t->data['metaurl'] = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(); $t->data['metadata'] = htmlspecialchars($metaxml); $t->data['metadataflat'] = htmlspecialchars($metaflat); $t->data['defaultidp'] = $defaultidp; diff --git a/modules/core/www/authenticate.php b/modules/core/www/authenticate.php index 0e23193c1..606095058 100644 --- a/modules/core/www/authenticate.php +++ b/modules/core/www/authenticate.php @@ -53,6 +53,6 @@ $t->data['header'] = '{status:header_saml20_sp}'; $t->data['attributes'] = $attributes; // if saml:sp:IdP is set, this is SAML auth so we can pass a NameId $t->data['nameid'] = !is_null( $as->getAuthData('saml:sp:IdP') ) ? $as->getAuthData('saml:sp:NameID') : FALSE; -$t->data['logouturl'] = SimpleSAML_Utilities::selfURLNoQuery() . '?as=' . urlencode($asId) . '&logout'; +$t->data['logouturl'] = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery() . '?as=' . urlencode($asId) . '&logout'; $t->show(); diff --git a/modules/discopower/lib/PowerIdPDisco.php b/modules/discopower/lib/PowerIdPDisco.php index ef50dc6e0..aaed123b6 100644 --- a/modules/discopower/lib/PowerIdPDisco.php +++ b/modules/discopower/lib/PowerIdPDisco.php @@ -224,7 +224,7 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco { $t->data['return'] = $this->returnURL; $t->data['returnIDParam'] = $this->returnIdParam; $t->data['entityID'] = $this->spEntityId; - $t->data['urlpattern'] = htmlspecialchars(SimpleSAML_Utilities::selfURLNoQuery()); + $t->data['urlpattern'] = htmlspecialchars(\SimpleSAML\Utils\HTTP::getSelfURLNoQuery()); $t->data['rememberenabled'] = $this->config->getBoolean('idpdisco.enableremember', FALSE); $t->data['rememberchecked'] = $this->config->getBoolean('idpdisco.rememberchecked', FALSE); $t->data['defaulttab'] = $this->discoconfig->getValue('defaulttab', 0); diff --git a/modules/oauth/www/authorize.php b/modules/oauth/www/authorize.php index 17392ad73..9ff13dc3d 100644 --- a/modules/oauth/www/authorize.php +++ b/modules/oauth/www/authorize.php @@ -41,7 +41,7 @@ try { $t->data['header'] = '{status:header_saml20_sp}'; $t->data['consumer'] = $consumer; // array containint {name, description, key, secret, owner} keys $t->data['urlAgree'] = \SimpleSAML\Utils\HTTP::addURLParameters(\SimpleSAML\Utils\HTTP::getSelfURL(), array("consent" => "yes")); - $t->data['logouturl'] = SimpleSAML_Utilities::selfURLNoQuery() . '?logout'; + $t->data['logouturl'] = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery() . '?logout'; $t->show(); @@ -70,7 +70,7 @@ try { $t->data['header'] = '{status:header_saml20_sp}'; $t->data['remaining'] = $session->getAuthData($as, "Expire") - time(); $t->data['attributes'] = $attributes; - $t->data['logouturl'] = SimpleSAML_Utilities::selfURLNoQuery() . '?logout'; + $t->data['logouturl'] = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery() . '?logout'; $t->data['oauth_verifier'] = $verifier; $t->show(); } diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php index e8e5a8b8d..936bdbada 100644 --- a/modules/saml/lib/IdP/SAML2.php +++ b/modules/saml/lib/IdP/SAML2.php @@ -362,7 +362,7 @@ class sspmod_saml_IdP_SAML2 { } $sessionLostURL = \SimpleSAML\Utils\HTTP::addURLParameters( - SimpleSAML_Utilities::selfURLNoQuery(), + \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(), $sessionLostParams); $state = array( diff --git a/modules/saml/lib/Message.php b/modules/saml/lib/Message.php index 1e85687ad..13532c047 100644 --- a/modules/saml/lib/Message.php +++ b/modules/saml/lib/Message.php @@ -500,7 +500,7 @@ class sspmod_saml_Message { } /* Validate Response-element destination. */ - $currentURL = SimpleSAML_Utilities::selfURLNoQuery(); + $currentURL = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(); $msgDestination = $response->getDestination(); if ($msgDestination !== NULL && $msgDestination !== $currentURL) { throw new Exception('Destination in response doesn\'t match the current URL. Destination is "' . @@ -556,7 +556,7 @@ class sspmod_saml_Message { } /* At least one valid signature found. */ - $currentURL = SimpleSAML_Utilities::selfURLNoQuery(); + $currentURL = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(); /* Check various properties of the assertion. */ diff --git a/modules/saml/www/sp/saml2-logout.php b/modules/saml/www/sp/saml2-logout.php index 1c5d87546..637009ac4 100644 --- a/modules/saml/www/sp/saml2-logout.php +++ b/modules/saml/www/sp/saml2-logout.php @@ -48,7 +48,7 @@ $spMetadata = $source->getMetadata(); sspmod_saml_Message::validateMessage($idpMetadata, $spMetadata, $message); $destination = $message->getDestination(); -if ($destination !== NULL && $destination !== SimpleSAML_Utilities::selfURLNoQuery()) { +if ($destination !== NULL && $destination !== \SimpleSAML\Utils\HTTP::getSelfURLNoQuery()) { throw new SimpleSAML_Error_Exception('Destination in logout message is wrong.'); } diff --git a/www/admin/hostnames.php b/www/admin/hostnames.php index 142cf16bf..51c2a80a4 100644 --- a/www/admin/hostnames.php +++ b/www/admin/hostnames.php @@ -19,7 +19,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\Utils\HTTP::getSelfURLHost()); -$attributes['Utilities_selfURLNoQuery()'] = array(SimpleSAML_Utilities::selfURLNoQuery()); +$attributes['Utilities_selfURLNoQuery()'] = array(\SimpleSAML\Utils\HTTP::getSelfURLNoQuery()); $attributes['Utilities_getSelfHostWithPath()'] = array(\SimpleSAML\Utils\HTTP::getSelfHostWithPath()); $attributes['Utilities_getFirstPathElement()'] = array(\SimpleSAML\Utils\HTTP::getFirstPathElement()); $attributes['Utilities_selfURL()'] = array(\SimpleSAML\Utils\HTTP::getSelfURL()); diff --git a/www/errorreport.php b/www/errorreport.php index a0f31e1a5..3e92b1804 100644 --- a/www/errorreport.php +++ b/www/errorreport.php @@ -99,4 +99,4 @@ if ($config->getBoolean('errorreporting', TRUE) && $toAddress !== 'na@example.or } /* Redirect the user back to this page to clear the POST request. */ -SimpleSAML_Utilities::redirectTrustedURL(SimpleSAML_Utilities::selfURLNoQuery()); +SimpleSAML_Utilities::redirectTrustedURL(\SimpleSAML\Utils\HTTP::getSelfURLNoQuery()); diff --git a/www/saml2/idp/metadata.php b/www/saml2/idp/metadata.php index 6f7377cfe..d78aefbb7 100644 --- a/www/saml2/idp/metadata.php +++ b/www/saml2/idp/metadata.php @@ -191,7 +191,7 @@ try { $t->data['available_certs'] = $availableCerts; $t->data['header'] = 'saml20-idp'; - $t->data['metaurl'] = SimpleSAML_Utilities::selfURLNoQuery(); + $t->data['metaurl'] = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(); $t->data['metadata'] = htmlspecialchars($metaxml); $t->data['metadataflat'] = htmlspecialchars($metaflat); $t->data['defaultidp'] = $defaultidp; diff --git a/www/shib13/idp/metadata.php b/www/shib13/idp/metadata.php index 92eb4ec05..73234215d 100644 --- a/www/shib13/idp/metadata.php +++ b/www/shib13/idp/metadata.php @@ -87,7 +87,7 @@ try { $t->data['header'] = 'shib13-idp'; - $t->data['metaurl'] = \SimpleSAML\Utils\HTTP::addURLParameters(SimpleSAML_Utilities::selfURLNoQuery(), array('output' => 'xml')); + $t->data['metaurl'] = \SimpleSAML\Utils\HTTP::addURLParameters(\SimpleSAML\Utils\HTTP::getSelfURLNoQuery(), array('output' => 'xml')); $t->data['metadata'] = htmlspecialchars($metaxml); $t->data['metadataflat'] = htmlspecialchars($metaflat); -- GitLab