From 1e2e25d73b8d49a196fa903f63b42c4dce77a8b0 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 12:21:32 +0000
Subject: [PATCH] Adding cidr hints as Metadata Extensions and added extension
 handling on idp as well as sp

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1087 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Metadata/SAMLBuilder.php | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php
index 756700c85..116843bf1 100644
--- a/lib/SimpleSAML/Metadata/SAMLBuilder.php
+++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php
@@ -83,6 +83,18 @@ class SimpleSAML_Metadata_SAMLBuilder {
 			}
 			$extensions->appendChild($attr);
 		}
+
+		if (array_key_exists('hint.cidr', $metadata)) {
+			$includeExtensions = TRUE;
+			$attr = $this->createElement('saml:Attribute', 'urn:oasis:names:tc:SAML:2.0:assertion');
+			$attr->setAttribute('Name', 'hint.cidr');
+			$hints = self::arrayize($metadata['hint.cidr']);
+			foreach ($hints AS $hint) {
+				$attr->appendChild($this->createTextElement('saml:AttributeValue', $hint));
+			}
+			$extensions->appendChild($attr);
+		}
+
 		
 		if (array_key_exists('scope', $metadata)) {
 			$includeExtensions = TRUE;
@@ -92,10 +104,17 @@ class SimpleSAML_Metadata_SAMLBuilder {
 				$scope->appendChild($this->document->createTextNode($scopetext));
 				$extensions->appendChild($scope);
 			}
-
 		}
 		if ($includeExtensions) $this->entityDescriptor->appendChild($extensions);
 	}
+	
+	public static function arrayize($data) {
+		if (is_array($data)) {
+			return $data;
+		} else {
+			return array($data);
+		}
+	}
 
 
 	
@@ -308,6 +327,8 @@ class SimpleSAML_Metadata_SAMLBuilder {
 		if (array_key_exists('redirect.sign', $metadata) && $metadata['redirect.sign']) {
 			$e->setAttribute('WantAuthnRequestSigned', 'true');
 		}
+		
+		$this->addExtensions($metadata);
 
 		$this->addCertificate($e, $metadata);
 
-- 
GitLab