mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Switched over to using the previously unused Security::inactiveMins() method for getting timeout modifiers
Signed-off-by: Mark Story <mark@mark-story.com>
This commit is contained in:
parent
5cf08cbe92
commit
b04a3f8514
2 changed files with 18 additions and 43 deletions
|
@ -199,18 +199,6 @@ class CakeSession extends Object {
|
||||||
$this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout'));
|
$this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout'));
|
||||||
$this->security = Configure::read('Security.level');
|
$this->security = Configure::read('Security.level');
|
||||||
}
|
}
|
||||||
switch ($this->security) {
|
|
||||||
case 'medium':
|
|
||||||
$this->factor = 5040;
|
|
||||||
break;
|
|
||||||
case 'low':
|
|
||||||
$this->factor = 2628000;
|
|
||||||
break;
|
|
||||||
case 'high':
|
|
||||||
default:
|
|
||||||
$this->factor = 10;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,20 +475,20 @@ class CakeSession extends Object {
|
||||||
|
|
||||||
switch ($this->security) {
|
switch ($this->security) {
|
||||||
case 'high':
|
case 'high':
|
||||||
$this->cookieLifeTime = Configure::read('Session.timeout') * $this->factor;
|
$this->cookieLifeTime = Configure::read('Session.timeout') * Security::inactiveMins();
|
||||||
if ($iniSet) {
|
if ($iniSet) {
|
||||||
ini_set('session.referer_check', $this->host);
|
ini_set('session.referer_check', $this->host);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'medium':
|
case 'medium':
|
||||||
$this->cookieLifeTime = Configure::read('Session.timeout') * $this->factor;
|
$this->cookieLifeTime = Configure::read('Session.timeout') * Security::inactiveMins();
|
||||||
if ($iniSet) {
|
if ($iniSet) {
|
||||||
ini_set('session.referer_check', $this->host);
|
ini_set('session.referer_check', $this->host);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'low':
|
case 'low':
|
||||||
default:
|
default:
|
||||||
$this->cookieLifeTime = Configure::read('Session.timeout') * $this->factor;
|
$this->cookieLifeTime = Configure::read('Session.timeout') * Security::inactiveMins();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,11 +615,11 @@ class CakeSession extends Object {
|
||||||
if (Configure::read('Security.level') === 'high') {
|
if (Configure::read('Security.level') === 'high') {
|
||||||
$check = $this->read('Config.timeout');
|
$check = $this->read('Config.timeout');
|
||||||
$check = $check - 1;
|
$check = $check - 1;
|
||||||
$this->write('Config.timeout', $this->factor);
|
$this->write('Config.timeout', Security::inactiveMins());
|
||||||
|
|
||||||
if (time() > ($time - (Security::inactiveMins() * Configure::read('Session.timeout')) + 2) || $check < 1) {
|
if (time() > ($time - (Security::inactiveMins() * Configure::read('Session.timeout')) + 2) || $check < 1) {
|
||||||
$this->renew();
|
$this->renew();
|
||||||
$this->write('Config.timeout', $this->factor);
|
$this->write('Config.timeout', Security::inactiveMins());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->valid = true;
|
$this->valid = true;
|
||||||
|
@ -643,7 +631,7 @@ class CakeSession extends Object {
|
||||||
} else {
|
} else {
|
||||||
$this->write('Config.userAgent', $this->_userAgent);
|
$this->write('Config.userAgent', $this->_userAgent);
|
||||||
$this->write('Config.time', $this->sessionTime);
|
$this->write('Config.time', $this->sessionTime);
|
||||||
$this->write('Config.timeout', $this->factor);
|
$this->write('Config.timeout', Security::inactiveMins());
|
||||||
$this->valid = true;
|
$this->valid = true;
|
||||||
$this->__setError(1, 'Session is valid');
|
$this->__setError(1, 'Session is valid');
|
||||||
}
|
}
|
||||||
|
@ -771,21 +759,7 @@ class CakeSession extends Object {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __write($id, $data) {
|
function __write($id, $data) {
|
||||||
switch (Configure::read('Security.level')) {
|
$expires = time() + Configure::read('Session.timeout') * Security::inactiveMins();
|
||||||
case 'medium':
|
|
||||||
$factor = 5040;
|
|
||||||
break;
|
|
||||||
case 'low':
|
|
||||||
$factor = 2628000;
|
|
||||||
break;
|
|
||||||
case 'high':
|
|
||||||
default:
|
|
||||||
$factor = 10;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$expires = time() + Configure::read('Session.timeout') * $factor;
|
|
||||||
|
|
||||||
$model =& ClassRegistry::getObject('Session');
|
$model =& ClassRegistry::getObject('Session');
|
||||||
$return = $model->save(compact('id', 'data', 'expires'));
|
$return = $model->save(compact('id', 'data', 'expires'));
|
||||||
return $return;
|
return $return;
|
||||||
|
|
|
@ -351,31 +351,32 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
function testSessionTimeout() {
|
function testSessionTimeout() {
|
||||||
|
|
||||||
session_destroy();
|
session_destroy();
|
||||||
$Session =& new SessionComponent();
|
unset($Session);
|
||||||
Configure::write('Security.level', 'low');
|
Configure::write('Security.level', 'low');
|
||||||
|
$Session =& new SessionComponent();
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertEqual($_SESSION['Config']['timeout'], $Session->factor);
|
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||||
$this->assertEqual($Session->time, mktime());
|
$this->assertEqual($Session->time, mktime());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->time + ($Session->factor * Configure::read('Session.timeout')));
|
$this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout')));
|
||||||
|
|
||||||
session_destroy();
|
session_destroy();
|
||||||
$Session =& new SessionComponent();
|
|
||||||
Configure::write('Security.level', 'medium');
|
Configure::write('Security.level', 'medium');
|
||||||
|
$Session =& new SessionComponent();
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertEqual($_SESSION['Config']['timeout'], $Session->factor);
|
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||||
$this->assertEqual($Session->time, mktime());
|
$this->assertEqual($Session->time, mktime());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->time + ($Session->factor * Configure::read('Session.timeout')));
|
$this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout')));
|
||||||
|
|
||||||
session_destroy();
|
session_destroy();
|
||||||
$Session =& new SessionComponent();
|
|
||||||
Configure::write('Security.level', 'high');
|
Configure::write('Security.level', 'high');
|
||||||
|
$Session =& new SessionComponent();
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertEqual($_SESSION['Config']['timeout'], $Session->factor);
|
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||||
$this->assertEqual($Session->time, mktime());
|
$this->assertEqual($Session->time, mktime());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->time + ($Session->factor * Configure::read('Session.timeout')));
|
$this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout')));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue