diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 4d22a7bf6f01f2b24398d25e6502a4177f763490..a0a968dc2f1ea29e39eb62382661bdd948e9d11d 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 c981f16e2258c098029bbdaaf6dbeb938eae181a..1c80fb8edda8eef9193db10c6ff6a1bba5787cd4 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 2cd520becdace56ee5667968f17365b8830aae6d..be2e1de407e99cb3e8c5e63b93fe8a84395d5014 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 cc4271df6bf63b42fd877cc7b64cf36f38594153..e22edad12a2f080a242e42487983dc8457925358 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()); } }