diff --git a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php index 2a36e10102c27..5c19e6aa78cce 100644 --- a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php +++ b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php @@ -12,8 +12,6 @@ namespace Symfony\Bundle\SecurityBundle\Debug; use Symfony\Component\HttpKernel\Event\RequestEvent; -use Symfony\Component\Security\Http\Firewall\LegacyListenerTrait; -use Symfony\Component\Security\Http\Firewall\ListenerInterface; use Symfony\Component\VarDumper\Caster\ClassStub; /** @@ -21,22 +19,17 @@ * * @author Robin Chalas * - * @internal since Symfony 4.3 + * @internal */ -final class WrappedListener implements ListenerInterface +final class WrappedListener { - use LegacyListenerTrait; - private $response; private $listener; private $time; private $stub; private static $hasVarDumper; - /** - * @param callable $listener - */ - public function __construct($listener) + public function __construct(callable $listener) { $this->listener = $listener; @@ -45,18 +38,10 @@ public function __construct($listener) } } - /** - * {@inheritdoc} - */ public function __invoke(RequestEvent $event) { $startTime = microtime(true); - if (\is_callable($this->listener)) { - ($this->listener)($event); - } else { - @trigger_error(sprintf('Calling the "%s::handle()" method from the firewall is deprecated since Symfony 4.3, implement "__invoke()" instead.', \get_class($this)), E_USER_DEPRECATED); - $this->listener->handle($event); - } + ($this->listener)($event); $this->time = microtime(true) - $startTime; $this->response = $event->getResponse(); } diff --git a/src/Symfony/Component/Security/CHANGELOG.md b/src/Symfony/Component/Security/CHANGELOG.md index 1afdfa175b9f5..f0fc358ab0fc9 100644 --- a/src/Symfony/Component/Security/CHANGELOG.md +++ b/src/Symfony/Component/Security/CHANGELOG.md @@ -4,18 +4,22 @@ CHANGELOG 5.0.0 ----- -* Removed the `AdvancedUserInterface`, use a custom user checker instead. -* Removed `Argon2iPasswordEncoder`, use `SodiumPasswordEncoder` instead -* Removed `BcryptPasswordEncoder`, use `NativePasswordEncoder` instead -* Removed the `has_role()` function from security expressions, use `is_granted()` instead. -* `SimpleAuthenticatorInterface`, `SimpleFormAuthenticatorInterface`, `SimplePreAuthenticatorInterface`, - `SimpleAuthenticationProvider`, `SimpleAuthenticationHandler`, `SimpleFormAuthenticationListener` and - `SimplePreAuthenticationListener` have been removed. Use Guard instead. -* Removed the `Role` and `SwitchUserRole` classes. Use strings for roles instead. -* Removed the `getReachableRoles()` method from the `RoleHierarchyInterface`. Role hierarchies must implement - the `getReachableRoleNames()` method instead and return roles as strings. -* Removed the `getRoles()` method from the `TokenInterface`. Tokens must implement the `getRoleNames()` method - instead and return roles as strings. + * The `FirewallMapInterface::getListeners()` method must return an array of 3 elements. + * Removed the `ContextListener::setLogoutOnUserChange()` method. + * Removed the `ListenerInterface`, turn your listeners into callables instead. + * Removed the `Firewall::handleRequest()` method, use `Firewall::callListeners()` instead. + * Removed the `AdvancedUserInterface`, use a custom user checker instead. + * Removed `Argon2iPasswordEncoder`, use `SodiumPasswordEncoder` instead + * Removed `BcryptPasswordEncoder`, use `NativePasswordEncoder` instead + * Removed the `has_role()` function from security expressions, use `is_granted()` instead. + * `SimpleAuthenticatorInterface`, `SimpleFormAuthenticatorInterface`, `SimplePreAuthenticatorInterface`, + `SimpleAuthenticationProvider`, `SimpleAuthenticationHandler`, `SimpleFormAuthenticationListener` and + `SimplePreAuthenticationListener` have been removed. Use Guard instead. + * Removed the `Role` and `SwitchUserRole` classes. Use strings for roles instead. + * Removed the `getReachableRoles()` method from the `RoleHierarchyInterface`. Role hierarchies must implement + the `getReachableRoleNames()` method instead and return roles as strings. + * Removed the `getRoles()` method from the `TokenInterface`. Tokens must implement the `getRoleNames()` method + instead and return roles as strings. 4.3.0 ----- diff --git a/src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php b/src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php index 25de3ce44079c..ce8d8730df630 100644 --- a/src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php +++ b/src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php @@ -21,8 +21,6 @@ use Symfony\Component\Security\Guard\AuthenticatorInterface; use Symfony\Component\Security\Guard\GuardAuthenticatorHandler; use Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken; -use Symfony\Component\Security\Http\Firewall\LegacyListenerTrait; -use Symfony\Component\Security\Http\Firewall\ListenerInterface; use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; /** @@ -31,12 +29,10 @@ * @author Ryan Weaver * @author Amaury Leroux de Lens * - * @final since Symfony 4.3 + * @final */ -class GuardAuthenticationListener implements ListenerInterface +class GuardAuthenticationListener { - use LegacyListenerTrait; - private $guardHandler; private $authenticationManager; private $providerKey; diff --git a/src/Symfony/Component/Security/Http/Firewall.php b/src/Symfony/Component/Security/Http/Firewall.php index 7cd51ce21e872..b239911b8b677 100644 --- a/src/Symfony/Component/Security/Http/Firewall.php +++ b/src/Symfony/Component/Security/Http/Firewall.php @@ -11,14 +11,12 @@ namespace Symfony\Component\Security\Http; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Http\Firewall\AccessListener; -use Symfony\Component\Security\Http\Firewall\LogoutListener; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Firewall uses a FirewallMap to register security listeners for the given @@ -38,17 +36,12 @@ class Firewall implements EventSubscriberInterface public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher) { - // the type-hint will be updated to the "EventDispatcherInterface" from symfony/contracts in 5.0 - $this->map = $map; $this->dispatcher = $dispatcher; $this->exceptionListeners = new \SplObjectStorage(); } - /** - * @internal since Symfony 4.3 - */ - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { if (!$event->isMasterRequest()) { return; @@ -57,11 +50,6 @@ public function onKernelRequest(GetResponseEvent $event) // register listeners for this firewall $listeners = $this->map->getListeners($event->getRequest()); - if (3 !== \count($listeners)) { - @trigger_error(sprintf('Not returning an array of 3 elements from %s::getListeners() is deprecated since Symfony 4.2, the 3rd element must be an instance of %s or null.', FirewallMapInterface::class, LogoutListener::class), E_USER_DEPRECATED); - $listeners[2] = null; - } - $authenticationListeners = $listeners[0]; $exceptionListener = $listeners[1]; $logoutListener = $listeners[2]; @@ -93,16 +81,9 @@ public function onKernelRequest(GetResponseEvent $event) } }; - if ($event instanceof RequestEvent) { - $this->callListeners($event, $authenticationListeners()); - } else { - $this->handleRequest($event, $authenticationListeners()); - } + $this->callListeners($event, $authenticationListeners()); } - /** - * @internal since Symfony 4.3 - */ public function onKernelFinishRequest(FinishRequestEvent $event) { $request = $event->getRequest(); @@ -125,22 +106,9 @@ public static function getSubscribedEvents() } protected function callListeners(RequestEvent $event, iterable $listeners) - { - $this->handleRequest($event, $listeners); - } - - /** - * @deprecated since Symfony 4.3, use callListeners instead - */ - protected function handleRequest(GetResponseEvent $event, $listeners) { foreach ($listeners as $listener) { - if (\is_callable($listener)) { - $listener($event); - } else { - @trigger_error(sprintf('Calling the "%s::handle()" method from the firewall is deprecated since Symfony 4.3, implement "__invoke()" instead.', \get_class($this)), E_USER_DEPRECATED); - $listener->handle($event); - } + $listener($event); if ($event->hasResponse()) { break; diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php index 58e188cc4c567..1c8457008d3f6 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -49,12 +48,10 @@ * @author Fabien Potencier * @author Johannes M. Schmitt * - * @internal since Symfony 4.3 + * @internal */ -abstract class AbstractAuthenticationListener implements ListenerInterface +abstract class AbstractAuthenticationListener { - use LegacyListenerTrait; - protected $options; protected $logger; protected $authenticationManager; @@ -95,7 +92,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM 'require_previous_session' => true, ], $options); $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + $this->dispatcher = $dispatcher; $this->httpUtils = $httpUtils; } diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php index 500ae43e498bd..b969ae3bdb1d0 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; @@ -33,12 +32,10 @@ * * @author Fabien Potencier * - * @internal since Symfony 4.3 + * @internal */ -abstract class AbstractPreAuthenticatedListener implements ListenerInterface +abstract class AbstractPreAuthenticatedListener { - use LegacyListenerTrait; - protected $logger; private $tokenStorage; private $authenticationManager; @@ -52,7 +49,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM $this->authenticationManager = $authenticationManager; $this->providerKey = $providerKey; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + $this->dispatcher = $dispatcher; } /** diff --git a/src/Symfony/Component/Security/Http/Firewall/AccessListener.php b/src/Symfony/Component/Security/Http/Firewall/AccessListener.php index e915f024b99ae..8c25d5f9c4561 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AccessListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AccessListener.php @@ -24,12 +24,10 @@ * * @author Fabien Potencier * - * @final since Symfony 4.3 + * @final */ -class AccessListener implements ListenerInterface +class AccessListener { - use LegacyListenerTrait; - private $tokenStorage; private $accessDecisionManager; private $map; diff --git a/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php index b7a7381bfc885..f9f0ff0946400 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php @@ -24,12 +24,10 @@ * * @author Fabien Potencier * - * @final since Symfony 4.3 + * @final */ -class AnonymousAuthenticationListener implements ListenerInterface +class AnonymousAuthenticationListener { - use LegacyListenerTrait; - private $tokenStorage; private $secret; private $authenticationManager; diff --git a/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php index 9d6d81715c294..77c4f9dac96a9 100644 --- a/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php @@ -27,12 +27,10 @@ * * @author Fabien Potencier * - * @final since Symfony 4.3 + * @final */ -class BasicAuthenticationListener implements ListenerInterface +class BasicAuthenticationListener { - use LegacyListenerTrait; - private $tokenStorage; private $authenticationManager; private $providerKey; diff --git a/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php b/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php index 671f279fdf9a2..94515061de88c 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php @@ -22,12 +22,10 @@ * * @author Fabien Potencier * - * @final since Symfony 4.3 + * @final */ -class ChannelListener implements ListenerInterface +class ChannelListener { - use LegacyListenerTrait; - private $map; private $authenticationEntryPoint; private $logger; diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index 98f84d04c0b54..0aa5399c0cfd4 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -28,6 +27,7 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Http\Event\DeauthenticatedEvent; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * ContextListener manages the SecurityContext persistence through a session. @@ -35,12 +35,10 @@ * @author Fabien Potencier * @author Johannes M. Schmitt * - * @final since Symfony 4.3 + * @final */ -class ContextListener implements ListenerInterface +class ContextListener { - use LegacyListenerTrait; - private $tokenStorage; private $sessionKey; private $logger; @@ -66,18 +64,6 @@ public function __construct(TokenStorageInterface $tokenStorage, iterable $userP $this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class); } - /** - * Enables deauthentication during refreshUser when the user has changed. - * - * @param bool $logoutOnUserChange - * - * @deprecated since Symfony 4.1 - */ - public function setLogoutOnUserChange($logoutOnUserChange) - { - @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1.', __METHOD__), E_USER_DEPRECATED); - } - /** * Reads the Security Token from the session. */ diff --git a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php index 76a5a9107b4c2..f79121fe21675 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php @@ -15,7 +15,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -39,7 +39,7 @@ * * @author Fabien Potencier * - * @final since Symfony 4.3, EventDispatcherInterface type-hints will be updated to the interface from symfony/contracts in 5.0 + * @final */ class ExceptionListener { @@ -87,7 +87,7 @@ public function unregister(EventDispatcherInterface $dispatcher) /** * Handles security related exceptions. */ - public function onKernelException(GetResponseForExceptionEvent $event) + public function onKernelException(ExceptionEvent $event) { $exception = $event->getException(); do { @@ -101,7 +101,7 @@ public function onKernelException(GetResponseForExceptionEvent $event) } while (null !== $exception = $exception->getPrevious()); } - private function handleAuthenticationException(GetResponseForExceptionEvent $event, AuthenticationException $exception): void + private function handleAuthenticationException(ExceptionEvent $event, AuthenticationException $exception): void { if (null !== $this->logger) { $this->logger->info('An AuthenticationException was thrown; redirecting to authentication entry point.', ['exception' => $exception]); @@ -115,7 +115,7 @@ private function handleAuthenticationException(GetResponseForExceptionEvent $eve } } - private function handleAccessDeniedException(GetResponseForExceptionEvent $event, AccessDeniedException $exception) + private function handleAccessDeniedException(ExceptionEvent $event, AccessDeniedException $exception) { $event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception)); diff --git a/src/Symfony/Component/Security/Http/Firewall/LegacyListenerTrait.php b/src/Symfony/Component/Security/Http/Firewall/LegacyListenerTrait.php deleted file mode 100644 index 98933e0f3eeff..0000000000000 --- a/src/Symfony/Component/Security/Http/Firewall/LegacyListenerTrait.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Security\Http\Firewall; - -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\RequestEvent; - -/** - * @deprecated - * - * @internal - */ -trait LegacyListenerTrait -{ - /** - * @deprecated since Symfony 4.3, use __invoke() instead - */ - public function handle(GetResponseEvent $event) - { - @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.3, use __invoke() instead.', __METHOD__), E_USER_DEPRECATED); - - if (!$event instanceof RequestEvent) { - $event = new class($event) extends RequestEvent { - private $event; - - public function __construct(GetResponseEvent $event) - { - parent::__construct($event->getKernel(), $event->getRequest(), $event->getRequestType()); - $this->event = $event; - } - - public function getResponse() - { - return $this->event->getResponse(); - } - - public function setResponse(Response $response) - { - $this->event->setResponse($response); - } - - public function hasResponse() - { - return $this->event->hasResponse(); - } - }; - } - - $this->__invoke($event); - } -} diff --git a/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php b/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php deleted file mode 100644 index 88c999a543f89..0000000000000 --- a/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Security\Http\Firewall; - -use Symfony\Component\HttpKernel\Event\GetResponseEvent; - -/** - * Interface that must be implemented by firewall listeners. - * - * @author Johannes M. Schmitt - * - * @deprecated since Symfony 4.3, turn listeners into callables instead - */ -interface ListenerInterface -{ - public function handle(GetResponseEvent $event); -} diff --git a/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php b/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php index 4dabe20a9cb3e..5ec26e7fc4edf 100644 --- a/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php @@ -28,12 +28,10 @@ * * @author Fabien Potencier * - * @final since Symfony 4.3 + * @final */ -class LogoutListener implements ListenerInterface +class LogoutListener { - use LegacyListenerTrait; - private $tokenStorage; private $options; private $handlers; diff --git a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php index ebc03db862952..d2008b412dced 100644 --- a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -31,10 +30,8 @@ * * @final since Symfony 4.3 */ -class RememberMeListener implements ListenerInterface +class RememberMeListener { - use LegacyListenerTrait; - private $tokenStorage; private $rememberMeServices; private $authenticationManager; @@ -49,7 +46,7 @@ public function __construct(TokenStorageInterface $tokenStorage, RememberMeServi $this->rememberMeServices = $rememberMeServices; $this->authenticationManager = $authenticationManager; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + $this->dispatcher = $dispatcher; $this->catchExceptions = $catchExceptions; $this->sessionStrategy = null === $sessionStrategy ? new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE) : $sessionStrategy; } diff --git a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php index e0fa3134f7424..d591d846dcc3d 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -36,12 +35,10 @@ * * @author Fabien Potencier * - * @final since Symfony 4.3 + * @final */ -class SwitchUserListener implements ListenerInterface +class SwitchUserListener { - use LegacyListenerTrait; - const EXIT_VALUE = '_exit'; private $tokenStorage; @@ -69,7 +66,7 @@ public function __construct(TokenStorageInterface $tokenStorage, UserProviderInt $this->usernameParameter = $usernameParameter; $this->role = $role; $this->logger = $logger; - $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); + $this->dispatcher = $dispatcher; $this->stateless = $stateless; } diff --git a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php index ab991572f11cf..9a1e9671f4f60 100644 --- a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -42,12 +41,10 @@ * * @author Kévin Dunglas * - * @final since Symfony 4.3 + * @final */ -class UsernamePasswordJsonAuthenticationListener implements ListenerInterface +class UsernamePasswordJsonAuthenticationListener { - use LegacyListenerTrait; - private $tokenStorage; private $authenticationManager; private $httpUtils; @@ -69,14 +66,11 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM $this->successHandler = $successHandler; $this->failureHandler = $failureHandler; $this->logger = $logger; - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + $this->eventDispatcher = $eventDispatcher; $this->options = array_merge(['username_path' => 'username', 'password_path' => 'password'], $options); $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } - /** - * {@inheritdoc} - */ public function __invoke(RequestEvent $event) { $request = $event->getRequest(); diff --git a/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php b/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php index 1993db5731bcd..66fdc3fc0b2b3 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php +++ b/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Security\Http\RememberMe; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -20,11 +20,11 @@ * * @author Johannes M. Schmitt * - * @final since Symfony 4.3 + * @final */ class ResponseListener implements EventSubscriberInterface { - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse(ResponseEvent $event) { if (!$event->isMasterRequest()) { return; diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php index ac1c5fbab86b2..28e4889594085 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php @@ -15,7 +15,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ExceptionEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; @@ -191,11 +190,7 @@ private function createEvent(\Exception $exception, $kernel = null) $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); } - if (class_exists(ExceptionEvent::class)) { - return new ExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception); - } - - return new GetResponseForExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception); + return new ExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception); } private function createExceptionListener(TokenStorageInterface $tokenStorage = null, AuthenticationTrustResolverInterface $trustResolver = null, HttpUtils $httpUtils = null, AuthenticationEntryPointInterface $authenticationEntryPoint = null, $errorPage = null, AccessDeniedHandlerInterface $accessDeniedHandler = null) diff --git a/src/Symfony/Component/Security/Http/Tests/FirewallTest.php b/src/Symfony/Component/Security/Http/Tests/FirewallTest.php index bb81bc36a7086..916be9d6c18cc 100644 --- a/src/Symfony/Component/Security/Http/Tests/FirewallTest.php +++ b/src/Symfony/Component/Security/Http/Tests/FirewallTest.php @@ -12,14 +12,10 @@ namespace Symfony\Component\Security\Http\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Http\Firewall; -use Symfony\Component\Security\Http\Firewall\ExceptionListener; -use Symfony\Component\Security\Http\FirewallMapInterface; class FirewallTest extends TestCase { @@ -111,33 +107,4 @@ public function testOnKernelRequestWithSubRequest() $this->assertFalse($event->hasResponse()); } - - /** - * @group legacy - * @expectedDeprecation Not returning an array of 3 elements from Symfony\Component\Security\Http\FirewallMapInterface::getListeners() is deprecated since Symfony 4.2, the 3rd element must be an instance of Symfony\Component\Security\Http\Firewall\LogoutListener or null. - */ - public function testMissingLogoutListener() - { - $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); - - $listener = $this->getMockBuilder(ExceptionListener::class)->disableOriginalConstructor()->getMock(); - $listener - ->expects($this->once()) - ->method('register') - ->with($this->equalTo($dispatcher)) - ; - - $request = new Request(); - - $map = $this->getMockBuilder(FirewallMapInterface::class)->getMock(); - $map - ->expects($this->once()) - ->method('getListeners') - ->with($this->equalTo($request)) - ->willReturn([[], $listener]) - ; - - $firewall = new Firewall($map, $dispatcher); - $firewall->onKernelRequest(new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST)); - } }