From 5657c3c2176263b323e5884572c855d63e79e5b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Tue, 16 Jun 2009 11:50:53 +0000
Subject: [PATCH] Support retrieving subset of all metadata + fix typo in
 configuration file + more robust http metadata download

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1524 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Metadata/SAMLParser.php        |  2 +-
 .../config-templates/aggregator.php           |  2 +-
 modules/aggregator/www/index.php              | 30 +++++++++++++------
 modules/metarefresh/lib/MetaLoader.php        |  9 ++++--
 4 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index ed7f9559c..1cae3e4c4 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -272,7 +272,7 @@ class SimpleSAML_Metadata_SAMLParser {
 
 		$doc = new DOMDocument();
 
-		$res = $doc->load($file);
+		$res = @$doc->load($file);
 		if($res !== TRUE) {
 			throw new Exception('Failed to read XML from file: ' . $file);
 		}
diff --git a/modules/aggregator/config-templates/aggregator.php b/modules/aggregator/config-templates/aggregator.php
index 868ced2a5..e17552425 100644
--- a/modules/aggregator/config-templates/aggregator.php
+++ b/modules/aggregator/config-templates/aggregator.php
@@ -4,7 +4,7 @@
 $config = array(
 
 	/* List of aggregators. */
-	'aggragators' => array(
+	'aggregators' => array(
 		'example' => array(
 			array('type' => 'flatfile'),  /* Metadata from metadata-directory. */
 			array('type' => 'xml', 'url' => 'https://idp.example.org/Metadata'),
diff --git a/modules/aggregator/www/index.php b/modules/aggregator/www/index.php
index aa1e88eab..282aa97f5 100644
--- a/modules/aggregator/www/index.php
+++ b/modules/aggregator/www/index.php
@@ -1,19 +1,31 @@
 <?php
 
-/* Types of metadata. */
-$metadataSets = array(
-	'saml20-idp-remote',
-	'saml20-sp-remote',
-	'shib13-idp-remote',
-	'shib13-sp-remote',
-	);
-
 $globalConfig = SimpleSAML_Configuration::getInstance();
 $aggregatorConfig = SimpleSAML_Configuration::getConfig('aggregator.php');
 
 
 $reconstruct = $aggregatorConfig->getBoolean('reconstruct', FALSE);
-$aggregators = $aggregatorConfig->getArray('aggragators');
+$aggregators = $aggregatorConfig->getArray('aggregators');
+
+$metadataSets = array('saml20-idp-remote', 'saml20-sp-remote', 'shib13-idp-remote', 'shib13-sp-remote');
+if ($aggregatorConfig->hasValue('default-set')) {
+	$metadataSets = $aggregatorConfig->getArray('default-set');
+}
+if (isset($_REQUEST['set'])) {
+	switch($_REQUEST) {
+		case 'saml2' :
+			$metadataSets = array('saml20-idp-remote', 'saml20-sp-remote'); break;
+		case 'shib13' :
+			$metadataSets = array('shib13-idp-remote', 'shib13-sp-remote'); break;
+		case 'idp' :
+			$metadataSets = array('saml20-idp-remote', 'shib13-idp-remote'); break;
+		case 'sp' :
+			$metadataSets = array('saml20-sp-remote', 'shib13-sp-remote'); break;
+		
+		default:
+			$metadataSets = array($_REQUEST['set']);
+	}
+}
 
 if (!array_key_exists('id', $_GET)) {
 	$t = new SimpleSAML_XHTML_Template($globalConfig, 'aggregator:list.php');
diff --git a/modules/metarefresh/lib/MetaLoader.php b/modules/metarefresh/lib/MetaLoader.php
index a9949a070..83e181ba2 100644
--- a/modules/metarefresh/lib/MetaLoader.php
+++ b/modules/metarefresh/lib/MetaLoader.php
@@ -29,8 +29,13 @@ class sspmod_metarefresh_MetaLoader {
 	 * @param $src  Filename of the metadata file.
 	 */
 	public function loadSource($source) {
-
-		$entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($source['src']);
+		
+		$entities = array();
+		try {
+			$entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($source['src']);
+		} catch(Exception $e) {
+			SimpleSAML_Logger::warning('metarefresh: Failed to retrieve metadata. ' . $e->getMessage());
+		}
 		$ca = NULL;
 		foreach($entities as $entity) {
 			if(array_key_exists('validateFingerprint', $source) && $source['validateFingerprint'] !== NULL) {
-- 
GitLab