Skip to content

Commit 7ea8def

Browse files
Merge branch '4.4'
* 4.4: (23 commits) [HttpFoundation] fix docblock [HttpKernel] Flatten "exception" controller argument if not typed Fix MySQL column type definition. Link the right file depending on the new version [Cache] Redis Tag Aware warn on wrong eviction policy [HttpClient] fix HttpClientDataCollector [HttpKernel] collect bundle classes, not paths [Config] fix id-generation for GlobResource [HttpKernel] dont check cache freshness more than once per process [Finder] Allow ssh2 stream wrapper for sftp [FrameworkBundle] fix wiring of httplug client add FrameworkBundle requirement [SecurityBundle] add tests with empty authenticator [Security] always check the token on non-lazy firewalls [DI] Use reproducible entropy to generate env placeholders [WebProfilerBundle] Require symfony/twig-bundle [Mailer] Add UPGRADE entry about the null transport DSN bumped Symfony version to 4.3.9 updated VERSION for 4.3.8 updated CHANGELOG for 4.3.8 ...
2 parents ee5f4d2 + 5ef19ef commit 7ea8def

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Firewall/AccessListener.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
1919
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
2020
use Symfony\Component\Security\Http\AccessMapInterface;
21+
use Symfony\Component\Security\Http\Event\LazyResponseEvent;
2122

2223
/**
2324
* AccessListener enforces access control rules.
@@ -49,6 +50,10 @@ public function __construct(TokenStorageInterface $tokenStorage, AccessDecisionM
4950
*/
5051
public function __invoke(RequestEvent $event)
5152
{
53+
if (!$event instanceof LazyResponseEvent && null === $token = $this->tokenStorage->getToken()) {
54+
throw new AuthenticationCredentialsNotFoundException('A Token was not found in the TokenStorage.');
55+
}
56+
5257
$request = $event->getRequest();
5358

5459
list($attributes) = $this->map->getPatterns($request);
@@ -57,7 +62,7 @@ public function __invoke(RequestEvent $event)
5762
return;
5863
}
5964

60-
if (null === $token = $this->tokenStorage->getToken()) {
65+
if ($event instanceof LazyResponseEvent && null === $token = $this->tokenStorage->getToken()) {
6166
throw new AuthenticationCredentialsNotFoundException('A Token was not found in the TokenStorage.');
6267
}
6368

Tests/Firewall/AccessListenerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1919
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
2020
use Symfony\Component\Security\Http\AccessMapInterface;
21+
use Symfony\Component\Security\Http\Event\LazyResponseEvent;
2122
use Symfony\Component\Security\Http\Firewall\AccessListener;
2223

2324
class AccessListenerTest extends TestCase
@@ -219,7 +220,7 @@ public function testHandleWhenAccessMapReturnsEmptyAttributes()
219220
->willReturn($request)
220221
;
221222

222-
$listener($event);
223+
$listener(new LazyResponseEvent($event));
223224
}
224225

225226
public function testHandleWhenTheSecurityTokenStorageHasNoToken()

0 commit comments

Comments
 (0)