From 8c2e7a2c871aebe4a9ded1d2185b5df93748ef94 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Mon, 12 Oct 2009 14:00:17 +0000
Subject: [PATCH] SAMLBuilder: Handle multiple ACS endpoints.

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

diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php
index e5411828a..87702af25 100644
--- a/lib/SimpleSAML/Metadata/SAMLBuilder.php
+++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php
@@ -263,22 +263,27 @@ class SimpleSAML_Metadata_SAMLBuilder {
 			$e->appendChild($t);
 		}
 
+		$acsIndex = 0;
 		if (array_key_exists('AssertionConsumerService', $metadata)) {
-			$index = 0;
-			if (array_key_exists('AssertionConsumerService.artifact', $metadata)) {
+			foreach (SimpleSAML_Utilities::arrayize($metadata['AssertionConsumerService']) as $acs) {
 				$t = $this->createElement('AssertionConsumerService');
-				$t->setAttribute('index', (string)$index);
+				$t->setAttribute('index', (string)$acsIndex);
+				$t->setAttribute('Binding', 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST');
+				$t->setAttribute('Location', $acs);
+				$e->appendChild($t);
+				$acsIndex += 1;
+			}
+		}
+		if (array_key_exists('AssertionConsumerService.artifact', $metadata)) {
+			foreach (SimpleSAML_Utilities::arrayize($metadata['AssertionConsumerService.artifact']) as $acs) {
+				$t = $this->createElement('AssertionConsumerService');
+				$t->setAttribute('index', (string)$acsIndex);
 				$t->setAttribute('Binding', 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact');
-				$t->setAttribute('Location', $metadata['AssertionConsumerService.artifact']);
+				$t->setAttribute('Location', $acs);
 				$e->appendChild($t);
-				$index++;
+				$acsIndex += 1;
 			}
 
-			$t = $this->createElement('AssertionConsumerService');
-			$t->setAttribute('index', (string)$index);
-			$t->setAttribute('Binding', 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST');
-			$t->setAttribute('Location', $metadata['AssertionConsumerService']);
-			$e->appendChild($t);
 		}
 
 
@@ -425,23 +430,27 @@ class SimpleSAML_Metadata_SAMLBuilder {
 			$e->appendChild($t);
 		}
 
+		$acsIndex = 0;
 		if (array_key_exists('AssertionConsumerService', $metadata)) {
-
-			$index = 0;
-			if (array_key_exists('AssertionConsumerService.artifact', $metadata)) {
+			foreach (SimpleSAML_Utilities::arrayize($metadata['AssertionConsumerService']) as $acs) {
 				$t = $this->createElement('AssertionConsumerService');
-				$t->setAttribute('index', (string)$index);
+				$t->setAttribute('index', (string)$acsIndex);
+				$t->setAttribute('Binding', 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post');
+				$t->setAttribute('Location', $acs);
+				$e->appendChild($t);
+				$acsIndex += 1;
+			}
+		}
+		if (array_key_exists('AssertionConsumerService.artifact', $metadata)) {
+			foreach (SimpleSAML_Utilities::arrayize($metadata['AssertionConsumerService.artifact']) as $acs) {
+				$t = $this->createElement('AssertionConsumerService');
+				$t->setAttribute('index', (string)$acsIndex);
 				$t->setAttribute('Binding', 'urn:oasis:names:tc:SAML:1.0:profiles:artifact-01');
-				$t->setAttribute('Location', $metadata['AssertionConsumerService.artifact']);
+				$t->setAttribute('Location', $acs);
 				$e->appendChild($t);
-				$index++;
+				$acsIndex += 1;
 			}
-			
-			$t = $this->createElement('AssertionConsumerService');
-			$t->setAttribute('index', (string)$index);
-			$t->setAttribute('Binding', 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post');
-			$t->setAttribute('Location', $metadata['AssertionConsumerService']);
-			$e->appendChild($t);
+
 		}
 
 		$this->entityDescriptor->appendChild($e);
-- 
GitLab