From cddb7d91015669ad8998715751bde2fbd5be49b6 Mon Sep 17 00:00:00 2001 From: Andjelko Horvat <comel@vingd.com> Date: Fri, 13 Sep 2013 11:03:54 +0000 Subject: [PATCH] Add SimpleSAML_SessionHandler::getSessionCookieName() (patch 1 from issue #571). git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3275 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/SessionHandler.php | 8 ++++++++ lib/SimpleSAML/SessionHandlerCookie.php | 11 +++++++++++ lib/SimpleSAML/SessionHandlerPHP.php | 26 +++++++++++++++++++++---- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/SimpleSAML/SessionHandler.php b/lib/SimpleSAML/SessionHandler.php index 2d1a28c90..1a44c559b 100644 --- a/lib/SimpleSAML/SessionHandler.php +++ b/lib/SimpleSAML/SessionHandler.php @@ -63,6 +63,14 @@ abstract class SimpleSAML_SessionHandler { abstract public function getCookieSessionId(); + /** + * Retrieve the session cookie name. + * + * @return string The session cookie name. + */ + abstract public function getSessionCookieName(); + + /** * Save the session. * diff --git a/lib/SimpleSAML/SessionHandlerCookie.php b/lib/SimpleSAML/SessionHandlerCookie.php index 7c5ae37a7..1e01d86ba 100644 --- a/lib/SimpleSAML/SessionHandlerCookie.php +++ b/lib/SimpleSAML/SessionHandlerCookie.php @@ -76,6 +76,17 @@ extends SimpleSAML_SessionHandler { } + /** + * Retrieve the session cookie name. + * + * @return string The session cookie name. + */ + public function getSessionCookieName() { + + return $this->cookie_name; + } + + /* This static function creates a session id. A session id consists * of 32 random hexadecimal characters. * diff --git a/lib/SimpleSAML/SessionHandlerPHP.php b/lib/SimpleSAML/SessionHandlerPHP.php index 17480b68c..1e7305489 100644 --- a/lib/SimpleSAML/SessionHandlerPHP.php +++ b/lib/SimpleSAML/SessionHandlerPHP.php @@ -13,6 +13,10 @@ */ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler { + /* This variable contains the session cookie name. */ + protected $cookie_name; + + /* Initialize the PHP session handling. This constructor is protected * because it should only be called from * SimpleSAML_SessionHandler::createSessionHandler(...). @@ -42,8 +46,12 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler { session_set_cookie_params($params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']); } - $cookiename = $config->getString('session.phpsession.cookiename', NULL); - if (!empty($cookiename)) session_name($cookiename); + $this->cookie_name = $config->getString('session.phpsession.cookiename', NULL); + if (!empty($this->cookie_name)) { + session_name($this->cookie_name); + } else { + $this->cookie_name = session_name(); + } $savepath = $config->getString('session.phpsession.savepath', NULL); if(!empty($savepath)) { @@ -109,6 +117,17 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler { } + /** + * Retrieve the session cookie name. + * + * @return string The session cookie name. + */ + public function getSessionCookieName() { + + return $this->cookie_name; + } + + /** * Save the current session to the PHP session array. * @@ -169,8 +188,7 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler { */ public function hasSessionCookie() { - $cookieName = session_name(); - return array_key_exists($cookieName, $_COOKIE); + return array_key_exists($this->cookie_name, $_COOKIE); } -- GitLab