[Security] fixed session creation on login (closes #7011)
This commit is contained in:
parent
e50d33308a
commit
3615e199d2
@ -117,14 +117,16 @@ class ContextListener implements ListenerInterface
|
||||
}
|
||||
|
||||
$request = $event->getRequest();
|
||||
$session = $request->hasPreviousSession() ? $request->getSession() : null;
|
||||
$session = $request->getSession();
|
||||
|
||||
if (null === $session) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((null === $token = $this->context->getToken()) || ($token instanceof AnonymousToken)) {
|
||||
$session->remove('_security_'.$this->contextKey);
|
||||
if ($request->hasPreviousSession()) {
|
||||
$session->remove('_security_'.$this->contextKey);
|
||||
}
|
||||
} else {
|
||||
$session->set('_security_'.$this->contextKey, serialize($token));
|
||||
}
|
||||
|
@ -99,6 +99,25 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$listener = new ContextListener($this->securityContext, array(), 'session');
|
||||
$listener->onKernelResponse($event);
|
||||
|
||||
$this->assertTrue($session->isStarted());
|
||||
}
|
||||
|
||||
public function testOnKernelResponseWithoutSessionNorToken()
|
||||
{
|
||||
$request = new Request();
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request->setSession($session);
|
||||
|
||||
$event = new FilterResponseEvent(
|
||||
$this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'),
|
||||
$request,
|
||||
HttpKernelInterface::MASTER_REQUEST,
|
||||
new Response()
|
||||
);
|
||||
|
||||
$listener = new ContextListener($this->securityContext, array(), 'session');
|
||||
$listener->onKernelResponse($event);
|
||||
|
||||
$this->assertFalse($session->isStarted());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user