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

Skip to content

Commit 7de8b4e

Browse files
committed
[Security] Move AbstractListener abstract methods to the new FirewallListenerInterface
1 parent eb8d909 commit 7de8b4e

File tree

7 files changed

+53
-22
lines changed

7 files changed

+53
-22
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
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;
2022
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
2123

2224
class SortFirewallListenersPassTest extends TestCase
@@ -59,6 +61,14 @@ public function testSortFirewallListeners()
5961

6062
class FirewallListenerPriorityMinus1 implements FirewallListenerInterface
6163
{
64+
public function supports(Request $request): ?bool
65+
{
66+
}
67+
68+
public function authenticate(RequestEvent $event)
69+
{
70+
}
71+
6272
public static function getPriority(): int
6373
{
6474
return -1;
@@ -67,6 +77,14 @@ public static function getPriority(): int
6777

6878
class FirewallListenerPriority1 implements FirewallListenerInterface
6979
{
80+
public function supports(Request $request): ?bool
81+
{
82+
}
83+
84+
public function authenticate(RequestEvent $event)
85+
{
86+
}
87+
7088
public static function getPriority(): int
7189
{
7290
return 1;
@@ -75,6 +93,14 @@ public static function getPriority(): int
7593

7694
class FirewallListenerPriority2 implements FirewallListenerInterface
7795
{
96+
public function supports(Request $request): ?bool
97+
{
98+
}
99+
100+
public function authenticate(RequestEvent $event)
101+
{
102+
}
103+
78104
public static function getPriority(): int
79105
{
80106
return 2;

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CHANGELOG
1414
* Added a CurrentUser attribute to force the UserValueResolver to resolve an argument to the current user.
1515
* Added `LoginThrottlingListener`.
1616
* Added `LoginLinkAuthenticator`.
17+
* Moved methods `supports()` and `authenticate()` from `AbstractListener` to `FirewallListenerInterface`.
1718

1819
5.1.0
1920
-----

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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

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

14-
use Symfony\Component\HttpFoundation\Request;
1514
use Symfony\Component\HttpKernel\Event\RequestEvent;
1615

1716
/**
@@ -28,18 +27,6 @@ final public function __invoke(RequestEvent $event)
2827
}
2928
}
3029

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-
4330
public static function getPriority(): int
4431
{
4532
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