From 5ee2e408018a837ae8eaccc09dc2ff40863af8b9 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 2 Sep 2009 06:45:48 +0000
Subject: [PATCH] Handle missing SP metadata in iframe logout.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1737 44740490-163a-0410-bde0-09ae8108e29a
---
 www/saml2/idp/SingleLogoutServiceiFrame.php | 24 +++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/www/saml2/idp/SingleLogoutServiceiFrame.php b/www/saml2/idp/SingleLogoutServiceiFrame.php
index 4202c1a56..2a8a50b0b 100644
--- a/www/saml2/idp/SingleLogoutServiceiFrame.php
+++ b/www/saml2/idp/SingleLogoutServiceiFrame.php
@@ -123,7 +123,17 @@ function updateslostatus() {
 		// add a command to the response to assign the innerHTML attribute of
 		// the element with id="SomeElementId" to whatever the new content is
 		
-		$spmetadata = $metadata->getMetaData($spentityid, 'saml20-sp-remote');
+		try {
+			$spmetadata = $metadata->getMetaData($spentityid, 'saml20-sp-remote');
+		} catch (Exception $e) {
+			/*
+			 * For some reason, the metadata for this SP is no longer available. Most
+			 * likely it was deleted from the IdP while the user had a session to it.
+			 * In any case - skip this SP.
+			 */
+			continue;
+		}
+
 		$name = array_key_exists('name', $spmetadata) ? $spmetadata['name'] : $spentityid;
 		
 		$spname = is_array($name) ? $t->getTranslation($name) : $name;
@@ -265,7 +275,17 @@ foreach ($listofsps AS $spentityid) {
 		$nameId = $session->getNameID();
 	}
 
-	$spMetadata = $metadata->getMetaDataConfig($spentityid, 'saml20-sp-remote');
+	try {
+		$spMetadata = $metadata->getMetaDataConfig($spentityid, 'saml20-sp-remote');
+	} catch (Exception $e) {
+		/*
+		 * For some reason, the metadata for this SP is no longer available. Most
+		 * likely it was deleted from the IdP while the user had a session to it.
+		 * In any case - skip this SP.
+		 */
+		continue;
+	}
+
 	$name = $spMetadata->getValue('name', $spentityid);
 
 	try {
-- 
GitLab