From 9de1f9bd42c38aedef218af41faade8f78e4a09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 20 May 2021 10:12:11 +0200 Subject: [PATCH] Remove deprecate session service --- .../Bundle/FrameworkBundle/CHANGELOG.md | 8 ++ .../Controller/AbstractController.php | 2 - .../Compiler/SessionPass.php | 72 -------------- .../DependencyInjection/Configuration.php | 9 +- .../FrameworkExtension.php | 37 +------- .../FrameworkBundle/FrameworkBundle.php | 2 - .../Resources/config/session.php | 71 +------------- .../FrameworkBundle/Resources/config/test.php | 6 +- .../Session/DeprecatedSessionFactory.php | 46 --------- .../Controller/AbstractControllerTest.php | 2 - .../Compiler/SessionPassTest.php | 95 ------------------- .../DependencyInjection/ConfigurationTest.php | 3 +- .../FrameworkExtensionTest.php | 13 +-- .../DeprecatedSessionController.php | 16 ---- .../TestBundle/Resources/config/routing.yml | 4 - .../Tests/Functional/SessionTest.php | 20 ---- .../Tests/Functional/app/Session/config.yml | 4 - .../RegisterTokenUsageTrackingPass.php | 1 + .../RegisterTokenUsageTrackingPassTest.php | 4 - .../SecurityRoutingIntegrationTest.php | 5 +- .../RegisterServiceSubscribersPass.php | 3 +- .../Session/Storage/ServiceSessionFactory.php | 2 +- .../EventListener/AbstractSessionListener.php | 1 + .../EventListener/SessionListener.php | 13 ++- .../Storage/UsageTrackingTokenStorage.php | 24 +---- .../Csrf/TokenStorage/SessionTokenStorage.php | 28 +----- .../Tests/Firewall/ContextListenerTest.php | 15 +-- .../CsrfTokenClearingLogoutHandlerTest.php | 15 ++- 28 files changed, 53 insertions(+), 468 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Session/DeprecatedSessionFactory.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SessionPassTest.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/DeprecatedSessionController.php diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 4d67ff130d983..477b1609d2d59 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +6.0 +--- + + * Remove the `session.storage` alias and `session.storage.*` services, use the `session.storage.factory` alias and `session.storage.factory.*` services instead + * Remove `framework.session.storage_id` configuration option, use the `framework.session.storage_factory_id` configuration option instead + * Remove the `session` service and the `SessionInterface` alias, use the `\Symfony\Component\HttpFoundation\Request::getSession()` or the new `\Symfony\Component\HttpFoundation\RequestStack::getSession()` methods instead + * Remove the `session.attribute_bag` service and `session.flash_bag` service + 5.3 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index 3ddd8b185c4a2..b5900c60ae0ad 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -29,7 +29,6 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; -use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -94,7 +93,6 @@ public static function getSubscribedServices() 'request_stack' => '?'.RequestStack::class, 'http_kernel' => '?'.HttpKernelInterface::class, 'serializer' => '?'.SerializerInterface::class, - 'session' => '?'.SessionInterface::class, 'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class, 'twig' => '?'.Environment::class, 'doctrine' => '?'.ManagerRegistry::class, diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php deleted file mode 100644 index 7230fc9fb4ce2..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -/** - * @internal to be removed in 6.0 - */ -class SessionPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container) - { - if (!$container->has('session.factory')) { - return; - } - - // BC layer: Make "session" an alias of ".session.do-not-use" when not overridden by the user - if (!$container->has('session')) { - $alias = $container->setAlias('session', '.session.do-not-use'); - $alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.'); - // restore previous behavior - $alias->setPublic(true); - - return; - } - - if ($container->hasDefinition('session')) { - $definition = $container->getDefinition('session'); - $definition->setDeprecated('symfony/framework-bundle', '5.3', 'The "%service_id%" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.'); - } else { - $alias = $container->getAlias('session'); - $alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" and "SessionInterface" aliases are deprecated, use "$requestStack->getSession()" instead.'); - $definition = $container->findDefinition('session'); - } - - // Convert internal service `.session.do-not-use` into alias of `session`. - $container->setAlias('.session.do-not-use', 'session'); - - $bags = [ - 'session.flash_bag' => $container->hasDefinition('session.flash_bag') ? $container->getDefinition('session.flash_bag') : null, - 'session.attribute_bag' => $container->hasDefinition('session.attribute_bag') ? $container->getDefinition('session.attribute_bag') : null, - ]; - - foreach ($definition->getArguments() as $v) { - if (!$v instanceof Reference || !isset($bags[$bag = (string) $v]) || !\is_array($factory = $bags[$bag]->getFactory())) { - continue; - } - - if ([0, 1] !== array_keys($factory) || !$factory[0] instanceof Reference || !\in_array((string) $factory[0], ['session', '.session.do-not-use'], true)) { - continue; - } - - if ('get'.ucfirst(substr($bag, 8, -4)).'Bag' !== $factory[1]) { - continue; - } - - $bags[$bag]->setFactory(null); - } - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 2f0d24dd858e9..e6e784b87d985 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -612,15 +612,8 @@ private function addSessionSection(ArrayNodeDefinition $rootNode) ->arrayNode('session') ->info('session configuration') ->canBeEnabled() - ->beforeNormalization() - ->ifTrue(function ($v) { - return \is_array($v) && isset($v['storage_id']) && isset($v['storage_factory_id']); - }) - ->thenInvalid('You cannot use both "storage_id" and "storage_factory_id" at the same time under "framework.session"') - ->end() ->children() - ->scalarNode('storage_id')->defaultValue('session.storage.native')->end() - ->scalarNode('storage_factory_id')->defaultNull()->end() + ->scalarNode('storage_factory_id')->defaultValue('session.storage.factory.native')->end() ->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end() ->scalarNode('name') ->validate() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 3c5a9759334c9..daed34b735e5a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -72,7 +72,6 @@ use Symfony\Component\HttpClient\RetryableHttpClient; use Symfony\Component\HttpClient\ScopingHttpClient; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; @@ -1048,20 +1047,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c $loader->load('session.php'); // session storage - if (null === $config['storage_factory_id']) { - trigger_deprecation('symfony/framework-bundle', '5.3', 'Not setting the "framework.session.storage_factory_id" configuration option is deprecated, it will default to "session.storage.factory.native" and will replace the "framework.session.storage_id" configuration option in version 6.0.'); - $container->setAlias('session.storage', $config['storage_id']); - $container->setAlias('session.storage.factory', 'session.storage.factory.service'); - } else { - $container->setAlias('session.storage.factory', $config['storage_factory_id']); - - $container->removeAlias(SessionStorageInterface::class); - $container->removeDefinition('session.storage.metadata_bag'); - $container->removeDefinition('session.storage.native'); - $container->removeDefinition('session.storage.php_bridge'); - $container->removeDefinition('session.storage.mock_file'); - $container->removeAlias('session.storage.filesystem'); - } + $container->setAlias('session.storage.factory', $config['storage_factory_id']); $options = ['cache_limiter' => '0']; foreach (['name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'cookie_samesite', 'use_cookies', 'gc_maxlifetime', 'gc_probability', 'gc_divisor', 'sid_length', 'sid_bits_per_character'] as $key) { @@ -1071,16 +1057,8 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c } if ('auto' === ($options['cookie_secure'] ?? null)) { - if (null === $config['storage_factory_id']) { - $locator = $container->getDefinition('session_listener')->getArgument(0); - $locator->setValues($locator->getValues() + [ - 'session_storage' => new Reference('session.storage', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), - 'request_stack' => new Reference('request_stack'), - ]); - } else { - $container->getDefinition('session.storage.factory.native')->replaceArgument(3, true); - $container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2, true); - } + $container->getDefinition('session.storage.factory.native')->replaceArgument(3, true); + $container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2, true); } $container->setParameter('session.storage.options', $options); @@ -1088,13 +1066,8 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c // session handler (the internal callback registered with PHP session management) if (null === $config['handler_id']) { // Set the handler class to be null - if ($container->hasDefinition('session.storage.native')) { - $container->getDefinition('session.storage.native')->replaceArgument(1, null); - $container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null); - } else { - $container->getDefinition('session.storage.factory.native')->replaceArgument(1, null); - $container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null); - } + $container->getDefinition('session.storage.factory.native')->replaceArgument(1, null); + $container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null); $container->setAlias('session.handler', 'session.handler.native_file'); } else { diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 7f439bb572f87..cfeef6e9f5862 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -20,7 +20,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SessionPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass; @@ -159,7 +158,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RegisterReverseContainerPass(true)); $container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass()); - $container->addCompilerPass(new SessionPass()); if ($container->getParameter('kernel.debug')) { $container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php index 9dbaff5c829e1..576b2b0f175e5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php @@ -11,13 +11,7 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; -use Symfony\Bundle\FrameworkBundle\Session\DeprecatedSessionFactory; -use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; -use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; -use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; -use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\SessionFactory; -use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MarshallingSessionHandler; @@ -25,22 +19,15 @@ use Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory; use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; -use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage; use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorageFactory; -use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory; -use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage; use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorageFactory; -use Symfony\Component\HttpFoundation\Session\Storage\ServiceSessionFactory; -use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; use Symfony\Component\HttpKernel\EventListener\SessionListener; return static function (ContainerConfigurator $container) { $container->parameters()->set('session.metadata.storage_key', '_sf2_meta'); $container->services() - ->set('.session.do-not-use', Session::class) // to be removed in 6.0 - ->factory([service('session.factory'), 'createSession']) ->set('session.factory', SessionFactory::class) ->args([ service('request_stack'), @@ -79,60 +66,9 @@ param('session.metadata.update_threshold'), ]), ]) - ->set('session.storage.factory.service', ServiceSessionFactory::class) - ->args([ - service('session.storage'), - ]) - ->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.native", "session.storage.factory.php_bridge" or "session.storage.factory.mock_file" instead.') - ->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0 - ->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession']) - ->alias(SessionInterface::class, '.session.do-not-use') - ->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" and "SessionInterface" aliases are deprecated, use "$requestStack->getSession()" instead.') - ->alias(SessionStorageInterface::class, 'session.storage') - ->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory" instead.') ->alias(\SessionHandlerInterface::class, 'session.handler') - ->set('session.storage.metadata_bag', MetadataBag::class) - ->args([ - param('session.metadata.storage_key'), - param('session.metadata.update_threshold'), - ]) - ->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, create your own "session.storage.factory" instead.') - - ->set('session.storage.native', NativeSessionStorage::class) - ->args([ - param('session.storage.options'), - service('session.handler'), - service('session.storage.metadata_bag'), - ]) - ->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.native" instead.') - - ->set('session.storage.php_bridge', PhpBridgeSessionStorage::class) - ->args([ - service('session.handler'), - service('session.storage.metadata_bag'), - ]) - ->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.php_bridge" instead.') - - ->set('session.flash_bag', FlashBag::class) - ->factory([service('.session.do-not-use'), 'getFlashBag']) - ->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getFlashBag()" instead.') - ->alias(FlashBagInterface::class, 'session.flash_bag') - - ->set('session.attribute_bag', AttributeBag::class) - ->factory([service('.session.do-not-use'), 'getBag']) - ->args(['attributes']) - ->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getAttributeBag()" instead.') - - ->set('session.storage.mock_file', MockFileSessionStorage::class) - ->args([ - param('kernel.cache_dir').'/sessions', - 'MOCKSESSID', - service('session.storage.metadata_bag'), - ]) - ->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.mock_file" instead.') - ->set('session.handler.native_file', StrictSessionHandler::class) ->args([ inline_service(NativeFileSessionHandler::class) @@ -146,8 +82,7 @@ ->set('session_listener', SessionListener::class) ->args([ service_locator([ - 'session' => service('.session.do-not-use')->ignoreOnInvalid(), - 'initialized_session' => service('.session.do-not-use')->ignoreOnUninitialized(), + 'session_factory' => service('session.factory'), 'logger' => service('logger')->ignoreOnInvalid(), 'session_collector' => service('data_collector.request.session_collector')->ignoreOnInvalid(), ]), @@ -155,10 +90,6 @@ ]) ->tag('kernel.event_subscriber') - // for BC - ->alias('session.storage.filesystem', 'session.storage.mock_file') - ->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory.mock_file" instead.') - ->set('session.marshaller', IdentityMarshaller::class) ->set('session.marshalling_handler', MarshallingSessionHandler::class) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.php index 61e4052521329..47b1e7647dd3d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.php @@ -36,11 +36,7 @@ ->set('test.client.cookiejar', CookieJar::class)->share(false) ->set('test.session.listener', TestSessionListener::class) - ->args([ - service_locator([ - 'session' => service('.session.do-not-use')->ignoreOnInvalid(), - ]), - ]) + ->args([service_locator([])]) ->tag('kernel.event_subscriber') ->set('test.service_container', TestContainer::class) diff --git a/src/Symfony/Bundle/FrameworkBundle/Session/DeprecatedSessionFactory.php b/src/Symfony/Bundle/FrameworkBundle/Session/DeprecatedSessionFactory.php deleted file mode 100644 index faa29a1c7ef59..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Session/DeprecatedSessionFactory.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Session; - -use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\Session\SessionInterface; - -/** - * Provides session and trigger deprecation. - * - * Used by service that should trigger deprecation when accessed by the user. - * - * @author Jérémy Derussé - * - * @internal to be removed in 6.0 - */ -class DeprecatedSessionFactory -{ - private $requestStack; - - public function __construct(RequestStack $requestStack) - { - $this->requestStack = $requestStack; - } - - public function getSession(): ?SessionInterface - { - trigger_deprecation('symfony/framework-bundle', '5.3', 'The "session" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.'); - - try { - return $this->requestStack->getSession(); - } catch (SessionNotFoundException $e) { - return null; - } - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php index 46fab2bcda42a..9b1283e8c1d26 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php @@ -68,7 +68,6 @@ public function testSubscribedServices() 'request_stack' => '?Symfony\\Component\\HttpFoundation\\RequestStack', 'http_kernel' => '?Symfony\\Component\\HttpKernel\\HttpKernelInterface', 'serializer' => '?Symfony\\Component\\Serializer\\SerializerInterface', - 'session' => '?Symfony\\Component\\HttpFoundation\\Session\\SessionInterface', 'security.authorization_checker' => '?Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface', 'twig' => '?Twig\\Environment', 'doctrine' => '?Doctrine\\Persistence\\ManagerRegistry', @@ -503,7 +502,6 @@ public function testAddFlash() $requestStack->push($request); $container = new Container(); - $container->set('session', $session); $container->set('request_stack', $requestStack); $controller = $this->createController(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SessionPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SessionPassTest.php deleted file mode 100644 index 7cbb3262f131f..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SessionPassTest.php +++ /dev/null @@ -1,95 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; - -use PHPUnit\Framework\TestCase; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SessionPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -class SessionPassTest extends TestCase -{ - public function testProcess() - { - $container = new ContainerBuilder(); - $container - ->register('session.factory'); // marker service - $container - ->register('.session.do-not-use'); - - (new SessionPass())->process($container); - - $this->assertTrue($container->hasAlias('session')); - $this->assertSame($container->findDefinition('session'), $container->getDefinition('.session.do-not-use')); - $this->assertTrue($container->getAlias('session')->isDeprecated()); - } - - public function testProcessUserDefinedSession() - { - $arguments = [ - new Reference('session.flash_bag'), - new Reference('session.attribute_bag'), - ]; - $container = new ContainerBuilder(); - $container - ->register('session.factory'); // marker service - $container - ->register('session') - ->setArguments($arguments); - $container - ->register('session.flash_bag') - ->setFactory([new Reference('.session.do-not-use'), 'getFlashBag']); - $container - ->register('session.attribute_bag') - ->setFactory([new Reference('.session.do-not-use'), 'getAttributeBag']); - - (new SessionPass())->process($container); - - $this->assertSame($arguments, $container->getDefinition('session')->getArguments()); - $this->assertNull($container->getDefinition('session.flash_bag')->getFactory()); - $this->assertNull($container->getDefinition('session.attribute_bag')->getFactory()); - $this->assertTrue($container->hasAlias('.session.do-not-use')); - $this->assertSame($container->getDefinition('session'), $container->findDefinition('.session.do-not-use')); - $this->assertTrue($container->getDefinition('session')->isDeprecated()); - } - - public function testProcessUserDefinedAlias() - { - $arguments = [ - new Reference('session.flash_bag'), - new Reference('session.attribute_bag'), - ]; - $container = new ContainerBuilder(); - $container - ->register('session.factory'); // marker service - $container - ->register('trueSession') - ->setArguments($arguments); - $container - ->setAlias('session', 'trueSession'); - $container - ->register('session.flash_bag') - ->setFactory([new Reference('.session.do-not-use'), 'getFlashBag']); - $container - ->register('session.attribute_bag') - ->setFactory([new Reference('.session.do-not-use'), 'getAttributeBag']); - - (new SessionPass())->process($container); - - $this->assertSame($arguments, $container->findDefinition('session')->getArguments()); - $this->assertNull($container->getDefinition('session.flash_bag')->getFactory()); - $this->assertNull($container->getDefinition('session.attribute_bag')->getFactory()); - $this->assertTrue($container->hasAlias('.session.do-not-use')); - $this->assertSame($container->findDefinition('session'), $container->findDefinition('.session.do-not-use')); - $this->assertTrue($container->getAlias('session')->isDeprecated()); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index b056ed498e5ad..25eeb37730296 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -466,8 +466,7 @@ protected static function getBundleDefaultConfig() ], 'session' => [ 'enabled' => false, - 'storage_id' => 'session.storage.native', - 'storage_factory_id' => null, + 'storage_factory_id' => 'session.storage.factory.native', 'handler_id' => 'session.handler.native_file', 'cookie_httponly' => true, 'cookie_samesite' => null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 02f8748c3d996..4de4fbc93d6ae 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -550,9 +550,6 @@ public function testSession() $this->assertTrue($container->hasAlias(SessionInterface::class), '->registerSessionConfiguration() loads session.xml'); $this->assertEquals('fr', $container->getParameter('kernel.default_locale')); $this->assertEquals('session.storage.factory.native', (string) $container->getAlias('session.storage.factory')); - $this->assertFalse($container->has('session.storage')); - $this->assertFalse($container->has('session.storage.native')); - $this->assertFalse($container->has('session.storage.php_bridge')); $this->assertEquals('session.handler.native_file', (string) $container->getAlias('session.handler')); $options = $container->getParameter('session.storage.options'); @@ -581,7 +578,7 @@ public function testNullSessionHandler() $this->assertNull($container->getDefinition('session.storage.factory.php_bridge')->getArgument(0)); $this->assertSame('session.handler.native_file', (string) $container->getAlias('session.handler')); - $expected = ['session', 'initialized_session', 'logger', 'session_collector']; + $expected = ['session_factory', 'logger', 'session_collector']; $this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues())); $this->assertFalse($container->getDefinition('session.storage.factory.native')->getArgument(3)); } @@ -596,11 +593,9 @@ public function testNullSessionHandlerLegacy() $container = $this->createContainerFromFile('session_legacy'); $this->assertTrue($container->hasAlias(SessionInterface::class), '->registerSessionConfiguration() loads session.xml'); - $this->assertNull($container->getDefinition('session.storage.native')->getArgument(1)); - $this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0)); $this->assertSame('session.handler.native_file', (string) $container->getAlias('session.handler')); - $expected = ['session', 'initialized_session', 'logger', 'session_collector']; + $expected = ['session_factory', 'logger', 'session_collector']; $this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues())); $this->assertFalse($container->getDefinition('session.storage.factory.native')->getArgument(3)); } @@ -1618,7 +1613,7 @@ public function testSessionCookieSecureAuto() { $container = $this->createContainerFromFile('session_cookie_secure_auto'); - $expected = ['session', 'initialized_session', 'logger', 'session_collector']; + $expected = ['session_factory', 'logger', 'session_collector']; $this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues())); } @@ -1631,7 +1626,7 @@ public function testSessionCookieSecureAutoLegacy() $container = $this->createContainerFromFile('session_cookie_secure_auto_legacy'); - $expected = ['session', 'initialized_session', 'logger', 'session_collector', 'session_storage', 'request_stack']; + $expected = ['logger', 'session_collector', 'request_stack']; $this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues())); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/DeprecatedSessionController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/DeprecatedSessionController.php deleted file mode 100644 index 75e9673c35a71..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/DeprecatedSessionController.php +++ /dev/null @@ -1,16 +0,0 @@ -get('session'); - - return new Response('done'); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml index d790c1a13125b..b9fe91463fb2b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml @@ -22,10 +22,6 @@ injected_flashbag_session_setflash: path: injected_flashbag/session_setflash/{message} defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\InjectedFlashbagSessionController::setFlashAction} -deprecated_session_setflash: - path: /deprecated_session/trigger - defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\DeprecatedSessionController::triggerAction} - session_showflash: path: /session_showflash defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::showFlashAction } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php index 7d66ff1726657..253947d02fb07 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php @@ -99,26 +99,6 @@ public function testFlashOnInjectedFlashbag($config, $insulate) $this->assertStringContainsString('No flash was set.', $crawler->text()); } - /** - * @group legacy - * @dataProvider getConfigs - */ - public function testSessionServiceTriggerDeprecation($config, $insulate) - { - $this->expectDeprecation('Since symfony/framework-bundle 5.3: The "session" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.'); - - $client = $this->createClient(['test_case' => 'Session', 'root_config' => $config]); - if ($insulate) { - $client->insulate(); - } - - // trigger deprecation - $crawler = $client->request('GET', '/deprecated_session/trigger'); - - // check response - $this->assertStringContainsString('done', $crawler->text()); - } - /** * See if two separate insulated clients can run without * polluting each other's session data. diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Session/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Session/config.yml index 03ee4fb151104..4807c42d1ede8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Session/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Session/config.yml @@ -9,7 +9,3 @@ services: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\InjectedFlashbagSessionController: autowire: true tags: ['controller.service_arguments'] - - Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\DeprecatedSessionController: - autowire: true - autoconfigure: true diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterTokenUsageTrackingPass.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterTokenUsageTrackingPass.php index 5ba017f51e386..4df056887571a 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterTokenUsageTrackingPass.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterTokenUsageTrackingPass.php @@ -41,6 +41,7 @@ public function process(ContainerBuilder $container) TokenStorageInterface::class => new BoundArgument(new Reference('security.untracked_token_storage'), false), ]); + // the `!$container->has('session.storage')` check can be removed when bumping to symfony/framework-bundle:6.0 if (!$container->has('session.factory') && !$container->has('session.storage')) { $container->setAlias('security.token_storage', 'security.untracked_token_storage')->setPublic(true); $container->getDefinition('security.untracked_token_storage')->addTag('kernel.reset', ['method' => 'reset']); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/RegisterTokenUsageTrackingPassTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/RegisterTokenUsageTrackingPassTest.php index 993601ee8e43e..cfc363b557c2c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/RegisterTokenUsageTrackingPassTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/RegisterTokenUsageTrackingPassTest.php @@ -17,10 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\SessionFactory; -use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; -use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Authentication\Token\Storage\UsageTrackingTokenStorage; use Symfony\Component\Security\Http\Firewall\ContextListener; @@ -44,7 +41,6 @@ public function testContextListenerIsNotModifiedIfTokenStorageDoesNotSupportUsag $container = new ContainerBuilder(); $container->setParameter('security.token_storage.class', TokenStorage::class); - $container->register('session', Session::class); $container->register('security.context_listener', ContextListener::class) ->setArguments([ new Reference('security.untracked_token_storage'), diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php index b649a4e6fa97c..b5b4a2c07f1a0 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php @@ -136,8 +136,9 @@ public function testPublicHomepage() $this->assertEquals(200, $client->getResponse()->getStatusCode(), (string) $client->getResponse()); $this->assertTrue($client->getResponse()->headers->getCacheControlDirective('public')); - $this->assertSame(0, self::getContainer()->get('session')->getUsageIndex()); + $this->assertSame(0, self::getContainer()->get('request_stack')->getSession()->getUsageIndex()); } + /** * @dataProvider provideLegacyClientOptions * @group legacy @@ -273,7 +274,7 @@ public function testLegacyPublicHomepage() $this->assertEquals(200, $client->getResponse()->getStatusCode(), (string) $client->getResponse()); $this->assertTrue($client->getResponse()->headers->getCacheControlDirective('public')); - $this->assertSame(0, self::getContainer()->get('session')->getUsageIndex()); + $this->assertSame(0, self::getContainer()->get('request_stack')->getSession()->getUsageIndex()); } private function assertAllowed($client, $path) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php index 055cb3490bc6b..3ca0c0f2dd8b2 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php @@ -68,6 +68,7 @@ protected function processValue($value, bool $isRoot = false) throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $this->currentId, ServiceSubscriberInterface::class)); } $class = $r->name; + // to remove when bumping to symfony/framework-bundle:6.0 $replaceDeprecatedSession = $this->container->has('.session.deprecated') && $r->isSubclassOf(AbstractController::class); $subscriberMap = []; @@ -89,7 +90,7 @@ protected function processValue($value, bool $isRoot = false) } if ($replaceDeprecatedSession && SessionInterface::class === $type) { // This prevents triggering the deprecation when building the container - // Should be removed in Symfony 6.0 + // Should be removed when bumping to symfony/framework-bundle:6.0 $type = '.session.deprecated'; } $serviceMap[$key] = new Reference($type); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/ServiceSessionFactory.php b/src/Symfony/Component/HttpFoundation/Session/Storage/ServiceSessionFactory.php index d17c60aebaac1..6d29bf8b161db 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/ServiceSessionFactory.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/ServiceSessionFactory.php @@ -16,7 +16,7 @@ /** * @author Jérémy Derussé * - * @internal to be removed in Symfony 6 + * @internal to be removed when bumping to symfony/framework-bundle:6.0 */ final class ServiceSessionFactory implements SessionStorageFactoryInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php b/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php index eae5fb6bab225..027dde515b0b8 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php @@ -62,6 +62,7 @@ public function onKernelRequest(RequestEvent $event) $request->setSessionFactory(function () use (&$sess) { return $sess ?? $sess = $this->getSession(); }); } + // Code related to `initialized_session` can be removed when bumping symfony/framework-bundle:6.0 $session = $this->container && $this->container->has('initialized_session') ? $this->container->get('initialized_session') : null; $this->sessionUsageStack[] = $session instanceof Session ? $session->getUsageIndex() : 0; } diff --git a/src/Symfony/Component/HttpKernel/EventListener/SessionListener.php b/src/Symfony/Component/HttpKernel/EventListener/SessionListener.php index f2b950cef2e2e..4f46367881c0f 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/SessionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/SessionListener.php @@ -25,6 +25,8 @@ * * @author Fabien Potencier * + * @internal to empty (or merge with AbstractSessionListener) when bumping to symfony/framework-bundle:6.0 + * * @final */ class SessionListener extends AbstractSessionListener @@ -53,10 +55,15 @@ public function onKernelRequest(RequestEvent $event) protected function getSession(): ?SessionInterface { - if (!$this->container->has('session')) { - return null; + // BC layer to remove when bumping symfony/framework-bundle:6.0 + if ($this->container->has('session')) { + return $this->container->get('session'); + } + + if ($this->container->has('session_factory')) { + return $this->container->get('session_factory')->createSession(); } - return $this->container->get('session'); + return null; } } diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/Storage/UsageTrackingTokenStorage.php b/src/Symfony/Component/Security/Core/Authentication/Token/Storage/UsageTrackingTokenStorage.php index 4b2cac747abf5..d9f7f12af40ff 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/Storage/UsageTrackingTokenStorage.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/Storage/UsageTrackingTokenStorage.php @@ -79,33 +79,11 @@ public static function getSubscribedServices(): array private function getSession(): SessionInterface { - // BC for symfony/security-bundle < 5.3 - if ($this->container->has('session')) { - trigger_deprecation('symfony/security-core', '5.3', 'Injecting the "session" in "%s" is deprecated, inject the "request_stack" instead.', __CLASS__); - - return $this->container->get('session'); - } - return $this->container->get('request_stack')->getSession(); } private function shouldTrackUsage(): bool { - if (!$this->enableUsageTracking) { - return false; - } - - // BC for symfony/security-bundle < 5.3 - if ($this->container->has('session')) { - return true; - } - - if (!$this->container->get('request_stack')->getMainRequest()) { - trigger_deprecation('symfony/security-core', '5.3', 'Using "%s" (service ID: "security.token_storage") outside the request-response cycle is deprecated, use the "%s" class (service ID: "security.untracked_token_storage") instead or disable usage tracking using "disableUsageTracking()".', __CLASS__, TokenStorage::class); - - return false; - } - - return true; + return $this->enableUsageTracking; } } diff --git a/src/Symfony/Component/Security/Csrf/TokenStorage/SessionTokenStorage.php b/src/Symfony/Component/Security/Csrf/TokenStorage/SessionTokenStorage.php index 70613f5f26f25..eceaefc92d463 100644 --- a/src/Symfony/Component/Security/Csrf/TokenStorage/SessionTokenStorage.php +++ b/src/Symfony/Component/Security/Csrf/TokenStorage/SessionTokenStorage.php @@ -11,12 +11,9 @@ namespace Symfony\Component\Security\Csrf\TokenStorage; -use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException; /** @@ -33,27 +30,14 @@ class SessionTokenStorage implements ClearableTokenStorageInterface private $requestStack; private $namespace; - /** - * Tp be remove in Symfony 6.0 - */ - private $session; /** * Initializes the storage with a RequestStack object and a session namespace. * - * @param RequestStack $requestStack - * @param string $namespace The namespace under which the token is stored in the requestStack + * @param string $namespace The namespace under which the token is stored in the requestStack */ - public function __construct(/* RequestStack*/ $requestStack, string $namespace = self::SESSION_NAMESPACE) + public function __construct(RequestStack $requestStack, string $namespace = self::SESSION_NAMESPACE) { - if ($requestStack instanceof SessionInterface) { - trigger_deprecation('symfony/security-csrf', '5.3', 'Passing a "%s" to "%s" is deprecated, use a "%s" instead.', SessionInterface::class, __CLASS__, RequestStack::class); - $request = new Request(); - $request->setSession($requestStack); - - $requestStack = new RequestStack(); - $requestStack->push($request); - } $this->requestStack = $requestStack; $this->namespace = $namespace; } @@ -129,12 +113,6 @@ public function clear() private function getSession(): SessionInterface { - try { - return $this->requestStack->getSession(); - } catch (SessionNotFoundException $e) { - trigger_deprecation('symfony/security-csrf', '5.3', 'Using the "%s" without a session has no effect and is deprecated. It will throw a "%s" in Symfony 6.0', __CLASS__, SessionNotFoundException::class); - - return $this->session ?? $this->session = new Session(new MockArraySessionStorage()); - } + return $this->requestStack->getSession(); } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php index f995d215cabf1..2c5c82dbc16bf 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php @@ -426,17 +426,10 @@ private function handleEventWithPreviousSession($userProviders, UserInterface $u $tokenStorage = new TokenStorage(); $usageIndex = $session->getUsageIndex(); - $tokenStorage = new UsageTrackingTokenStorage($tokenStorage, new class( - (new \ReflectionClass(UsageTrackingTokenStorage::class))->hasMethod('getSession') ? [ - 'request_stack' => function () use ($requestStack) { - return $requestStack; - }] : [ - // BC for symfony/framework-bundle < 5.3 - 'session' => function () use ($session) { - return $session; - }, - ] - ) implements ContainerInterface { + $tokenStorage = new UsageTrackingTokenStorage($tokenStorage, new class(['request_stack' => function () use ($requestStack) { + return $requestStack; + }, + ]) implements ContainerInterface { use ServiceLocatorTrait; }); $sessionTrackerEnabler = [$tokenStorage, 'enableUsageTracking']; diff --git a/src/Symfony/Component/Security/Http/Tests/Logout/CsrfTokenClearingLogoutHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/Logout/CsrfTokenClearingLogoutHandlerTest.php index 6942745e882a9..beebd1ff36434 100644 --- a/src/Symfony/Component/Security/Http/Tests/Logout/CsrfTokenClearingLogoutHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Logout/CsrfTokenClearingLogoutHandlerTest.php @@ -32,15 +32,12 @@ protected function setUp(): void { $this->session = new Session(new MockArraySessionStorage()); - // BC for symfony/security-core < 5.3 - if (\method_exists(SessionTokenStorage::class, 'getSession')) { - $request = new Request(); - $request->setSession($this->session); - $this->requestStack = new RequestStack(); - $this->requestStack->push($request); - } - - $this->csrfTokenStorage = new SessionTokenStorage($this->requestStack ?? $this->session, 'foo'); + $request = new Request(); + $request->setSession($this->session); + $this->requestStack = new RequestStack(); + $this->requestStack->push($request); + + $this->csrfTokenStorage = new SessionTokenStorage($this->requestStack, 'foo'); $this->csrfTokenStorage->setToken('foo', 'bar'); $this->csrfTokenStorage->setToken('foobar', 'baz'); $this->csrfTokenClearingLogoutHandler = new CsrfTokenClearingLogoutHandler($this->csrfTokenStorage);