From 60ec160eb782414726d5c4cd4b657fcb0c7a7530 Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Thu, 23 Apr 2015 10:50:59 +0200
Subject: [PATCH] Move SimpleSAML_Utilities:: checkCookie() to
 SimpleSAML\Utils\HTTP::checkSessionCookie() and deprecate the former.

---
 lib/SimpleSAML/Utilities.php   | 19 ++-----------------
 lib/SimpleSAML/Utils/HTTP.php  | 32 ++++++++++++++++++++++++++++++++
 modules/saml/lib/IdP/SAML1.php |  2 +-
 modules/saml/lib/IdP/SAML2.php |  2 +-
 4 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 4d22a7bf6..a0a968dc2 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -875,25 +875,10 @@ class SimpleSAML_Utilities {
 
 
 	/**
-	 * Check for session cookie, and show missing-cookie page if it is missing.
-	 *
-	 * @param string|NULL $retryURL  The URL the user should access to retry the operation.
+	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::checkSessionCookie() instead.
 	 */
 	public static function checkCookie($retryURL = NULL) {
-		assert('is_string($retryURL) || is_null($retryURL)');
-
-		$session = SimpleSAML_Session::getSessionFromRequest();
-		if ($session->hasSessionCookie()) {
-			return;
-		}
-
-		/* We didn't have a session cookie. Redirect to the no-cookie page. */
-
-		$url = SimpleSAML_Module::getModuleURL('core/no_cookie.php');
-		if ($retryURL !== NULL) {
-			$url = self::addURLParameter($url, array('retryURL' => $retryURL));
-		}
-		self::redirectTrustedURL($url);
+		return \SimpleSAML\Utils\HTTP::checkSessionCookie($retryURL);
 	}
 
 
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index c981f16e2..1c80fb8ed 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -258,6 +258,38 @@ class HTTP
     }
 
 
+    /**
+     * Check for session cookie, and show missing-cookie page if it is missing.
+     *
+     * @param string|NULL $retryURL The URL the user should access to retry the operation. Defaults to null.
+     *
+     * @return void If there is a session cookie, nothing will be returned. Otherwise, the user will be redirected to a
+     *     page telling about the missing cookie.
+     * @throws \SimpleSAML_Error_Exception If $retryURL is neither a string nor null.
+     *
+     * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+     */
+    public static function checkSessionCookie($retryURL = null)
+    {
+        if (!is_string($retryURL) || !is_null($retryURL)) {
+            throw new \SimpleSAML_Error_Exception('Invalid input parameters.');
+        }
+
+        $session = \SimpleSAML_Session::getSessionFromRequest();
+        if ($session->hasSessionCookie()) {
+            return;
+        }
+
+        // we didn't have a session cookie. Redirect to the no-cookie page
+
+        $url = \SimpleSAML_Module::getModuleURL('core/no_cookie.php');
+        if ($retryURL !== null) {
+            $url = self::addURLParameters($url, array('retryURL' => $retryURL));
+        }
+        self::redirectTrustedURL($url);
+    }
+
+
     /**
      * Check if a URL is valid and is in our list of allowed URLs.
      *
diff --git a/modules/saml/lib/IdP/SAML1.php b/modules/saml/lib/IdP/SAML1.php
index 2cd520bec..be2e1de40 100644
--- a/modules/saml/lib/IdP/SAML1.php
+++ b/modules/saml/lib/IdP/SAML1.php
@@ -69,7 +69,7 @@ class sspmod_saml_IdP_SAML1 {
 				 * Less than five seconds has passed since we were
 				 * here the last time. Cookies are probably disabled.
 				 */
-				SimpleSAML_Utilities::checkCookie(\SimpleSAML\Utils\HTTP::getSelfURL());
+				\SimpleSAML\Utils\HTTP::checkCookie(\SimpleSAML\Utils\HTTP::getSelfURL());
 			}
 		}
 
diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php
index cc4271df6..e22edad12 100644
--- a/modules/saml/lib/IdP/SAML2.php
+++ b/modules/saml/lib/IdP/SAML2.php
@@ -247,7 +247,7 @@ class sspmod_saml_IdP_SAML2 {
 					 * Less than five seconds has passed since we were
 					 * here the last time. Cookies are probably disabled.
 					 */
-					SimpleSAML_Utilities::checkCookie(\SimpleSAML\Utils\HTTP::getSelfURL());
+					\SimpleSAML\Utils\HTTP::checkCookie(\SimpleSAML\Utils\HTTP::getSelfURL());
 				}
 			}
 
-- 
GitLab