From a0895629bac6c67e4d08485a39bb9ae7173c4636 Mon Sep 17 00:00:00 2001 From: Ulf Seltmann <useltmann@users.noreply.github.com> Date: Mon, 12 Dec 2016 22:23:48 +0100 Subject: [PATCH] Configurable session cookie name (#867) --- config/vufind/config.ini | 3 ++ .../src/VuFind/Cookie/CookieManager.php | 30 +++++++++++++++---- module/VuFind/src/VuFind/Service/Factory.php | 7 ++++- .../src/VuFind/Session/ManagerFactory.php | 7 +++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/config/vufind/config.ini b/config/vufind/config.ini index fff872deaaa..59b9e5b8f1a 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -159,6 +159,9 @@ lifetime = 3600 ; Session lasts for 1 hour ; Set the domain used for cookies (sometimes useful for sharing the cookies across ; subdomains); by default, cookies will be restricted to the current hostname. ;domain = ".example.edu" +; This sets the session cookie's name. Only needed if you use session sharing over +; multiple subdomains (see domain setting above) and you have multiple PHP apps. +;session_name = VUFIND_SESSION ; Please set the ILS that VuFind will interact with. ; diff --git a/module/VuFind/src/VuFind/Cookie/CookieManager.php b/module/VuFind/src/VuFind/Cookie/CookieManager.php index 05a9d0008f0..66d95e0c99e 100644 --- a/module/VuFind/src/VuFind/Cookie/CookieManager.php +++ b/module/VuFind/src/VuFind/Cookie/CookieManager.php @@ -59,21 +59,31 @@ class CookieManager */ protected $secure; + /** + * The name of the session cookie + * + * @var string + */ + protected $sessionName; + /** * Constructor * - * @param array $cookies Cookie array to manipulate (e.g. $_COOKIE) - * @param string $path Cookie base path (default = /) - * @param string $domain Cookie domain - * @param bool $secure Are cookies secure only? (default = false) + * @param array $cookies Cookie array to manipulate (e.g. $_COOKIE) + * @param string $path Cookie base path (default = /) + * @param string $domain Cookie domain + * @param bool $secure Are cookies secure only? (default = false) + * @param string $sessionName Session cookie name (if null defaults to PHP + * settings) */ public function __construct($cookies, $path = '/', $domain = null, - $secure = false + $secure = false, $sessionName = null ) { $this->cookies = $cookies; $this->path = $path; $this->domain = $domain; $this->secure = $secure; + $this->sessionName = $sessionName; } /** @@ -116,6 +126,16 @@ class CookieManager return $this->secure; } + /** + * Get the name of the cookie + * + * @return mixed + */ + public function getSessionName() + { + return $this->sessionName; + } + /** * Support method for setGlobalCookie -- proxy PHP's setcookie() function * for compatibility with unit testing. diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index d406c6a583b..39a46be00f3 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -215,7 +215,12 @@ class Factory $domain = isset($config->Cookies->domain) ? $config->Cookies->domain : null; - return new \VuFind\Cookie\CookieManager($_COOKIE, $path, $domain, $secure); + $session_name = isset($config->Cookies->session_name) + ? $config->Cookies->session_name + : null; + return new \VuFind\Cookie\CookieManager( + $_COOKIE, $path, $domain, $secure, $session_name + ); } /** diff --git a/module/VuFind/src/VuFind/Session/ManagerFactory.php b/module/VuFind/src/VuFind/Session/ManagerFactory.php index 4210d729bd3..db2c4de8711 100644 --- a/module/VuFind/src/VuFind/Session/ManagerFactory.php +++ b/module/VuFind/src/VuFind/Session/ManagerFactory.php @@ -56,10 +56,17 @@ class ManagerFactory implements \Zend\ServiceManager\FactoryInterface 'cookie_path' => $cookieManager->getPath(), 'cookie_secure' => $cookieManager->isSecure() ]; + $domain = $cookieManager->getDomain(); if (!empty($domain)) { $options['cookie_domain'] = $domain; } + + $name = $cookieManager->getSessionName(); + if (!empty($name)) { + $options['name'] = $name; + } + return $options; } -- GitLab