Skip to content

Commit c935ea5

Browse files
feature #60879 [Security] Remove callable firewall listeners support (MatTheCat)
This PR was merged into the 8.0 branch. Discussion ---------- [Security] Remove callable firewall listeners support | Q | A | ------------- | --- | Branch? | 8.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT Follow-up of #60614 Now that firewall listeners must implement `FirewallListenerInterface`, their traceable version’s stub can be their class name again. Commits ------- fcadbf0 Remove callable firewall listeners support
2 parents 779dd40 + fcadbf0 commit c935ea5

16 files changed

+65
-193
lines changed

UPGRADE-8.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ Security
326326
+}
327327
```
328328

329+
* Remove callable firewall listeners support, extend `AbstractListener` or implement `FirewallListenerInterface` instead
330+
* Remove `AbstractListener::__invoke`
331+
* Remove `LazyFirewallContext::__invoke()`
332+
329333
Serializer
330334
----------
331335

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
8.0
5+
---
6+
7+
* Remove `LazyFirewallContext::__invoke()`
8+
49
7.4
510
---
611

src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use Symfony\Bundle\SecurityBundle\Security\LazyFirewallContext;
1717
use Symfony\Component\HttpKernel\Event\RequestEvent;
1818
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
19-
use Symfony\Component\Security\Http\Firewall\AbstractListener;
20-
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
2119
use Symfony\Contracts\Service\ResetInterface;
2220

2321
/**
@@ -33,7 +31,7 @@ final class TraceableFirewallListener extends FirewallListener implements ResetI
3331
public function getWrappedListeners(): array
3432
{
3533
return array_map(
36-
static fn (WrappedListener|WrappedLazyListener $listener) => $listener->getInfo(),
34+
static fn (WrappedLazyListener $listener) => $listener->getInfo(),
3735
$this->wrappedListeners
3836
);
3937
}
@@ -62,10 +60,7 @@ protected function callListeners(RequestEvent $event, iterable $listeners): void
6260
if ($listener instanceof TraceableAuthenticatorManagerListener) {
6361
$contextAuthenticatorManagerListener ??= $listener;
6462
}
65-
$contextWrappedListeners[] = $listener instanceof FirewallListenerInterface
66-
? new WrappedLazyListener($listener)
67-
: new WrappedListener($listener)
68-
;
63+
$contextWrappedListeners[] = new WrappedLazyListener($listener);
6964
}
7065
$this->listeners = $contextWrappedListeners;
7166
}, $listener, FirewallContext::class)();
@@ -78,23 +73,20 @@ protected function callListeners(RequestEvent $event, iterable $listeners): void
7873
if ($listener instanceof TraceableAuthenticatorManagerListener) {
7974
$this->authenticatorManagerListener ??= $listener;
8075
}
81-
$wrappedListener = $listener instanceof FirewallListenerInterface
82-
? new WrappedLazyListener($listener)
83-
: new WrappedListener($listener)
84-
;
76+
$wrappedListener = new WrappedLazyListener($listener);
8577
$this->wrappedListeners[] = $wrappedListener;
8678

8779
$requestListeners[] = $wrappedListener;
8880
}
8981
}
9082

9183
foreach ($requestListeners as $listener) {
92-
if (!$listener instanceof FirewallListenerInterface) {
93-
$listener($event);
94-
} elseif (false !== $listener->supports($event->getRequest())) {
95-
$listener->authenticate($event);
84+
if (false === $listener->supports($event->getRequest())) {
85+
continue;
9686
}
9787

88+
$listener->authenticate($event);
89+
9890
if ($event->hasResponse()) {
9991
break;
10092
}

src/Symfony/Bundle/SecurityBundle/Debug/TraceableListenerTrait.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Symfony/Bundle/SecurityBundle/Debug/WrappedLazyListener.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Bundle\SecurityBundle\Debug;
1313

1414
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
1516
use Symfony\Component\HttpKernel\Event\RequestEvent;
1617
use Symfony\Component\Security\Core\Exception\LazyResponseException;
18+
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
1719
use Symfony\Component\Security\Http\Firewall\AbstractListener;
1820
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
21+
use Symfony\Component\VarDumper\Caster\ClassStub;
1922

2023
/**
2124
* Wraps a lazy security listener.
@@ -26,7 +29,10 @@
2629
*/
2730
final class WrappedLazyListener extends AbstractListener
2831
{
29-
use TraceableListenerTrait;
32+
private ?Response $response = null;
33+
private FirewallListenerInterface $listener;
34+
private ?float $time = null;
35+
private ClassStub $stub;
3036

3137
public function __construct(FirewallListenerInterface $listener)
3238
{
@@ -54,4 +60,21 @@ public function authenticate(RequestEvent $event): void
5460

5561
$this->response = $event->getResponse();
5662
}
63+
64+
public function getInfo(): array
65+
{
66+
return [
67+
'response' => $this->response,
68+
'time' => $this->time,
69+
'stub' => $this->stub ??= new ClassStub($this->listener instanceof TraceableAuthenticatorManagerListener ? $this->listener->getAuthenticatorManagerListener()::class : $this->listener::class),
70+
];
71+
}
72+
73+
/**
74+
* Proxies all method calls to the original listener.
75+
*/
76+
public function __call(string $method, array $arguments): mixed
77+
{
78+
return $this->listener->{$method}(...$arguments);
79+
}
5780
}

src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Symfony/Bundle/SecurityBundle/Security/FirewallContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class FirewallContext
2525
{
2626
/**
27-
* @param iterable<mixed, callable> $listeners
27+
* @param iterable<mixed, FirewallListenerInterface> $listeners
2828
*/
2929
public function __construct(
3030
private iterable $listeners,
@@ -40,7 +40,7 @@ public function getConfig(): ?FirewallConfig
4040
}
4141

4242
/**
43-
* @return iterable<mixed, FirewallListenerInterface|callable>
43+
* @return iterable<mixed, FirewallListenerInterface>
4444
*/
4545
public function getListeners(): iterable
4646
{

src/Symfony/Bundle/SecurityBundle/Security/LazyFirewallContext.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\HttpKernel\Event\RequestEvent;
1616
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
1717
use Symfony\Component\Security\Http\Event\LazyResponseEvent;
18-
use Symfony\Component\Security\Http\Firewall\AbstractListener;
1918
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
2019
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
2120
use Symfony\Component\Security\Http\Firewall\LogoutListener;
@@ -54,20 +53,15 @@ public function authenticate(RequestEvent $event): void
5453
$lazy = $request->isMethodCacheable();
5554

5655
foreach (parent::getListeners() as $listener) {
57-
if (!$listener instanceof FirewallListenerInterface) {
58-
trigger_deprecation('symfony/security-http', '7.4', 'Using a callable as firewall listener is deprecated, extend "%s" or implement "%s" instead.', AbstractListener::class, FirewallListenerInterface::class);
59-
56+
if (false !== $supports = $listener->supports($request)) {
6057
$listeners[] = $listener;
61-
$lazy = false;
62-
} elseif (false !== $supports = $listener->supports($request)) {
63-
$listeners[] = [$listener, 'authenticate'];
6458
$lazy = $lazy && null === $supports;
6559
}
6660
}
6761

6862
if (!$lazy) {
6963
foreach ($listeners as $listener) {
70-
$listener($event);
64+
$listener->authenticate($event);
7165

7266
if ($event->hasResponse()) {
7367
return;
@@ -80,7 +74,7 @@ public function authenticate(RequestEvent $event): void
8074
$this->tokenStorage->setInitializer(function () use ($event, $listeners) {
8175
$event = new LazyResponseEvent($event);
8276
foreach ($listeners as $listener) {
83-
$listener($event);
77+
$listener->authenticate($event);
8478
}
8579
});
8680
}
@@ -89,14 +83,4 @@ public static function getPriority(): int
8983
{
9084
return 0;
9185
}
92-
93-
/**
94-
* @deprecated since Symfony 7.4, to be removed in 8.0
95-
*/
96-
public function __invoke(RequestEvent $event): void
97-
{
98-
trigger_deprecation('symfony/security-bundle', '7.4', 'The "%s()" method is deprecated since Symfony 7.4 and will be removed in 8.0.', __METHOD__);
99-
100-
$this->authenticate($event);
101-
}
10286
}

src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Symfony\Component\Security\Http\Firewall\AuthenticatorManagerListener;
3434
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
3535
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
36+
use Symfony\Component\VarDumper\Caster\ClassStub;
3637

3738
/**
3839
* @group time-sensitive
@@ -75,7 +76,8 @@ public function authenticate(RequestEvent $event): void
7576

7677
$listeners = $firewall->getWrappedListeners();
7778
$this->assertCount(1, $listeners);
78-
$this->assertSame($listener, $listeners[0]['stub']);
79+
$this->assertInstanceOf(ClassStub::class, $listeners[0]['stub']);
80+
$this->assertSame((string) new ClassStub($listener::class), (string) $listeners[0]['stub']);
7981
}
8082

8183
public function testOnKernelRequestRecordsAuthenticatorsInfo()

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"symfony/clock": "^7.4|^8.0",
2323
"symfony/config": "^7.4|^8.0",
2424
"symfony/dependency-injection": "^7.4|^8.0",
25-
"symfony/deprecation-contracts": "^2.5|^3",
2625
"symfony/event-dispatcher": "^7.4|^8.0",
2726
"symfony/http-kernel": "^7.4|^8.0",
2827
"symfony/http-foundation": "^7.4|^8.0",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy