summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2013-02-11 12:26:43 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2013-02-11 12:26:43 +0100
commit6efa9a2145a067d4034e24f86a0e0e37611472d3 (patch)
tree923b0095782ea8674d758720d95b5ab8fadded6c
parent2790e9e0bdd27ca40c3a6a4a773ca14685ce4d82 (diff)
parent49342d68ed1dd7eec52d30cf40280996dca6873d (diff)
downloadsymfony-security-6efa9a2145a067d4034e24f86a0e0e37611472d3.zip
symfony-security-6efa9a2145a067d4034e24f86a0e0e37611472d3.tar.gz
symfony-security-6efa9a2145a067d4034e24f86a0e0e37611472d3.tar.bz2
Merge branch '2.1' into 2.2
* 2.1: added support for the X-Forwarded-For header (closes #6982, closes #7000) fixed the IP address in HttpCache when calling the backend [EventDispatcher] Added assertion. [EventDispathcer] Fix removeListener [DependencyInjection] Add clone for resources which were introduced in 2.1 [DependencyInjection] Allow frozen containers to be dumped to graphviz Fix 'undefined index' error, when entering scope recursively [Security] fixed session creation on login (closes #7011) Add dot character `.` to legal mime subtype regular expression [HttpFoundation] fixed the creation of sub-requests under some circumstancies (closes #6923, closes #6936)
-rw-r--r--Http/Firewall/ContextListener.php6
-rw-r--r--Tests/Http/Firewall/ContextListenerTest.php19
2 files changed, 23 insertions, 2 deletions
diff --git a/Http/Firewall/ContextListener.php b/Http/Firewall/ContextListener.php
index 6c06ca8..8c71876 100644
--- a/Http/Firewall/ContextListener.php
+++ b/Http/Firewall/ContextListener.php
@@ -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));
}
diff --git a/Tests/Http/Firewall/ContextListenerTest.php b/Tests/Http/Firewall/ContextListenerTest.php
index 2a8a28e..ffe6195 100644
--- a/Tests/Http/Firewall/ContextListenerTest.php
+++ b/Tests/Http/Firewall/ContextListenerTest.php
@@ -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());
}