From 38f7bcbe685dc3574462ac361e13e5aad987840c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20P=C3=A9rez=20Crespo?= <jaime.perez@uninett.no>
Date: Mon, 25 Nov 2013 16:01:14 +0000
Subject: [PATCH] Make SimpleSAML_Configuration::getDefaultEndpoint to
 prioritize certain bindings for SingleLogoutService endpoints.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3300 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Configuration.php | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php
index f4640bd1f..ff376551f 100644
--- a/lib/SimpleSAML/Configuration.php
+++ b/lib/SimpleSAML/Configuration.php
@@ -995,6 +995,31 @@ class SimpleSAML_Configuration {
 		assert('is_string($endpointType)');
 
 		$endpoints = $this->getEndpoints($endpointType);
+
+		// SingleLogoutService is not an IndexedEndpointType, so we are free to choose the default.
+		if ($endpointType === "SingleLogoutService") {
+			
+
+			$eps = array();
+			foreach ($endpoints as $ep) {
+				if ($bindings !== NULL && !in_array($ep['Binding'], $bindings, TRUE)) {
+					/* Unsupported binding. Skip it. */
+					continue;
+				}
+				$eps[$ep['Binding']] = $ep;
+			}
+
+			// We will apply the following order:
+			// 1st: SAML2_Const::BINDING_SOAP
+			// 2nd: SAML2_Const::BINDING_HTTP_REDIRECT
+			if (isset($eps[SAML2_Const::BINDING_SOAP])) {
+				return $eps[SAML2_Const::BINDING_SOAP];
+			}
+			if (isset($eps[SAML2_Const::BINDING_HTTP_REDIRECT])) {
+				return $eps[SAML2_Const::BINDING_HTTP_REDIRECT];
+			}
+		}
+
 		$defaultEndpoint = SimpleSAML_Utilities::getDefaultEndpoint($endpoints, $bindings);
 		if ($defaultEndpoint !== NULL) {
 			return $defaultEndpoint;
-- 
GitLab