diff --git a/lib/SimpleSAML/Module.php b/lib/SimpleSAML/Module.php index b5d8f0245c6fc69490f3c971c4479ce2e2ade3c1..829fa7b1182a2bf51c2d98d2ec2c7274bde11ebe 100644 --- a/lib/SimpleSAML/Module.php +++ b/lib/SimpleSAML/Module.php @@ -157,7 +157,7 @@ class SimpleSAML_Module { $url = SimpleSAML_Utilities::getBaseURL() . 'module.php/' . $resource; if (!empty($parameters)) { - $url = SimpleSAML_Utilities::addURLparameter($url, $parameters); + $url = \SimpleSAML\Utils\HTTP::addURLParameters($url, $parameters); } return $url; } diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index a0dab57b64513302ddb1bb079ac4985b71dd25bb..334f5846bc3d4c23300d56e5f1299595da1255e8 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -252,48 +252,10 @@ class SimpleSAML_Utilities { /** - * Add one or more query parameters to the given URL. - * - * @param $url The URL the query parameters should be added to. - * @param $parameter The query parameters which should be added to the url. This should be - * an associative array. For backwards comaptibility, it can also be a - * query string representing the new parameters. This will write a warning - * to the log. - * @return The URL with the new query parameters. - */ - public static function addURLparameter($url, $parameter) { - - /* For backwards compatibility - allow $parameter to be a string. */ - if(is_string($parameter)) { - /* Print warning to log. */ - $backtrace = debug_backtrace(); - $where = $backtrace[0]['file'] . ':' . $backtrace[0]['line']; - SimpleSAML_Logger::warning( - 'Deprecated use of SimpleSAML_Utilities::addURLparameter at ' . $where . - '. The parameter "$parameter" should now be an array, but a string was passed.'); - - $parameter = self::parseQueryString($parameter); - } - assert('is_array($parameter)'); - - $queryStart = strpos($url, '?'); - if($queryStart === FALSE) { - $oldQuery = array(); - $url .= '?'; - } else { - $oldQuery = substr($url, $queryStart + 1); - if($oldQuery === FALSE) { - $oldQuery = array(); - } else { - $oldQuery = self::parseQueryString($oldQuery); - } - $url = substr($url, 0, $queryStart + 1); - } - - $query = array_merge($oldQuery, $parameter); - $url .= http_build_query($query, '', '&'); - - return $url; + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::addURLParameters() instead. + */ + public static function addURLparameter($url, $parameters) { + return \SimpleSAML\Utils\HTTP::addURLParameter($url, $parameters); } diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index d501162af742f2a86f7cf4b7fe9b0e08cb019395..bf7ac0c4520bc09779f180ba19495c2419ca4780 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -65,6 +65,46 @@ class HTTP } + /** + * Add one or more query parameters to the given URL. + * + * @param string $url The URL the query parameters should be added to. + * @param array $parameters The query parameters which should be added to the url. This should be an associative + * array. + * + * @return string The URL with the new query parameters. + * @throws \SimpleSAML_Error_Exception If $url is not a string or $parameters is not an array. + * + * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no> + * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> + */ + public static function addURLParameters($url, $parameters) + { + if (!is_string($url) || !is_array($parameters)) { + throw new \SimpleSAML_Error_Exception('Invalid input parameters.'); + } + + $queryStart = strpos($url, '?'); + if ($queryStart === false) { + $oldQuery = array(); + $url .= '?'; + } else { + $oldQuery = substr($url, $queryStart + 1); + if ($oldQuery === false) { + $oldQuery = array(); + } else { + $oldQuery = self::parseQueryString($oldQuery); + } + $url = substr($url, 0, $queryStart + 1); + } + + $query = array_merge($oldQuery, $parameters); + $url .= http_build_query($query, '', '&'); + + return $url; + } + + /** * Retrieve the port number from $_SERVER environment variables. * @@ -107,7 +147,7 @@ class HTTP public static function parseQueryString($query_string) { if (!is_string($query_string)) { - throw new \SimpleSAML_Error_Exception('Invalid input parameters'); + throw new \SimpleSAML_Error_Exception('Invalid input parameters.'); } $res = array(); diff --git a/modules/aselect/lib/Auth/Source/aselect.php b/modules/aselect/lib/Auth/Source/aselect.php index 874b5ca72e2d4794bf4038380ea74e033dd52ca8..fca98969368e70a8d2455ca5a0cc734a8484d195 100644 --- a/modules/aselect/lib/Auth/Source/aselect.php +++ b/modules/aselect/lib/Auth/Source/aselect.php @@ -125,7 +125,7 @@ class sspmod_aselect_Auth_Source_aselect extends SimpleSAML_Auth_Source { $signable .= $parameters[$p]; $parameters['signature'] = $this->base64_signature($signable); } - return SimpleSAML_Utilities::addURLparameter($this->server_url, $parameters); + return \SimpleSAML\Utils\HTTP::addURLParameters($this->server_url, $parameters); } /** @@ -177,7 +177,7 @@ class sspmod_aselect_Auth_Source_aselect extends SimpleSAML_Auth_Source { $as_url = $res['as_url']; unset($res['as_url']); - return SimpleSAML_Utilities::addURLparameter($as_url, $res); + return \SimpleSAML\Utils\HTTP::addURLParameters($as_url, $res); } /** diff --git a/modules/authtwitter/lib/Auth/Source/Twitter.php b/modules/authtwitter/lib/Auth/Source/Twitter.php index c07106633f4196b3a08a864a00c5792f77605f65..58e7ba64ae36a5d7c06e374df09cdd24e0d3b2d7 100644 --- a/modules/authtwitter/lib/Auth/Source/Twitter.php +++ b/modules/authtwitter/lib/Auth/Source/Twitter.php @@ -72,7 +72,7 @@ class sspmod_authtwitter_Auth_Source_Twitter extends SimpleSAML_Auth_Source { // Authorize the request token $url = 'https://api.twitter.com/oauth/authenticate'; if ($this->force_login) { - $url = SimpleSAML_Utilities::addURLparameter($url, array('force_login' => 'true')); + $url = \SimpleSAML\Utils\HTTP::addURLParameters($url, array('force_login' => 'true')); } $consumer->getAuthorizeRequest($url, $requestToken); } diff --git a/modules/cas/lib/Auth/Source/CAS.php b/modules/cas/lib/Auth/Source/CAS.php index 611fd85c2defe73abb22f6a69afdb6bf856e442a..81ae59e28be8aa816c802de69c31009b676d0e02 100644 --- a/modules/cas/lib/Auth/Source/CAS.php +++ b/modules/cas/lib/Auth/Source/CAS.php @@ -89,7 +89,7 @@ class sspmod_cas_Auth_Source_CAS extends SimpleSAML_Auth_Source { * @return list username and attributes */ private function casValidate($ticket, $service){ - $url = SimpleSAML_Utilities::addURLparameter($this->_casConfig['validate'], array( + $url = \SimpleSAML\Utils\HTTP::addURLParameters($this->_casConfig['validate'], array( 'ticket' => $ticket, 'service' => $service, )); @@ -112,7 +112,7 @@ class sspmod_cas_Auth_Source_CAS extends SimpleSAML_Auth_Source { * @return list username and attributes */ private function casServiceValidate($ticket, $service){ - $url = SimpleSAML_Utilities::addURLparameter($this->_casConfig['serviceValidate'], array( + $url = \SimpleSAML\Utils\HTTP::addURLParameters($this->_casConfig['serviceValidate'], array( 'ticket' => $ticket, 'service' => $service, )); diff --git a/modules/casserver/www/login.php b/modules/casserver/www/login.php index 43e08fb35b15a899f09015dfbba0c89e45ce9e64..f660a98c9e539359d46a8f71c5bbbc5d4ac053d2 100644 --- a/modules/casserver/www/login.php +++ b/modules/casserver/www/login.php @@ -49,7 +49,7 @@ storeTicket($ticket, $path, array('service' => $service, 'validbefore' => time() + 5)); SimpleSAML_Utilities::redirectTrustedURL( - SimpleSAML_Utilities::addURLparameter($service, + \SimpleSAML\Utils\HTTP::addURLParameters($service, array('ticket' => $ticket) ) ); \ No newline at end of file diff --git a/modules/cdc/lib/Server.php b/modules/cdc/lib/Server.php index 2aa88506137d7090166c9e2376049a8b79deeb14..8c2798fd71031a6809b1868cedae1ce2e138f598 100644 --- a/modules/cdc/lib/Server.php +++ b/modules/cdc/lib/Server.php @@ -324,7 +324,7 @@ class sspmod_cdc_Server { 'Signature' => $signature, ); - $url = SimpleSAML_Utilities::addURLparameter($to, $params); + $url = \SimpleSAML\Utils\HTTP::addURLParameters($to, $params); if (strlen($url) < 2048) { SimpleSAML_Utilities::redirectTrustedURL($url); } else { diff --git a/modules/discojuice/www/central.php b/modules/discojuice/www/central.php index 6f1a7ead6fd137123deefb72e0e98b77073141af..9404fd546c4101224bc2ab27c68f0a0687e1650f 100644 --- a/modules/discojuice/www/central.php +++ b/modules/discojuice/www/central.php @@ -12,7 +12,7 @@ $entityid = $_REQUEST['entityID']; // Return to... $returnidparam = !empty($_REQUEST['returnIDParam']) ? $_REQUEST['returnIDParam'] : 'entityID'; -$href = SimpleSAML_Utilities::addURLparameter( +$href = \SimpleSAML\Utils\HTTP::addURLParameters( $_REQUEST['return'], array($returnidparam => '') ); diff --git a/modules/oauth/lib/Consumer.php b/modules/oauth/lib/Consumer.php index 8e3e5aed60fb4da5facb4b81e4c5e10c73abcb01..265b1cab906ea5dfc7ce712dacdfc163ec651e47 100644 --- a/modules/oauth/lib/Consumer.php +++ b/modules/oauth/lib/Consumer.php @@ -91,7 +91,7 @@ class sspmod_oauth_Consumer { if ($callback) { $params['oauth_callback'] = $callback; } - $authorizeURL = SimpleSAML_Utilities::addURLparameter($url, $params); + $authorizeURL = \SimpleSAML\Utils\HTTP::addURLParameters($url, $params); if ($redirect) { SimpleSAML_Utilities::redirectTrustedURL($authorizeURL); exit; diff --git a/modules/oauth/lib/OAuthStore.php b/modules/oauth/lib/OAuthStore.php index 6a239a6c04e51d5d5cc76161356893b1d3e55fdf..974387a21a410a147f72ab4c3022a6dbbade49e0 100644 --- a/modules/oauth/lib/OAuthStore.php +++ b/modules/oauth/lib/OAuthStore.php @@ -63,7 +63,7 @@ class sspmod_oauth_OAuthStore extends OAuthDataStore { if ($oConsumer && ($oConsumer->callback_url)) $url = $oConsumer->callback_url; $verifier = SimpleSAML\Utils\Random::generateID(); - $url = SimpleSAML_Utilities::addURLparameter($url, array("oauth_verifier"=>$verifier)); + $url = \SimpleSAML\Utils\HTTP::addURLParameters($url, array("oauth_verifier"=>$verifier)); $this->store->set('authorized', $requestTokenKey, $verifier, $data, $this->config->getValue('requestTokenDuration', 60*30) ); diff --git a/modules/oauth/www/authorize.php b/modules/oauth/www/authorize.php index afcc395b9a1722fb6d65795967307f7b1e4b459e..523670ecf148be54873fa8d3797638c1fee1e60a 100644 --- a/modules/oauth/www/authorize.php +++ b/modules/oauth/www/authorize.php @@ -40,7 +40,7 @@ try { $t = new SimpleSAML_XHTML_Template($config, 'oauth:consent.php'); $t->data['header'] = '{status:header_saml20_sp}'; $t->data['consumer'] = $consumer; // array containint {name, description, key, secret, owner} keys - $t->data['urlAgree'] = SimpleSAML_Utilities::addURLparameter( SimpleSAML_Utilities::selfURL(), array("consent" => "yes") ); + $t->data['urlAgree'] = \SimpleSAML\Utils\HTTP::addURLParameters(SimpleSAML_Utilities::selfURL(), array("consent" => "yes")); $t->data['logouturl'] = SimpleSAML_Utilities::selfURLNoQuery() . '?logout'; $t->show(); diff --git a/modules/saml/lib/IdP/SAML1.php b/modules/saml/lib/IdP/SAML1.php index 9ef95b78a5f679eefeced77140d7b3b91231d2c3..79c8617ea2f7347c1ebf6d6efa2f0ef1a4889919 100644 --- a/modules/saml/lib/IdP/SAML1.php +++ b/modules/saml/lib/IdP/SAML1.php @@ -115,7 +115,7 @@ class sspmod_saml_IdP_SAML1 { 'protocol' => 'saml1', )); - $sessionLostURL = SimpleSAML_Utilities::addURLparameter( + $sessionLostURL = \SimpleSAML\Utils\HTTP::addURLParameters( SimpleSAML_Utilities::selfURL(), array('cookieTime' => time())); diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php index ae9a6d4fbd5f7dedc81eee0261631cf10f9fdc6c..a6bf33a4c8e793af3315346c3907fea00ca17746 100644 --- a/modules/saml/lib/IdP/SAML2.php +++ b/modules/saml/lib/IdP/SAML2.php @@ -361,7 +361,7 @@ class sspmod_saml_IdP_SAML2 { $sessionLostParams['RelayState'] = $relayState; } - $sessionLostURL = SimpleSAML_Utilities::addURLparameter( + $sessionLostURL = \SimpleSAML\Utils\HTTP::addURLParameters( SimpleSAML_Utilities::selfURLNoQuery(), $sessionLostParams); diff --git a/templates/includes/header.php b/templates/includes/header.php index cb59059fc896289154c728c192028021a6ed9e10..10f75765b7a61148edb2092aceb3316071078d17 100644 --- a/templates/includes/header.php +++ b/templates/includes/header.php @@ -186,7 +186,7 @@ if($onLoad !== '') { if ($current) { $textarray[] = $langnames[$lang]; } else { - $textarray[] = '<a href="' . htmlspecialchars(SimpleSAML_Utilities::addURLparameter(SimpleSAML_Utilities::selfURL(), array($this->languageParameterName => $lang))) . '">' . + $textarray[] = '<a href="' . htmlspecialchars(\SimpleSAML\Utils\HTTP::addURLParameters(SimpleSAML_Utilities::selfURL(), array($this->languageParameterName => $lang))) . '">' . $langnames[$lang] . '</a>'; } } diff --git a/www/shib13/idp/metadata.php b/www/shib13/idp/metadata.php index fc0a3583431b4b4376f8523539f22ba03cdf5143..92eb4ec05119d3036757f9f1c66ccf46165ee492 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_Utilities::addURLparameter(SimpleSAML_Utilities::selfURLNoQuery(), array('output' => 'xml')); + $t->data['metaurl'] = \SimpleSAML\Utils\HTTP::addURLParameters(SimpleSAML_Utilities::selfURLNoQuery(), array('output' => 'xml')); $t->data['metadata'] = htmlspecialchars($metaxml); $t->data['metadataflat'] = htmlspecialchars($metaflat);