summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJaime Perez Crespo <jaime.perez@uninett.no>2016-03-03 11:48:54 +0100
committerJaime Perez Crespo <jaime.perez@uninett.no>2016-03-03 11:48:54 +0100
commitd4de56da714ffc46cfee0b066c723c21be527c79 (patch)
treef79bb33b6e580868fb071da5915f7da0edcab9ec /lib
parent7ce18d59c208fb28baaef549280d09bf9b9dc903 (diff)
downloadsimplesamlphp-d4de56da714ffc46cfee0b066c723c21be527c79.zip
simplesamlphp-d4de56da714ffc46cfee0b066c723c21be527c79.tar.gz
simplesamlphp-d4de56da714ffc46cfee0b066c723c21be527c79.tar.bz2
Rename Utils\HTTP::getSelfHostWithoutPort() to Utils\HTTP::getSelfHostWithNonStandardPort(), change the logic, and reimplement Utils\HTTP::getSelfHost() to depend on use the former. Complete the tests to include the case of port 443 while using HTTPS.
Diffstat (limited to 'lib')
-rw-r--r--lib/SimpleSAML/Metadata/MetaDataStorageHandler.php2
-rw-r--r--lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php4
-rw-r--r--lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php4
-rw-r--r--lib/SimpleSAML/Metadata/MetaDataStorageSource.php2
-rw-r--r--lib/SimpleSAML/Utils/HTTP.php29
5 files changed, 22 insertions, 19 deletions
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
index 50c3209..5c1c6e8 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
@@ -207,7 +207,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler
}
// then we look for the hostname
- $currenthost = \SimpleSAML\Utils\HTTP::getSelfHostWithoutPort(); // sp.example.org
+ $currenthost = \SimpleSAML\Utils\HTTP::getSelfHost(); // sp.example.org
foreach ($this->sources as $source) {
$index = $source->getEntityIdFromHostPath($currenthost, $set, $type);
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
index 80bade1..3f86322 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php
@@ -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::getSelfHostWithoutPort();
+ return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost();
} elseif ($set === 'adfs-idp-hosted') {
- return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHostWithoutPort().':idp';
+ return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost().':idp';
} else {
throw new Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
}
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
index 7202a73..e898116 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
@@ -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::getSelfHostWithoutPort();
+ return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost();
} elseif ($set === 'adfs-idp-hosted') {
- return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHostWithoutPort().':idp';
+ return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost().':idp';
} else {
throw new Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
}
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
index d442bf7..9d677cd 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php
@@ -198,7 +198,7 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource
$metadataSet = $this->getMetadataSet($set);
// check for hostname
- $currenthost = \SimpleSAML\Utils\HTTP::getSelfHostWithoutPort(); // sp.example.org
+ $currenthost = \SimpleSAML\Utils\HTTP::getSelfHost(); // sp.example.org
foreach ($metadataSet as $index => $entry) {
if ($index === $entityId) {
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index c25bc6d..00946fc 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -595,32 +595,35 @@ class HTTP
/**
* Retrieve our own host.
*
- * @return string The current host (with non-default ports included).
+ * E.g. www.example.com
*
- * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
- * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+ * @return string The current host.
+ *
+ * @author Jaime Perez, UNINETT AS <jaime.perez@uninett.no>
*/
public static function getSelfHost()
{
- $url = self::getBaseURL();
-
- $start = strpos($url, '://') + 3;
- $length = strcspn($url, '/', $start);
-
- return substr($url, $start, $length);
+ return array_shift(explode(':', self::getSelfHostWithNonStandardPort()));
}
/**
- * Retrieve our own host.
+ * Retrieve our own host, including the port in case the it is not standard for the protocol in use. That is port
+ * 80 for HTTP and port 443 for HTTPS.
+ *
+ * E.g. www.example.com:8080
*
- * @return string The current host without port specification.
+ * @return string The current host, followed by a colon and the port number, in case the port is not standard for
+ * the protocol.
+ *
+ * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
+ * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
*/
- public static function getSelfHostWithoutPort()
+ public static function getSelfHostWithNonStandardPort()
{
$url = self::getBaseURL();
$start = strpos($url, '://') + 3;
- $length = strcspn($url, '/:', $start);
+ $length = strcspn($url, '/', $start);
return substr($url, $start, $length);
}