Skip to content

[Security][Http] Remove BC layers #31782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,24 @@
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;

/**
* Wraps a security listener for calls record.
*
* @author Robin Chalas <robin.chalas@gmail.com>
*
* @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;

Expand All @@ -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();
}
Expand Down
28 changes: 16 additions & 12 deletions src/Symfony/Component/Security/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -31,12 +29,10 @@
* @author Ryan Weaver <ryan@knpuniversity.com>
* @author Amaury Leroux de Lens <amaury@lerouxdelens.com>
*
* @final since Symfony 4.3
* @final
*/
class GuardAuthenticationListener implements ListenerInterface
class GuardAuthenticationListener
{
use LegacyListenerTrait;

private $guardHandler;
private $authenticationManager;
private $providerKey;
Expand Down
40 changes: 4 additions & 36 deletions src/Symfony/Component/Security/Http/Firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,12 +48,10 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @internal since Symfony 4.3
* @internal
*/
abstract class AbstractAuthenticationListener implements ListenerInterface
abstract class AbstractAuthenticationListener
{
use LegacyListenerTrait;

protected $options;
protected $logger;
protected $authenticationManager;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,12 +32,10 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @internal since Symfony 4.3
* @internal
*/
abstract class AbstractPreAuthenticatedListener implements ListenerInterface
abstract class AbstractPreAuthenticatedListener
{
use LegacyListenerTrait;

protected $logger;
private $tokenStorage;
private $authenticationManager;
Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.3
* @final
*/
class AccessListener implements ListenerInterface
class AccessListener
{
use LegacyListenerTrait;

private $tokenStorage;
private $accessDecisionManager;
private $map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.3
* @final
*/
class AnonymousAuthenticationListener implements ListenerInterface
class AnonymousAuthenticationListener
{
use LegacyListenerTrait;

private $tokenStorage;
private $secret;
private $authenticationManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.3
* @final
*/
class BasicAuthenticationListener implements ListenerInterface
class BasicAuthenticationListener
{
use LegacyListenerTrait;

private $tokenStorage;
private $authenticationManager;
private $providerKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.3
* @final
*/
class ChannelListener implements ListenerInterface
class ChannelListener
{
use LegacyListenerTrait;

private $map;
private $authenticationEntryPoint;
private $logger;
Expand Down
20 changes: 3 additions & 17 deletions src/Symfony/Component/Security/Http/Firewall/ContextListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,19 +27,18 @@
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.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @final since Symfony 4.3
* @final
*/
class ContextListener implements ListenerInterface
class ContextListener
{
use LegacyListenerTrait;

private $tokenStorage;
private $sessionKey;
private $logger;
Expand All @@ -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.
*/
Expand Down
Loading