From add24fd6082cf562a4a343d6fb64ef47ca29bb01 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 9 Sep 2010 07:34:56 +0000 Subject: [PATCH] discopower: Allow configuring of the lifetime of the CDC cookie. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2535 44740490-163a-0410-bde0-09ae8108e29a --- .../config-templates/module_discopower.php | 9 +++++++++ modules/discopower/lib/PowerIdPDisco.php | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/discopower/config-templates/module_discopower.php b/modules/discopower/config-templates/module_discopower.php index 5764dd285..92493ca87 100644 --- a/modules/discopower/config-templates/module_discopower.php +++ b/modules/discopower/config-templates/module_discopower.php @@ -36,6 +36,15 @@ $config = array ( */ 'cdc.domain' => NULL, + /* + * The lifetime of the common domain cookie, in seconds. + * + * If this is NULL (the default), the common domain cookie will be deleted when the browser closes. + * + * Example: 'cdc.lifetime' => 180*24*60*60, // 180 days. + */ + 'cdc.lifetime' => NULL, + ); ?> diff --git a/modules/discopower/lib/PowerIdPDisco.php b/modules/discopower/lib/PowerIdPDisco.php index 1ed76f7f5..bdd4a79e8 100644 --- a/modules/discopower/lib/PowerIdPDisco.php +++ b/modules/discopower/lib/PowerIdPDisco.php @@ -25,6 +25,15 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco { private $cdcDomain; + /** + * The lifetime of the CDC cookie, in seconds. + * If set to NULL, it will only be valid until the browser is closed. + * + * @var int|NULL + */ + private $cdcLifetime; + + /** * Initializes this discovery service. * @@ -45,6 +54,8 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco { /* Ensure that the CDC domain starts with a dot ('.') as required by the spec. */ $this->cdcDomain = '.' . $this->cdcDomain; } + + $this->cdcLifetime = $this->discoconfig->getInteger('cdc.lifetime', NULL); } @@ -291,7 +302,13 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco { $newCookie = $tmp[1]; } - setcookie('_saml_idp', $newCookie, time() + 180*24*60*60, '/', $this->cdcDomain, TRUE); + if ($this->cdcLifetime === NULL) { + $expire = 0; + } else { + $expire = time() + $this->cdcLifetime; + } + + setcookie('_saml_idp', $newCookie, $expire, '/', $this->cdcDomain, TRUE); } -- GitLab