From 30e94d22bda3843f3ed241c62221a9a638d51394 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Wed, 22 Jul 2015 17:50:24 +0200 Subject: [PATCH] Allow to specify which metadata sets to use in metarefresh. Can be configured either per set or per source. --- modules/metarefresh/hooks/hook_cron.php | 17 +++++++++++ modules/metarefresh/lib/MetaLoader.php | 40 ++++++++++++++++++++++--- modules/metarefresh/www/fetch.php | 17 +++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/modules/metarefresh/hooks/hook_cron.php b/modules/metarefresh/hooks/hook_cron.php index f1a0512c7..9f18ffea4 100644 --- a/modules/metarefresh/hooks/hook_cron.php +++ b/modules/metarefresh/hooks/hook_cron.php @@ -48,8 +48,25 @@ function metarefresh_hook_cron(&$croninfo) { $whitelist = $mconfig->getArray('whitelist', array()); $conditionalGET = $mconfig->getBoolean('conditionalGET', FALSE); + // get global type filters + $available_types = array( + 'saml20-idp-remote', + 'saml20-sp-remote', + 'shib13-idp-remote', + 'shib13-sp-remote', + 'attributeauthority-remote' + ); + $set_types = $set->getArrayize('types', $available_types); + foreach($set->getArray('sources') AS $source) { + // filter metadata by type of entity + if (isset($source['types'])) { + $metaloader->setTypes($source['types']); + } else { + $metaloader->setTypes($set_types); + } + # Merge global and src specific blacklists if(isset($source['blacklist'])) { $source['blacklist'] = array_unique(array_merge($source['blacklist'], $blacklist)); diff --git a/modules/metarefresh/lib/MetaLoader.php b/modules/metarefresh/lib/MetaLoader.php index 3f09817ea..91f505e28 100644 --- a/modules/metarefresh/lib/MetaLoader.php +++ b/modules/metarefresh/lib/MetaLoader.php @@ -11,8 +11,13 @@ class sspmod_metarefresh_MetaLoader { private $oldMetadataSrc; private $stateFile; private $changed; - private static $types = array('saml20-idp-remote', 'saml20-sp-remote', - 'shib13-idp-remote', 'shib13-sp-remote', 'attributeauthority-remote'); + private $types = array( + 'saml20-idp-remote', + 'saml20-sp-remote', + 'shib13-idp-remote', + 'shib13-sp-remote', + 'attributeauthority-remote' + ); /** @@ -37,6 +42,33 @@ class sspmod_metarefresh_MetaLoader { } + + /** + * Get the types of entities that will be loaded. + * + * @return array The entity types allowed. + */ + public function getTypes() + { + return $this->types; + } + + + /** + * Set the types of entities that will be loaded. + * + * @param string|array $types Either a string with the name of one single type allowed, or an array with a list of + * types. Pass an empty array to reset to all types of entities. + */ + public function setTypes($types) + { + if (!is_array($types)) { + $types = array($types); + } + $this->types = $types; + } + + /** * This function processes a SAML metadata file. * @@ -176,7 +208,7 @@ class sspmod_metarefresh_MetaLoader { private function addCachedMetadata($source) { if(isset($this->oldMetadataSrc)) { - foreach(self::$types as $type) { + foreach($this->types as $type) { foreach($this->oldMetadataSrc->getMetadataSet($type) as $entity) { if(array_key_exists('metarefresh:src', $entity)) { if($entity['metarefresh:src'] == $source['src']) { @@ -369,7 +401,7 @@ class sspmod_metarefresh_MetaLoader { } } - foreach(self::$types as $type) { + foreach($this->types as $type) { $filename = $outputDir . '/' . $type . '.php'; diff --git a/modules/metarefresh/www/fetch.php b/modules/metarefresh/www/fetch.php index 322c34408..5f8cb282a 100644 --- a/modules/metarefresh/www/fetch.php +++ b/modules/metarefresh/www/fetch.php @@ -30,8 +30,25 @@ foreach ($sets AS $setkey => $set) { $blacklist = $mconfig->getArray('blacklist', array()); $whitelist = $mconfig->getArray('whitelist', array()); + // get global type filters + $available_types = array( + 'saml20-idp-remote', + 'saml20-sp-remote', + 'shib13-idp-remote', + 'shib13-sp-remote', + 'attributeauthority-remote' + ); + $set_types = $set->getArrayize('types', $available_types); + foreach($set->getArray('sources') AS $source) { + // filter metadata by type of entity + if (isset($source['types'])) { + $metaloader->setTypes($source['types']); + } else { + $metaloader->setTypes($set_types); + } + # Merge global and src specific blacklists if(isset($source['blacklist'])) { $source['blacklist'] = array_unique(array_merge($source['blacklist'], $blacklist)); -- GitLab