From 62160070fd314c843ec3da3b8df0d4cd2908eec0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Thu, 7 Jan 2010 10:35:58 +0000
Subject: [PATCH] Fix for new endpoint format for the metaedit module...

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2079 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/metaedit/lib/MetaEditor.php | 34 +++++++++++++++++++++++++----
 modules/metaedit/www/edit.php       |  4 +++-
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/modules/metaedit/lib/MetaEditor.php b/modules/metaedit/lib/MetaEditor.php
index ac83b235d..73049f503 100644
--- a/modules/metaedit/lib/MetaEditor.php
+++ b/modules/metaedit/lib/MetaEditor.php
@@ -17,13 +17,22 @@ class sspmod_metaedit_MetaEditor {
 			if (isset($metadata[$key])) unset($metadata[$key]);
 		}
 	}
+	
+	protected function getEndpointField($request, &$metadata, $key) {
+		if (array_key_exists('field_' . $key, $request)) {
+			$e = array('Binding' => SAML2_Const::BINDING_HTTP_REDIRECT, 'Location' => $request['field_' . $key], 'index' => '0');
+			$metadata[$key] = $e;
+		} else {
+			if (isset($metadata[$key])) unset($metadata[$key]);
+		}
+	}
 
 	public function formToMeta($request, $metadata = array(), $override = NULL) {
 		$this->getStandardField($request, $metadata, 'entityid');
 		$this->getStandardField($request, $metadata, 'name');
 		$this->getStandardField($request, $metadata, 'description');
-		$this->getStandardField($request, $metadata, 'AssertionConsumerService');
-		$this->getStandardField($request, $metadata, 'SingleLogoutService');
+		$this->getEndpointField($request, $metadata, 'AssertionConsumerService');
+		$this->getEndpointField($request, $metadata, 'SingleLogoutService');
 		// $this->getStandardField($request, $metadata, 'certFingerprint');
 		$metadata['updated'] = time();
 		
@@ -106,6 +115,23 @@ class sspmod_metaedit_MetaEditor {
 			
 		}
 	}
+	
+	protected function endpointField($metadata, $key, $name, $textarea = FALSE) {
+		$value = '';
+		if (array_key_exists($key, $metadata)) {
+			$value = htmlspecialchars($metadata[$key]['Location']);
+		}
+		
+		if ($textarea) {
+			return '<tr><td class="name">' . $name . '</td><td class="data">
+			<textarea name="field_' . $key . '" rows="5" cols="50">' . $value . '</textarea></td></tr>';
+			
+		} else {
+			return '<tr><td class="name">' . $name . '</td><td class="data">
+			<input type="text" size="60" name="field_' . $key . '" value="' . $value . '" /></td></tr>';
+			
+		}
+	}
 
 	public function metaToForm($metadata) {
 		$this->flattenLanguageField($metadata, 'name');
@@ -133,8 +159,8 @@ class sspmod_metaedit_MetaEditor {
 				$this->readonlyDateField($metadata, 'expire', 'Expire') .
 
 			'</table></div><div id="saml"><table class="formtable">' .
-				$this->standardField($metadata, 'AssertionConsumerService', 'AssertionConsumerService endpoint') .
-				$this->standardField($metadata, 'SingleLogoutService', 'SingleLogoutService endpoint') .
+				$this->endpointField($metadata, 'AssertionConsumerService', 'AssertionConsumerService endpoint') .
+				$this->endpointField($metadata, 'SingleLogoutService', 'SingleLogoutService endpoint') .
 				// $this->standardField($metadata, 'certFingerprint', 'Certificate Fingerprint') .			
 				
 			'</table></div>' .
diff --git a/modules/metaedit/www/edit.php b/modules/metaedit/www/edit.php
index f8f47917a..d8079784b 100644
--- a/modules/metaedit/www/edit.php
+++ b/modules/metaedit/www/edit.php
@@ -41,7 +41,9 @@ if (array_key_exists('entityid', $_REQUEST)) {
 
 	/* Trim metadata endpoint arrays. */
 	$metadata['AssertionConsumerService'] = SimpleSAML_Utilities::getDefaultEndpoint($metadata['AssertionConsumerService'], array(SAML2_Const::BINDING_HTTP_POST));
-	$metadata['SingleLoogutService'] = SimpleSAML_Utilities::getDefaultEndpoint($metadata['SingleLogoutService'], array(SAML2_Const::BINDING_HTTP_REDIRECT));
+	$metadata['SingleLogoutService'] = SimpleSAML_Utilities::getDefaultEndpoint($metadata['SingleLogoutService'], array(SAML2_Const::BINDING_HTTP_REDIRECT));
+
+	#echo '<pre>'; print_r($metadata); exit;
 
 } else {
 	$metadata = array(
-- 
GitLab