Skip to content
Snippets Groups Projects
Commit 942c6bab authored by Tim Steiner's avatar Tim Steiner
Browse files

Updates to Unl_Cas to make the native PHP session handling work with older versions of PHP. @1h00

parent e3d4d2c1
Branches
Tags
No related merge requests found
...@@ -41,8 +41,9 @@ class Unl_Cas ...@@ -41,8 +41,9 @@ class Unl_Cas
const PARAM_RENEW = 3; const PARAM_RENEW = 3;
/** /**
* Session storage use to prevent infinate redirect loops when in gateway mode. * Session storage use to prevent infinite redirect loops when in gateway mode.
* @var Zend_Session_Namespace * Do not use this directly, use $this->_session()
* @var Zend_Session_Namespace|array
*/ */
private $_session; private $_session;
...@@ -75,13 +76,10 @@ class Unl_Cas ...@@ -75,13 +76,10 @@ class Unl_Cas
$this->_session = new Zend_Session_Namespace(__CLASS__); $this->_session = new Zend_Session_Namespace(__CLASS__);
} catch (Zend_Session_Exception $e) { } catch (Zend_Session_Exception $e) {
//Problem starting Zend_Session (probably because it was already started, use standard PHP sessions. //Problem starting Zend_Session (probably because it was already started, use standard PHP sessions.
if (!array_key_exists(__CLASS__, $_SESSION) || !$_SESSION[__CLASS__] instanceof ArrayObject) { if (!array_key_exists(__CLASS__, $_SESSION) || !is_array($_SESSION[__CLASS__])) {
$_SESSION[__CLASS__] = new ArrayObject(); $_SESSION[__CLASS__] = array();
} }
$this->_session = $_SESSION[__CLASS__]; $this->_session = NULL;
}
if (!isset($this->_session->ticket)) {
$this->_session->ticket = NULL;
} }
} }
...@@ -160,7 +158,7 @@ class Unl_Cas ...@@ -160,7 +158,7 @@ class Unl_Cas
*/ */
public function getUsername() public function getUsername()
{ {
return $this->_session->username; return $this->_session('username');
} }
/** /**
...@@ -290,7 +288,7 @@ class Unl_Cas ...@@ -290,7 +288,7 @@ class Unl_Cas
$response = $client->request(); $response = $client->request();
if ($response->isSuccessful() && $this->_parseResponse($response->getBody())) { if ($response->isSuccessful() && $this->_parseResponse($response->getBody())) {
$this->_addValidTicket($ticket); $this->_addValidTicket($ticket);
$this->_session->ticket = $ticket; $this->_session('ticket', $ticket);
return true; return true;
} }
return false; return false;
...@@ -308,7 +306,7 @@ class Unl_Cas ...@@ -308,7 +306,7 @@ class Unl_Cas
if ($xml->loadXML($response)) { if ($xml->loadXML($response)) {
if ($success = $xml->getElementsByTagName('authenticationSuccess')) { if ($success = $xml->getElementsByTagName('authenticationSuccess')) {
if ($success->length > 0 && $uid = $success->item(0)->getElementsByTagName('user')) { if ($success->length > 0 && $uid = $success->item(0)->getElementsByTagName('user')) {
$this->_session->username = $uid->item(0)->nodeValue; $this->_session('username', $uid->item(0)->nodeValue);
return true; return true;
} }
} }
...@@ -362,7 +360,7 @@ class Unl_Cas ...@@ -362,7 +360,7 @@ class Unl_Cas
public function isTicketExpired() public function isTicketExpired()
{ {
return !$this->_isStillValidTicket($this->_session->ticket); return !$this->_isStillValidTicket($this->_session('ticket'));
} }
public function handleLogoutRequest($saml) public function handleLogoutRequest($saml)
...@@ -382,9 +380,30 @@ class Unl_Cas ...@@ -382,9 +380,30 @@ class Unl_Cas
public function destroySession() public function destroySession()
{ {
$this->_removeValidTicket($this->_session->ticket); $this->_removeValidTicket($this->_session('ticket'));
$this->_session->ticket = NULL; $this->_session('ticket', NULL);
$this->_session->username = NULL; $this->_session('username', NULL);
}
// Wrapper to use either Zend sessions or native PHP sessions
protected function _session($key, $val = NULL)
{
if ($this->_session instanceof Zend_Session_Namespace) {
if (func_num_args() == 2) {
$this->_session->$key = $val;
} else {
return $this->_session->$key;
}
} else {
if (func_num_args() == 2) {
$_SESSION[__CLASS__][$key] = $val;
} else {
if (!isset($_SESSION[__CLASS__][$key])) {
return NULL;
}
return $_SESSION[__CLASS__][$key];
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment