From 1c37632ecd98983cf52386376777edfbea88acb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Wed, 7 Jan 2009 10:06:33 +0000
Subject: [PATCH] Support for adding "tags" in SAML 2.0 metadata Extensions

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1085 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Metadata/SAMLBuilder.php | 29 ++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php
index 998f3aa62..b04bbf16f 100644
--- a/lib/SimpleSAML/Metadata/SAMLBuilder.php
+++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php
@@ -10,6 +10,8 @@
  */
 class SimpleSAML_Metadata_SAMLBuilder {
 
+
+
 	/**
 	 * The DOMDocument we are working in.
 	 */
@@ -68,6 +70,24 @@ class SimpleSAML_Metadata_SAMLBuilder {
 	}
 	
 	
+	private function addExtensions($metadata) {
+		$extensions = $this->createElement('Extensions'); 
+#		$extensions->setAttribute('xmlns:saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
+		
+		if (array_key_exists('tags', $metadata)) {
+			$attr = $this->createElement('saml:Attribute', 'urn:oasis:names:tc:SAML:2.0:assertion');
+			$attr->setAttribute('Name', 'tags');
+			foreach ($metadata['tags'] AS $tag) {
+				$attr->appendChild($this->createTextElement('saml:AttributeValue', $tag));
+			}
+			$extensions->appendChild($attr);
+		}
+		
+		
+		$this->entityDescriptor->appendChild($extensions);
+	}
+
+
 	
 	private function addOrganizationInfo($metadata) {
 		if (array_key_exists('name', $metadata)) {
@@ -156,6 +176,9 @@ class SimpleSAML_Metadata_SAMLBuilder {
 
 		$e = $this->createElement('SPSSODescriptor');
 		$e->setAttribute('protocolSupportEnumeration', 'urn:oasis:names:tc:SAML:2.0:protocol');
+		
+		
+		$this->addExtensions($metadata);
 
 		$this->addCertificate($e, $metadata);
 
@@ -476,10 +499,10 @@ class SimpleSAML_Metadata_SAMLBuilder {
 	 * @param string $name  The name of the DOMElement.
 	 * @return DOMElement  The new DOMElement.
 	 */
-	private function createElement($name) {
+	private function createElement($name, $ns = 'urn:oasis:names:tc:SAML:2.0:metadata') {
 		assert('is_string($name)');
-
-		return $this->document->createElementNS('urn:oasis:names:tc:SAML:2.0:metadata', $name);
+		assert('is_string($ns)');
+		return $this->document->createElementNS($ns, $name);
 	}
 
 
-- 
GitLab