8000 [Security] Move AbstractListener abstract methods to the new Firewall… · symfony/symfony@4b108ee · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b108ee

Browse files
committed
[Security] Move AbstractListener abstract methods to the new FirewallListenerInterface
1 parent eb6167c commit 4b108ee

File tree

6 files changed

+53
-21
lines changed

6 files changed

+53
-21
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
1616
use Symfony\Bundle\SecurityBundle\Security\LazyFirewallContext;
1717
use Symfony\Component\HttpKernel\Event\RequestEvent;
18-
use Symfony\Component\Security\Http\Firewall\AbstractListener;
18+
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
1919

2020
/**
2121
* Firewall collecting called listeners.
@@ -41,7 +41,7 @@ protected function callListeners(RequestEvent $event, iterable $listeners)
4141
\Closure::bind(function () use (&$wrappedLazyListeners, &$wrappedListeners) {
4242
$listeners = [];
4343
foreach ($this->listeners as $listener) {
44-
if ($listener instanceof AbstractListener) {
44+
if ($listener instanceof FirewallListenerInterface) {
4545
$listener = new WrappedLazyListener($listener);
4646
$listeners[] = $listener;
4747
$wrappedLazyListeners[] = $listener;
@@ -58,7 +58,7 @@ protected function callListeners(RequestEvent $event, iterable $listeners)
5858

5959
$listener($event);
6060
} else {
61-
$wrappedListener = $listener instanceof AbstractListener ? new WrappedLazyListener($listener) : new WrappedListener($listener);
61+
$wrappedListener = $listener instanceof FirewallListenerInterface ? new WrappedLazyListener($listener) : new WrappedListener($listener);
6262
$wrappedListener($event);
6363
$wrappedListeners[] = $wrappedListener->getInfo();
6464
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Symfony\Component\HttpKernel\Event\RequestEvent;
1515
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
1616
use Symfony\Component\Security\Http\Event\LazyResponseEvent;
17-
use Symfony\Component\Security\Http\Firewall\AbstractListener;
1817
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
18+
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
1919
use Symfony\Component\Security\Http\Firewall\LogoutListener;
2020

2121
/**
@@ -46,9 +46,9 @@ public function __invoke(RequestEvent $event)
4646
$lazy = $request->isMethodCacheable();
4747

4848
foreach (parent::getListeners() as $listener) {
49-
if (!$lazy || !$listener instanceof AbstractListener) {
49+
if (!$lazy || !$listener instanceof FirewallListenerInterface) {
5050
$listeners[] = $listener;
51-
$lazy = $lazy && $listener instanceof AbstractListener;
51+
$lazy = $lazy && $listener instanceof FirewallListenerInterface;
5252
} elseif (false !== $supports = $listener->supports($request)) {
5353
$listeners[] = [$listener, 'authenticate'];
5454
$lazy = null === $supports;

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/SortFirewallListenersPassTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\DependencyInjection\Reference;
20+
use Symfony\Component\HttpFoundation\Request;
21+
use Symfony\Component\HttpKernel\Event\RequestEvent;
22+
use Symfony\Component\Security\Http\Firewall\AbstractListener;
2023
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
2124

2225
class SortFirewallListenersPassTest extends TestCase
@@ -59,6 +62,14 @@ public function testSortFirewallListeners()
5962

6063
class FirewallListenerPriorityMinus1 implements FirewallListenerInterface
6164
{
65+
public function supports(Request $request): ?bool
66+
{
67+
}
68+
69+
public function authenticate(RequestEvent $event)
70+
{
71+
}
72+
6273
public static function getPriority(): int
6374
{
6475
return -1;
@@ -67,6 +78,14 @@ public static function getPriority(): int
6778

6879
class FirewallListenerPriority1 implements FirewallListenerInterface
6980
{
81+
public function supports(Request $request): ?bool
82+
{
83+
}
84+
85+
public function authenticate(RequestEvent $event)
86+
{
87+
}
88+
7089
public static function getPriority(): int
7190
{
7291
return 1;
@@ -75,6 +94,14 @@ public static function getPriority(): int
7594

7695
class FirewallListenerPriority2 implements FirewallListenerInterface
7796
{
97+
public function supports(Request $request): ?bool
98+
{
99+
}
100+
101+
public function authenticate(RequestEvent $event)
102+
{
103+
}
104+
78105
public static function getPriority(): int
79106
{
80107
return 2;

src/Symfony/Component/Security/Http/Authentication/AuthenticatorManagerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
16-
use Symfony\Component\Security\Http\Firewall\AbstractListener;
16+
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
1717

1818
/**
1919
* @author Wouter de Jong <wouter@wouterj.nl>
@@ -26,7 +26,7 @@ interface AuthenticatorManagerInterface
2626
/**
2727
* Called to see if authentication should be attempted on this request.
2828
*
29-
* @see AbstractListener::supports()
29+
* @see FirewallListenerInterface::supports()
3030
*/
3131
public function supports(Request $request): ?bool;
3232

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ final public function __invoke(RequestEvent $event)
2828
}
2929
}
3030

31-
/**
32-
* Tells whether the authenticate() method should be called or not depending on the incoming request.
33-
*
34-
* Returning null means authenticate() can be called lazily when accessing the token storage.
35-
*/
36-
abstract public function supports(Request $request): ?bool;
37-
38-
/**
39-
* Does whatever is required to authenticate the request, typically calling $event->setResponse() internally.
40-
*/
41-
abstract public function authenticate(RequestEvent $event);
42-
4331
public static function getPriority(): int
4432
{
4533
return 0; // Default

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,30 @@
1111

1212
namespace Symfony\Component\Security\Http\Firewall;
1313

14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpKernel\Event\RequestEvent;
16+
1417
/**
15-
* Can be implemented by firewall listeners to define their priority in execution.
18+
* Can be implemented by firewall listeners.
1619
*
1720
* @author Christian Scheb <me@christianscheb.de>
21+
* @author Nicolas Grekas <p@tchwork.com>
22+
* @author Robin Chalas <robin.chalas@gmail.com>
1823
*/
1924
interface FirewallListenerInterface
2025
{
26+
/**
27+
* Tells whether the authenticate() method should be called or not depending on the incoming request.
28+
*
29+
* Returning null means authenticate() can be called lazily when accessing the token storage.
30+
*/
31+
public function supports(Request $request): ?bool;
32+
33+
/**
34+
* Does whatever is required to authenticate the request, typically calling $event->setResponse() internally.
35+
*/
36+
public function authenticate(RequestEvent $event);
37+
2138
/**
2239
* Defines the priority of the listener.
2340
* The higher the number, the earlier a listener is executed.

0 commit comments

Comments
 (0)
0