Skip to content
Snippets Groups Projects
Commit 838044ca authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Move SimpleSAML_Metadata_MetaDataStorageHandlerMDX to...

Move SimpleSAML_Metadata_MetaDataStorageHandlerMDX to SimpleSAML\Metadata\Sources\MDQ, and stop referring to it as MDX elsewhere.
parent 619e888c
No related branches found
No related tags found
No related merge requests found
...@@ -807,11 +807,11 @@ $config = array( ...@@ -807,11 +807,11 @@ $config = array(
* - 'file': Path to the XML file with the metadata. * - 'file': Path to the XML file with the metadata.
* - 'url': The URL to fetch metadata from. THIS IS ONLY FOR DEBUGGING - THERE IS NO CACHING OF THE RESPONSE. * - 'url': The URL to fetch metadata from. THIS IS ONLY FOR DEBUGGING - THERE IS NO CACHING OF THE RESPONSE.
* *
* MDX metadata handler: * MDQ metadata handler:
* This metadata handler looks up for the metadata of an entity at the given MDX server. * This metadata handler looks up for the metadata of an entity at the given MDQ server.
* The MDX metadata handler defines the following options: * The MDQ metadata handler defines the following options:
* - 'type': This is always 'mdx'. * - 'type': This is always 'mdq'.
* - 'server': Base URL of the MDX server. Mandatory. * - 'server': Base URL of the MDQ server. Mandatory.
* - 'validateFingerprint': The fingerprint of the certificate used to sign the metadata. You don't need this * - 'validateFingerprint': The fingerprint of the certificate used to sign the metadata. You don't need this
* option if you don't want to validate the signature on the metadata. Optional. * option if you don't want to validate the signature on the metadata. Optional.
* - 'cachedir': Directory where metadata can be cached. Optional. * - 'cachedir': Directory where metadata can be cached. Optional.
...@@ -843,12 +843,12 @@ $config = array( ...@@ -843,12 +843,12 @@ $config = array(
* array('type' => 'xml', 'file' => 'idp.example.org-idpMeta.xml'), * array('type' => 'xml', 'file' => 'idp.example.org-idpMeta.xml'),
* ), * ),
* *
* This example defines an mdx source. * This example defines an mdq source.
* 'metadata.sources' => array( * 'metadata.sources' => array(
* array( * array(
* 'type' => 'mdx', * 'type' => 'mdq',
* 'server' => 'http://mdx.server.com:8080', * 'server' => 'http://mdq.server.com:8080',
* 'cachedir' => '/var/simplesamlphp/mdx-cache', * 'cachedir' => '/var/simplesamlphp/mdq-cache',
* 'cachelength' => 86400 * 'cachelength' => 86400
* ) * )
* ), * ),
......
...@@ -75,7 +75,8 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource ...@@ -75,7 +75,8 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource
case 'serialize': case 'serialize':
return new SimpleSAML_Metadata_MetaDataStorageHandlerSerialize($sourceConfig); return new SimpleSAML_Metadata_MetaDataStorageHandlerSerialize($sourceConfig);
case 'mdx': case 'mdx':
return new SimpleSAML_Metadata_MetaDataStorageHandlerMDX($sourceConfig); case 'mdq':
return new \SimpleSAML\Metadata\Sources\MDQ($sourceConfig);
case 'pdo': case 'pdo':
return new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($sourceConfig); return new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($sourceConfig);
default: default:
......
<?php <?php
namespace SimpleSAML\Metadata\Sources;
use SimpleSAML\Logger;
use SimpleSAML\Utils\HTTP;
/** /**
* This class implements SAML Metadata Exchange Protocol * This class implements SAML Metadata Query Protocol
* *
* @author Andreas Åkre Solberg, UNINETT AS. * @author Andreas Åkre Solberg, UNINETT AS.
* @author Olav Morken, UNINETT AS. * @author Olav Morken, UNINETT AS.
* @author Tamas Frank, NIIFI * @author Tamas Frank, NIIFI
* @package SimpleSAMLphp * @package SimpleSAMLphp
*/ */
class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_MetaDataStorageSource class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
{ {
/** /**
* The URL of MDX server (url:port) * The URL of MDQ server (url:port)
* *
* @var string * @var string
*/ */
...@@ -47,7 +51,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -47,7 +51,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
* This function initializes the dynamic XML metadata source. * This function initializes the dynamic XML metadata source.
* *
* Options: * Options:
* - 'server': URL of the MDX server (url:port). Mandatory. * - 'server': URL of the MDQ server (url:port). Mandatory.
* - 'validateFingerprint': The fingerprint of the certificate used to sign the metadata. * - 'validateFingerprint': The fingerprint of the certificate used to sign the metadata.
* You don't need this option if you don't want to validate the signature on the metadata. * You don't need this option if you don't want to validate the signature on the metadata.
* Optional. * Optional.
...@@ -57,14 +61,14 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -57,14 +61,14 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
* *
* @param array $config The configuration for this instance of the XML metadata source. * @param array $config The configuration for this instance of the XML metadata source.
* *
* @throws Exception If no server option can be found in the configuration. * @throws \Exception If no server option can be found in the configuration.
*/ */
protected function __construct($config) protected function __construct($config)
{ {
assert('is_array($config)'); assert('is_array($config)');
if (!array_key_exists('server', $config)) { if (!array_key_exists('server', $config)) {
throw new Exception("The 'server' configuration option is not set."); throw new \Exception(__CLASS__.": the 'server' configuration option is not set.");
} else { } else {
$this->server = $config['server']; $this->server = $config['server'];
} }
...@@ -76,7 +80,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -76,7 +80,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
} }
if (array_key_exists('cachedir', $config)) { if (array_key_exists('cachedir', $config)) {
$globalConfig = SimpleSAML_Configuration::getInstance(); $globalConfig = \SimpleSAML_Configuration::getInstance();
$this->cacheDir = $globalConfig->resolvePath($config['cachedir']); $this->cacheDir = $globalConfig->resolvePath($config['cachedir']);
} else { } else {
$this->cacheDir = null; $this->cacheDir = null;
...@@ -130,7 +134,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -130,7 +134,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
* *
* @return array|NULL The associative array with the metadata for this entity, or NULL * @return array|NULL The associative array with the metadata for this entity, or NULL
* if the entity could not be found. * if the entity could not be found.
* @throws Exception If an error occurs while loading metadata from cache. * @throws \Exception If an error occurs while loading metadata from cache.
*/ */
private function getFromCache($set, $entityId) private function getFromCache($set, $entityId)
{ {
...@@ -146,9 +150,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -146,9 +150,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
return null; return null;
} }
if (!is_readable($cachefilename)) { if (!is_readable($cachefilename)) {
throw new Exception('Could not read cache file for entity ['.$cachefilename.']'); throw new \Exception(__CLASS__.': could not read cache file for entity ['.$cachefilename.']');
} }
SimpleSAML\Logger::debug('MetaData - Handler.MDX: Reading cache ['.$entityId.'] => ['.$cachefilename.']'); Logger::debug(__CLASS__.': reading cache ['.$entityId.'] => ['.$cachefilename.']');
/* Ensure that this metadata isn't older that the cachelength option allows. This /* Ensure that this metadata isn't older that the cachelength option allows. This
* must be verified based on the file, since this option may be changed after the * must be verified based on the file, since this option may be changed after the
...@@ -156,25 +160,25 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -156,25 +160,25 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
*/ */
$stat = stat($cachefilename); $stat = stat($cachefilename);
if ($stat['mtime'] + $this->cacheLength <= time()) { if ($stat['mtime'] + $this->cacheLength <= time()) {
SimpleSAML\Logger::debug('MetaData - Handler.MDX: Cache file older that the cachelength option allows.'); Logger::debug(__CLASS__.': cache file older that the cachelength option allows.');
return null; return null;
} }
$rawData = file_get_contents($cachefilename); $rawData = file_get_contents($cachefilename);
if (empty($rawData)) { if (empty($rawData)) {
$error = error_get_last(); $error = error_get_last();
throw new Exception( throw new \Exception(
'Error reading metadata from cache file "'.$cachefilename.'": '.$error['message'] __CLASS__.': error reading metadata from cache file "'.$cachefilename.'": '.$error['message']
); );
} }
$data = unserialize($rawData); $data = unserialize($rawData);
if ($data === false) { if ($data === false) {
throw new Exception('Error unserializing cached data from file "'.$cachefilename.'".'); throw new \Exception(__CLASS__.': error unserializing cached data from file "'.$cachefilename.'".');
} }
if (!is_array($data)) { if (!is_array($data)) {
throw new Exception('Cached metadata from "'.$cachefilename.'" wasn\'t an array.'); throw new \Exception(__CLASS__.': Cached metadata from "'.$cachefilename.'" wasn\'t an array.');
} }
return $data; return $data;
...@@ -188,7 +192,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -188,7 +192,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
* @param string $entityId The entity id of this entity. * @param string $entityId The entity id of this entity.
* @param array $data The associative array with the metadata for this entity. * @param array $data The associative array with the metadata for this entity.
* *
* @throws Exception If metadata cannot be written to cache. * @throws \Exception If metadata cannot be written to cache.
*/ */
private function writeToCache($set, $entityId, $data) private function writeToCache($set, $entityId, $data)
{ {
...@@ -202,9 +206,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -202,9 +206,9 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
$cachefilename = $this->getCacheFilename($set, $entityId); $cachefilename = $this->getCacheFilename($set, $entityId);
if (!is_writable(dirname($cachefilename))) { if (!is_writable(dirname($cachefilename))) {
throw new Exception('Could not write cache file for entity ['.$cachefilename.']'); throw new \Exception(__CLASS__.': could not write cache file for entity ['.$cachefilename.']');
} }
SimpleSAML\Logger::debug('MetaData - Handler.MDX: Writing cache ['.$entityId.'] => ['.$cachefilename.']'); Logger::debug(__CLASS__.': Writing cache ['.$entityId.'] => ['.$cachefilename.']');
file_put_contents($cachefilename, serialize($data)); file_put_contents($cachefilename, serialize($data));
} }
...@@ -212,13 +216,13 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -212,13 +216,13 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
/** /**
* Retrieve metadata for the correct set from a SAML2Parser. * Retrieve metadata for the correct set from a SAML2Parser.
* *
* @param SimpleSAML_Metadata_SAMLParser $entity A SAML2Parser representing an entity. * @param \SimpleSAML_Metadata_SAMLParser $entity A SAML2Parser representing an entity.
* @param string $set The metadata set we are looking for. * @param string $set The metadata set we are looking for.
* *
* @return array|NULL The associative array with the metadata, or NULL if no metadata for * @return array|NULL The associative array with the metadata, or NULL if no metadata for
* the given set was found. * the given set was found.
*/ */
private static function getParsedSet(SimpleSAML_Metadata_SAMLParser $entity, $set) private static function getParsedSet(\SimpleSAML_Metadata_SAMLParser $entity, $set)
{ {
assert('is_string($set)'); assert('is_string($set)');
...@@ -236,7 +240,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -236,7 +240,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
return $ret[0]; return $ret[0];
default: default:
SimpleSAML\Logger::warning('MetaData - Handler.MDX: Unknown metadata set: '.$set); Logger::warning(__CLASS__.': unknown metadata set: \''.$set.'\'.');
} }
return null; return null;
...@@ -258,14 +262,14 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -258,14 +262,14 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
* *
* @return array An associative array with metadata for the given entity, or NULL if we are unable to * @return array An associative array with metadata for the given entity, or NULL if we are unable to
* locate the entity. * locate the entity.
* @throws Exception If an error occurs while downloading metadata, validating the signature or writing to cache. * @throws \Exception If an error occurs while downloading metadata, validating the signature or writing to cache.
*/ */
public function getMetaData($index, $set) public function getMetaData($index, $set)
{ {
assert('is_string($index)'); assert('is_string($index)');
assert('is_string($set)'); assert('is_string($set)');
SimpleSAML\Logger::info('MetaData - Handler.MDX: Loading metadata entity ['.$index.'] from ['.$set.']'); Logger::info(__CLASS__.': loading metadata entity ['.$index.'] from ['.$set.']');
// read from cache if possible // read from cache if possible
$data = $this->getFromCache($set, $index); $data = $this->getFromCache($set, $index);
...@@ -277,45 +281,44 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_ ...@@ -277,45 +281,44 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerMDX extends SimpleSAML_Metadata_
if (isset($data)) { if (isset($data)) {
// metadata found in cache and not expired // metadata found in cache and not expired
SimpleSAML\Logger::debug('MetaData - Handler.MDX: Using cached metadata for: '.$index.'.'); Logger::debug(__CLASS__.': using cached metadata for: '.$index.'.');
return $data; return $data;
} }
// look at Metadata Query Protocol: https://github.com/iay/md-query/blob/master/draft-young-md-query.txt // look at Metadata Query Protocol: https://github.com/iay/md-query/blob/master/draft-young-md-query.txt
$mdx_url = $this->server.'/entities/'.urlencode($index); $mdq_url = $this->server.'/entities/'.urlencode($index);
SimpleSAML\Logger::debug('MetaData - Handler.MDX: Downloading metadata for "'.$index.'" from ['.$mdx_url.']'); Logger::debug(__CLASS__.': downloading metadata for "'.$index.'" from ['.$mdq_url.']');
try { try {
$xmldata = \SimpleSAML\Utils\HTTP::fetch($mdx_url); $xmldata = HTTP::fetch($mdq_url);
} catch (Exception $e) { } catch (\Exception $e) {
SimpleSAML\Logger::warning('Fetching metadata for '.$index.': '.$e->getMessage()); Logger::warning('Fetching metadata for '.$index.': '.$e->getMessage());
} }
if (empty($xmldata)) { if (empty($xmldata)) {
$error = error_get_last(); $error = error_get_last();
throw new Exception( throw new \Exception(
'Error downloading metadata for "'.$index.'" from "'.$mdx_url.'": '.$error['message'] 'Error downloading metadata for "'.$index.'" from "'.$mdq_url.'": '.$error['message']
); );
} }
/** @var string $xmldata */ /** @var string $xmldata */
$entity = SimpleSAML_Metadata_SAMLParser::parseString($xmldata); $entity = \SimpleSAML_Metadata_SAMLParser::parseString($xmldata);
SimpleSAML\Logger::debug('MetaData - Handler.MDX: Completed parsing of ['.$mdx_url.']'); Logger::debug(__CLASS__.': completed parsing of ['.$mdq_url.']');
if ($this->validateFingerprint !== null) { if ($this->validateFingerprint !== null) {
if (!$entity->validateFingerprint($this->validateFingerprint)) { if (!$entity->validateFingerprint($this->validateFingerprint)) {
throw new Exception('Error, could not verify signature for entity: '.$index.'".'); throw new \Exception(__CLASS__.': error, could not verify signature for entity: '.$index.'".');
} }
} }
$data = self::getParsedSet($entity, $set); $data = self::getParsedSet($entity, $set);
if ($data === null) { if ($data === null) {
throw new Exception('No metadata for set "'.$set.'" available from "'.$index.'".'); throw new \Exception(__CLASS__.': no metadata for set "'.$set.'" available from "'.$index.'".');
} }
$this->writeToCache($set, $index, $data); $this->writeToCache($set, $index, $data);
return $data; return $data;
} }
} }
...@@ -22,6 +22,16 @@ function temporaryLoader($class) ...@@ -22,6 +22,16 @@ function temporaryLoader($class)
if (!strstr($class, 'SimpleSAML_')) { if (!strstr($class, 'SimpleSAML_')) {
return; // not a valid class name for old classes return; // not a valid class name for old classes
} }
$original = $class;
// list of classes that have been renamed or moved
$renamed = array(
'SimpleSAML_Metadata_MetaDataStorageHandlerMDX' => 'SimpleSAML_Metadata_Sources_MDQ',
);
if (array_key_exists($class, $renamed)) {
// the class has been renamed, try to load it and create an alias
$class = $renamed[$class];
}
// try to load it from the corresponding file // try to load it from the corresponding file
$path = explode('_', $class); $path = explode('_', $class);
...@@ -39,8 +49,8 @@ function temporaryLoader($class) ...@@ -39,8 +49,8 @@ function temporaryLoader($class)
$new = join('\\', $path); $new = join('\\', $path);
if (class_exists($new, false) || interface_exists($new, false)) { if (class_exists($new, false) || interface_exists($new, false)) {
// do not try to autoload it if it doesn't exist! It should! // do not try to autoload it if it doesn't exist! It should!
class_alias($new, $class); class_alias($new, $original);
SimpleSAML\Logger::warning("The class or interface '$class' is now using namespaces, please use '$new'."); SimpleSAML\Logger::warning("The class or interface '$original' is now using namespaces, please use '$new'.");
} }
} }
......
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