Skip to content

Commit b69255a

Browse files
committed
Trigger an E_USER_WARNING if max idle time exceeds session.gc_maxlifetime
1 parent e5f4f8c commit b69255a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Symfony/Component/Security/Http/Firewall/SessionExpirationListener.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $http
3535
{
3636
$this->tokenStorage = $tokenStorage;
3737
$this->httpUtils = $httpUtils;
38-
$this->maxIdleTime = $maxIdleTime;
38+
$this->setMaxIdleTime($maxIdleTime);
3939
$this->targetUrl = $targetUrl;
4040
$this->logger = $logger;
4141
}
@@ -74,6 +74,17 @@ public function handle(GetResponseEvent $event)
7474
$event->setResponse($response);
7575
}
7676

77+
/**
78+
* @param int $maxIdleTime
79+
*/
80+
private function setMaxIdleTime($maxIdleTime)
81+
{
82+
if ($maxIdleTime > ini_get('session.gc_maxlifetime')) {
83+
trigger_error("Max idle time should not be greater than 'session.gc_maxlifetime'", \E_USER_WARNING);
84+
}
85+
$this->maxIdleTime = (int) $maxIdleTime;
86+
}
87+
7788
/**
7889
* Checks if the given session has expired.
7990
*

src/Symfony/Component/Security/Http/Tests/Firewall/SessionExpirationListenerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ public function testHandleWhenSessionHasExpiredAndTargetUrl()
218218
$listener->handle($event);
219219
}
220220

221+
/**
222+
* @expectedException \PHPUnit_Framework_Error_Warning
223+
*/
224+
public function testWarningIsTriggeredIfMaxIdleTimeIsTooHigh()
225+
{
226+
$gcMaxlifetime = ini_get('session.gc_maxlifetime');
227+
new SessionExpirationListener(
228+
$this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'),
229+
$this->getHttpUtils(),
230+
$gcMaxlifetime + 1
231+
);
232+
}
233+
221234
private function getHttpUtils()
222235
{
223236
return $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')

0 commit comments

Comments
 (0)