From 6794f43f656bee86212ae6d8372851d7cdc752fb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Fri, 26 Oct 2007 12:30:19 +0000
Subject: [PATCH] Adding getRedirectURL() functionality

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@58 44740490-163a-0410-bde0-09ae8108e29a
---
 .../Bindings/SAML20/HTTPRedirect.php           | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
index 0d1dc310f..fc37858e6 100644
--- a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
+++ b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
@@ -29,7 +29,8 @@ class SimpleSAML_Bindings_SAML20_HTTPRedirect {
 		$this->metadata = $metadatastore;
 	}
 	
-	public function sendMessage($request, $remoteentityid, $relayState = null, $endpoint = 'SingleSignOnService', $direction = 'SAMLRequest', $mode = 'SP') {
+	public function getRedirectURL($request, $remoteentityid, $relayState = null, $endpoint = 'SingleSignOnService', $direction = 'SAMLRequest', $mode = 'SP') {
+	
 		if (!in_array($mode, array('SP', 'IdP'))) {
 			throw new Exception('mode parameter of sendMessage() must be either SP or IdP');
 		}
@@ -39,7 +40,12 @@ class SimpleSAML_Bindings_SAML20_HTTPRedirect {
 		}
 
 		$md = $this->metadata->getMetaData($remoteentityid, $metadataset);
-		$idpTargetUrl = $md[$endpoint];
+		
+		$realendpoint = $endpoint;
+		if ($endpoint == 'SingleLogoutServiceResponse' && !isset($md[$endpoint])) 
+			$realendpoint = 'SingleLogoutService';
+		
+		$idpTargetUrl = $md[$realendpoint];
 		
 		if (!isset($idpTargetUrl) or $idpTargetUrl == '') {
 			throw new Exception('Could not find endpoint [' .$endpoint  . '] in metadata for [' . $remoteentityid . '] (looking in ' . $metadataset . ')');
@@ -51,6 +57,14 @@ class SimpleSAML_Bindings_SAML20_HTTPRedirect {
 		if (isset($relayState)) {
 			$redirectURL .= "&RelayState=" . urlencode($relayState);
 		}
+		return $redirectURL;
+	
+	}
+	
+	
+	public function sendMessage($request, $remoteentityid, $relayState = null, $endpoint = 'SingleSignOnService', $direction = 'SAMLRequest', $mode = 'SP') {
+		
+		$redirectURL = $this->getRedirectURL($request, $remoteentityid, $relayState, $endpoint, $direction, $mode);
 		
 		if ($this->configuration->getValue('debug')) {
 	
-- 
GitLab