Skip to content
Snippets Groups Projects
Commit 7ce18d59 authored by Andrés Blanco's avatar Andrés Blanco
Browse files

Fixes issue 337

parent 07eef913
No related branches found
No related tags found
No related merge requests found
......@@ -207,11 +207,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
}
// then we look for the hostname
$currenthost = \SimpleSAML\Utils\HTTP::getSelfHost(); // sp.example.org
if (strpos($currenthost, ":") !== false) {
$currenthostdecomposed = explode(":", $currenthost);
$currenthost = $currenthostdecomposed[0];
}
$currenthost = \SimpleSAML\Utils\HTTP::getSelfHostWithoutPort(); // sp.example.org
foreach ($this->sources as $source) {
$index = $source->getEntityIdFromHostPath($currenthost, $set, $type);
......
......@@ -134,9 +134,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerFlatFile extends SimpleSAML_Meta
} elseif ($set === 'shib13-idp-hosted') {
return $baseurl.'shib13/idp/metadata.php';
} elseif ($set === 'wsfed-sp-hosted') {
return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost();
return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHostWithoutPort();
} elseif ($set === 'adfs-idp-hosted') {
return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost().':idp';
return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHostWithoutPort().':idp';
} else {
throw new Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
}
......
......@@ -151,9 +151,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerPdo extends SimpleSAML_Metadata_
} elseif ($set === 'shib13-sp-hosted') {
return $baseurl.'shib13/sp/metadata.php';
} elseif ($set === 'wsfed-sp-hosted') {
return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost();
return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHostWithoutPort();
} elseif ($set === 'adfs-idp-hosted') {
return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost().':idp';
return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHostWithoutPort().':idp';
} else {
throw new Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
}
......
......@@ -198,11 +198,7 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource
$metadataSet = $this->getMetadataSet($set);
// check for hostname
$currenthost = \SimpleSAML\Utils\HTTP::getSelfHost(); // sp.example.org
if (strpos($currenthost, ":") !== false) {
$currenthostdecomposed = explode(":", $currenthost);
$currenthost = $currenthostdecomposed[0];
}
$currenthost = \SimpleSAML\Utils\HTTP::getSelfHostWithoutPort(); // sp.example.org
foreach ($metadataSet as $index => $entry) {
if ($index === $entityId) {
......
......@@ -336,7 +336,7 @@ class HTTP
/**
* Helper function to retrieve a file or URL with proxy support, also
* Helper function to retrieve a file or URL with proxy support, also
* supporting proxy basic authorization..
*
* An exception will be thrown if we are unable to retrieve the data.
......@@ -605,11 +605,25 @@ class HTTP
$url = self::getBaseURL();
$start = strpos($url, '://') + 3;
$length = strcspn($url, '/:', $start);
$length = strcspn($url, '/', $start);
return substr($url, $start, $length);
}
/**
* Retrieve our own host.
*
* @return string The current host without port specification.
*/
public static function getSelfHostWithoutPort()
{
$url = self::getBaseURL();
$start = strpos($url, '://') + 3;
$length = strcspn($url, '/:', $start);
return substr($url, $start, $length);
}
/**
* Retrieve our own host together with the URL path. Please note this function will return the base URL for the
......
<?php
namespace SimpleSAML\Test\Utils;
use SimpleSAML\Utils\HTTP;
class HTTPTest extends \PHPUnit_Framework_TestCase
{
/**
* Test HTTP::getSelfHost with and without custom port
*/
public function testGetSelfHost()
{
\SimpleSAML_Configuration::loadFromArray(array(
'baseurlpath' => '',
), '[ARRAY]', 'simplesaml');
$_SERVER['SERVER_PORT'] = '80';
$this->assertEquals('localhost', HTTP::getSelfHost());
$_SERVER['SERVER_PORT'] = '3030';
$this->assertEquals('localhost:3030', HTTP::getSelfHost());
}
/**
* Test HTTP::getSelfHostWithoutPort
*/
public function testGetSelfHostWithoutPort()
{
\SimpleSAML_Configuration::loadFromArray(array(
'baseurlpath' => '',
), '[ARRAY]', 'simplesaml');
$_SERVER['SERVER_PORT'] = '80';
$this->assertEquals('localhost', HTTP::getSelfHostWithoutPort());
$_SERVER['SERVER_PORT'] = '3030';
$this->assertEquals('localhost', HTTP::getSelfHostWithoutPort());
}
}
......@@ -17,7 +17,7 @@ $attributes['SERVER_PROTOCOL'] = array($_SERVER['SERVER_PROTOCOL']);
$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_getSelfHost()'] = array(\SimpleSAML\Utils\HTTP::getSelfHostWithoutPort());
$attributes['Utilities_selfURLhost()'] = array(\SimpleSAML\Utils\HTTP::getSelfURLHost());
$attributes['Utilities_selfURLNoQuery()'] = array(\SimpleSAML\Utils\HTTP::getSelfURLNoQuery());
$attributes['Utilities_getSelfHostWithPath()'] = array(\SimpleSAML\Utils\HTTP::getSelfHostWithPath());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment