From fc1e909426e7c47fb0efb868cc9d125bfd679e6f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Mon, 7 Jan 2008 15:12:16 +0000
Subject: [PATCH] Copied the flat file metadata handler to a new SAML2 Meta
 data class. For now, just a copy, will implement this class tomorrow.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@144 44740490-163a-0410-bde0-09ae8108e29a
---
 .../MetaDataStorageHandlerSAML2Meta.php       | 94 +++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 lib/SimpleSAML/Metadata/MetaDataStorageHandlerSAML2Meta.php

diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSAML2Meta.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSAML2Meta.php
new file mode 100644
index 000000000..16497ea73
--- /dev/null
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSAML2Meta.php
@@ -0,0 +1,94 @@
+<?php
+
+/*
+ * This file is part of simpleSAMLphp. See the file COPYING in the
+ * root of the distribution for licence information.
+ *
+ * This file defines a base class for metadata handling.
+ * Instantiation of session handler objects should be done through
+ * the class method getMetadataHandler().
+ */
+
+require_once('SimpleSAML/Configuration.php');
+require_once('SimpleSAML/Utilities.php');
+require_once('SimpleSAML/Metadata/MetaDataStorageHandler.php');
+
+/**
+ * Configuration of SimpleSAMLphp
+ */
+class MetaDataStorageHandlerSAML2Meta extends SimpleSAML_Metadata_MetaDataStorageHandler {
+
+
+
+
+
+	/* This constructor is included in case it is needed in the the
+	 * future. Including it now allows us to write parent::__construct() in
+	 * the subclasses of this class.
+	 */
+	protected function __construct() {
+	}
+
+
+
+	public function load($set) {
+		$metadata = null;
+		if (!in_array($set, array(
+			'saml20-sp-hosted', 'saml20-sp-remote','saml20-idp-hosted', 'saml20-idp-remote',
+			'shib13-sp-hosted', 'shib13-sp-remote', 'shib13-idp-hosted', 'shib13-idp-remote',
+			'openid-provider'))) {
+				throw new Exception('Trying to load illegal set of Meta data [' . $set . ']');
+		}
+		
+		/* Get the configuration. */
+		$config = SimpleSAML_Configuration::getInstance();
+		assert($config instanceof SimpleSAML_Configuration);
+		
+		$metadatasetfile = $config->getBaseDir() . '/' . 
+			$config->getValue('metadatadir') . '/' . $set . '.php';
+		
+		
+		if (!file_exists($metadatasetfile)) {
+			throw new Exception('Could not open file: ' . $metadatasetfile);
+		}
+		include($metadatasetfile);
+		
+		if (!is_array($metadata)) {
+			throw new Exception('Could not load metadata set [' . $set . '] from file: ' . $metadatasetfile);
+		}
+		foreach ($metadata AS $key => $entry) { 
+			$this->metadata[$set][$key] = $entry;
+			$this->metadata[$set][$key]['entityid'] = $key;
+			
+			if (isset($entry['host'])) {
+				$this->hostmap[$set][$entry['host']] = $key;
+			}
+			
+		}
+
+	}
+
+	
+	public function getMetaData($entityid = null, $set = 'saml20-sp-hosted') {
+		if (!isset($entityid)) {
+			return $this->getMetaDataCurrent($set);
+		}
+		
+		//echo 'find metadata for entityid [' . $entityid . '] in metadata set [' . $set . ']';
+		
+		if (!isset($this->metadata[$set])) {
+			$this->load($set);
+		}
+		if (!isset($this->metadata[$set][$entityid]) ) {
+			throw new Exception('Could not find metadata for entityid [' . $entityid . '] in metadata set [' . $set . ']');
+		}
+		return $this->metadata[$set][$entityid];
+	}
+	
+
+
+	
+	
+}
+
+?>
\ No newline at end of file
-- 
GitLab