8000 feature #50866 [Security] Remove deprecated code paths (nicolas-grekas) · symfony/symfony@b7122d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7122d8

Browse files
feature #50866 [Security] Remove deprecated code paths (nicolas-grekas)
This PR was merged into the 7.0 branch. Discussion ---------- [Security] Remove deprecated code paths | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - * Remove configuration options `enable_authenticator_manager` and `csrf_token_generator` * Remove `{username}` parameter, use `{user_identifier}` instead * A few other things that are not worth mentioning in the changelog IMHO Commits ------- a3a3856 [Security] Remove deprecated code paths
2 parents 4dfe50e + a3a3856 commit b7122d8

File tree

26 files changed

+46
-458
lines changed

26 files changed

+46
-458
lines changed

.github/expected-missing-return-types.diff

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,10 +2389,10 @@ index cecce6c01b..f2e0c7fdf5 100644
23892389
{
23902390
parent::newLine($count);
23912391
diff --git a/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php b/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php
2392-
index 6ad89dc522..40020baee7 100644
2392+
index 10bed7d031..e26109851f 100644
23932393
--- a/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php
23942394
+++ b/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php
2395-
@@ -141,5 +141,5 @@ class NonStringInput extends Input
2395+
@@ -128,5 +128,5 @@ class NonStringInput extends Input
23962396
}
23972397

23982398
- public function parse()
@@ -9981,17 +9981,17 @@ index eabfe17bba..5a41823338 100644
99819981
{
99829982
throw new \BadMethodCallException('Cannot add attribute to NullToken.');
99839983
diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/Storage/To 10000 kenStorage.php b/src/Symfony/Component/Security/Core/Authentication/Token/Storage/TokenStorage.php
9984-
index 0ec6b1cfb9..2e235a6069 100644
9984+
index 8acc31bca2..25779a31b5 100644
99859985
--- a/src/Symfony/Component/Security/Core/Authentication/Token/Storage/TokenStorage.php
99869986
+++ b/src/Symfony/Component/Security/Core/Authentication/Token/Storage/TokenStorage.php
99879987
@@ -41,5 +41,5 @@ class TokenStorage implements TokenStorageInterface, ResetInterface
99889988
* @return void
99899989
*/
9990-
- public function setToken(TokenInterface $token = null)
9991-
+ public function setToken(TokenInterface $token = null): void
9990+
- public function setToken(?TokenInterface $token)
9991+
+ public function setToken(?TokenInterface $token): void
99929992
{
9993-
if (1 > \func_num_args()) {
9994-
@@ -64,5 +64,5 @@ class TokenStorage implements TokenStorageInterface, ResetInterface
9993+
if ($token) {
9994+
@@ -60,5 +60,5 @@ class TokenStorage implements TokenStorageInterface, ResetInterface
99959995
* @return void
99969996
*/
99979997
- public function reset()
@@ -10172,23 +10172,16 @@ index a493b00e79..377dcacc09 100644
1017210172
{
1017310173
}
1017410174
diff --git a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php
10175-
index e0aef90a14..651578d1f1 100644
10175+
index 13441bc758..e2bc96ff48 100644
1017610176
--- a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php
1017710177
+++ b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php
10178-
@@ -55,5 +55,5 @@ class InMemoryUserProvider implements UserProviderInterface
10179-
* @throws \LogicException
10178+
@@ -53,5 +53,5 @@ class InMemoryUserProvider implements UserProviderInterface
10179+
* @return void
1018010180
*/
1018110181
- public function createUser(UserInterface $user)
1018210182
+ public function createUser(UserInterface $user): void
1018310183
{
1018410184
if (!$user instanceof InMemoryUser) {
10185-
@@ -100,5 +100,5 @@ class InMemoryUserProvider implements UserProviderInterface
10186-
* @throws UserNotFoundException if user whose given username does not exist
10187-
*/
10188-
- private function getUser(string $username): UserInterface
10189-
+ private function getUser(string $username): InMemoryUser
10190-
{
10191-
if (!isset($this->users[strtolower($username)])) {
1019210185
diff --git a/src/Symfony/Component/Security/Core/User/UserCheckerInterface.php b/src/Symfony/Component/Security/Core/User/UserCheckerInterface.php
1019310186
index 91f21c71d0..95e818392e 100644
1019410187
--- a/src/Symfony/Component/Security/Core/User/UserCheckerInterface.php

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Enabling SecurityBundle and not configuring it is not allowed
8+
* Remove configuration options `enable_authenticator_manager` and `csrf_token_generator`
89

910
6.4
1011
---

src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function getConfigTreeBuilder(): TreeBuilder
6565
->end()
6666
->booleanNode('hide_user_not_found')->defaultTrue()->end()
6767
->booleanNode('erase_credentials')->defaultTrue()->end()
68-
->booleanNode('enable_authenticator_manager')->setDeprecated('symfony/security-bundle', '6.2', 'The "%node%" option at "%path%" is deprecated.')->defaultTrue()->end()
6968
->arrayNode('access_decision_manager')
7069
->addDefaultsIfNotSet()
7170
->children()
@@ -216,14 +215,6 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
216215
->arrayNode('logout')
217216
->treatTrueLike([])
218217
-& 57AE gt;canBeUnset()
219-
->beforeNormalization()
220-
->ifTrue(fn ($v): bool => isset($v['csrf_token_generator']) && !isset($v['csrf_token_manager']))
221-
->then(function (array $v): array {
222-
$v['csrf_token_manager'] = $v['csrf_token_generator'];
223-
224-
return $v;
225-
})
226-
->end()
227218
->beforeNormalization()
228219
->ifTrue(fn ($v): bool => \is_array($v) && (isset($v['csrf_token_manager']) xor isset($v['enable_csrf'])))
229220
->then(function (array $v): array {
@@ -240,13 +231,6 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
240231
->booleanNode('enable_csrf')->defaultNull()->end()
241232
->scalarNode('csrf_token_id')->defaultValue('logout')->end()
242233
->scalarNode('csrf_parameter')->defaultValue('_csrf_token')->end()
243-
->scalarNode('csrf_token_generator')
244-
->setDeprecated(
245-
'symfony/security-bundle',
246-
'6.3',
247-
'The "%node%" option is deprecated. Use "csrf_token_manager" instead.'
248-
)
249-
->end()
250234
->scalarNode('csrf_token_manager')->end()
251235
->scalarNode('path')->defaultValue('/logout')->end()
252236
->scalarNode('target')->defaultValue('/')->end()

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory;
1313

14-
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
15-
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1614
use Symfony\Component\DependencyInjection\ChildDefinition;
1715
use Symfony\Component\DependencyInjection\ContainerBuilder;
1816
use Symfony\Component\DependencyInjection\Reference;
@@ -50,23 +48,8 @@ public function getKey(): string
5048
return 'form-login';
5149
}
5250

53-
public function addConfiguration(NodeDefinition $node): void
54-
{
55-
parent::addConfiguration($node);
56-
57-
$node
58-
->children()
59-
->scalarNode('csrf_token_generator')->cannotBeEmpty()->end()
60-
->end()
61-
;
62-
}
63-
6451
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
6552
{
66-
if (isset($config['csrf_token_generator'])) {
67-
throw new InvalidConfigurationException('The "csrf_token_generator" on "form_login" does not exist, use "enable_csrf" instead.');
68-
}
69-
7053
$authenticatorId = 'security.authenticator.form_login.'.$firewallName;
7154
$options = array_intersect_key($config, $this->options);
7255
$authenticator = $container

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
use Symfony\Component\Security\Core\Authorization\Strategy\PriorityStrategy;
5555
use Symfony\Component\Security\Core\Authorization\Strategy\UnanimousStrategy;
5656
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
57-
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
5857
use Symfony\Component\Security\Core\User\ChainUserChecker;
5958
use Symfony\Component\Security\Core\User\ChainUserProvider;
6059
use Symfony\Component\Security\Core\User\UserCheckerInterface;
@@ -104,11 +103,6 @@ public function load(array $configs, ContainerBuilder $container): void
104103
$loader->load('security.php');
105104
$loader->load('password_hasher.php');
106105
$loader->load('security_listeners.php');
107-
108-
if (!$config['enable_authenticator_manager']) {
109-
throw new InvalidConfigurationException('"security.enable_authenticator_manager" must be set to "true".');
110-
}
111-
112106
$loader->load('security_authenticator.php');
113107
$loader->load('security_authenticator_access_token.php');
114108

@@ -177,11 +171,6 @@ public function load(array $configs, ContainerBuilder $container): void
177171

178172
$container->registerForAutoconfiguration(VoterInterface::class)
179173
->addTag('security.voter');
180-
181-
// required for compatibility with Symfony 5.4
182-
$container->getDefinition('security.access_listener')->setArgument(3, false);
183-
$container->getDefinition('security.authorization_checker')->setArgument(2, false);
184-
$container->getDefinition('security.authorization_checker')->setArgument(3, false);
185174
}
186175

187176
private function createStrategyDefinition(string $strategy, bool $allowIfAllAbstainDecisions, bool $allowIfEqualGrantedDeniedDecisions): Definition
@@ -666,15 +655,11 @@ private function getUserProvider(ContainerBuilder $container, string $id, array
666655
return $this->createMissingUserProvider($container, $id, $factoryKey);
667656
}
668657

669-
if ('remember_me' === $factoryKey || 'anonymous' === $factoryKey || 'custom_authenticators' === $factoryKey) {
670-
if ('custom_authenticators' === $factoryKey) {
671-
trigger_deprecation('symfony/security-bundle', '5.4', 'Not configuring explicitly the provider for the "%s" firewall is deprecated because it\'s ambiguous as there is more than one registered provider. Set the "provider" key to one of the configured providers, even if your custom authenticators don\'t use it.', $id);
672-
}
673-
658+
if ('remember_me' === $factoryKey || 'anonymous' === $factoryKey) {
674659
return 'security.user_providers';
675660
}
676661

677-
throw new InvalidConfigurationException(sprintf('Not configuring explicitly the provider for the "%s" authenticator on "%s" firewall is ambiguous as there is more than one registered provider.', $factoryKey, $id));
662+
throw new InvalidConfigurationException(sprintf('Not configuring explicitly the provider for the "%s" authenticator on "%s" firewall is ambiguous as there is more than one registered provider. Set the "provider" key to one of the configured providers, even if your custom authenticators don\'t use it.', $factoryKey, $id));
678663
}
679664

680665
private function createMissingUserProvider(ContainerBuilder $container, string $id, string $factoryKey): string

src/Symfony/Bundle/SecurityBundle/Resources/config/security.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use Symfony\Component\Security\Core\Authorization\Voter\RoleVoter;
3636
use Symfony\Component\Security\Core\Role\RoleHierarchy;
3737
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
38-
use Symfony\Component\Security\Core\Security as LegacySecurity;
3938
use Symfony\Component\Security\Core\User\ChainUserProvider;
4039
use Symfony\Component\Security\Core\User\InMemoryUserChecker;
4140
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
@@ -94,8 +93,6 @@
9493
abstract_arg('authenticators'),
9594
])
9695
->alias(Security::class, 'security.helper')
97-
->alias(LegacySecurity::class, 'security.helper')
98-
->deprecate('symfony/security-bundle', '6.2', 'The "%alias_id%" service alias is deprecated, use "'.Security::class.'" instead.')
9996

10097
->set('security.user_value_resolver', UserValueResolver::class)
10198
->args([

src/Symfony/Bundle/SecurityBundle/Security.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,13 @@
2020
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
2121
use Symfony\Component\Security\Core\Exception\LogicException;
2222
use Symfony\Component\Security\Core\Exception\LogoutException;
23-
use Symfony\Component\Security\Core\Security as LegacySecurity;
2423
use Symfony\Component\Security\Core\User\UserInterface;
2524
use Symfony\Component\Security\Csrf\CsrfToken;
2625
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
2726
use Symfony\Component\Security\Http\Event\LogoutEvent;
2827
use Symfony\Component\Security\Http\ParameterBagUtils;
29-
use Symfony\Component\Security\Http\SecurityRequestAttributes;
3028
use Symfony\Contracts\Service\ServiceProviderInterface;
3129

32-
if (class_exists(LegacySecurity::class)) {
33-
class_alias(LegacySecurity::class, InternalSecurity::class);
34-
} else {
35-
/**
36-
* @internal
37-
*/
38-
class InternalSecurity
39-
{
40-
}
41-
}
42-
4330
/**
4431
* Helper class for commonly-needed security tasks.
4532
*
@@ -49,23 +36,8 @@ class InternalSecurity
4936
*
5037
* @final
5138
*/
52-
class Security extends InternalSecurity implements AuthorizationCheckerInterface
39+
class Security implements AuthorizationCheckerInterface
5340
{
54-
/**
55-
* @deprecated since Symfony 6.4, use SecurityRequestAttributes::ACCESS_DENIED_ERROR instead
56-
*/
57-
public const ACCESS_DENIED_ERROR = SecurityRequestAttributes::ACCESS_DENIED_ERROR;
58-
59-
/**
60-
* @deprecated since Symfony 6.4, use SecurityRequestAttributes::ACCESS_DENIED_ERROR instead
61-
*/
62-
public const AUTHENTICATION_ERROR = SecurityRequestAttributes::AUTHENTICATION_ERROR;
63-
64-
/**
65-
* @deprecated since Symfony 6.4, use SecurityRequestAttributes::ACCESS_DENIED_ERROR instead
66-
*/
67-
public const LAST_USERNAME = SecurityRequestAttributes::LAST_USERNAME;
68-
6941
public function __construct(
7042
private readonly ContainerInterface $container,
7143
private readonly array $authenticators = [],

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@
3030
use Symfony\Component\HttpFoundation\Response;
3131
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
3232
use Symfony\Component\Security\Core\Exception\AuthenticationException;
33-
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
3433
use Symfony\Component\Security\Core\User\InMemoryUserChecker;
3534
use Symfony\Component\Security\Core\User\UserCheckerInterface;
3635
use Symfony\Component\Security\Core\User\UserInterface;
3736
use Symfony\Component\Security\Core\User\UserProviderInterface;
3837
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
3938
use Symfony\Component\Security\Http\Authenticator\HttpBasicAuthenticator;
4039
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
41-
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
4240

4341
class SecurityExtensionTest extends TestCase
4442
{
@@ -162,8 +160,6 @@ public function testPerListenerProvider()
162160

163161
public function testMissingProviderForListener()
164162
{
165-
$this->expectException(InvalidConfigurationException::class);
166-
$this->expectExceptionMessage('Not configuring explicitly the provider for the "http_basic" authenticator on "ambiguous" firewall is ambiguous as there is more than one registered provider.');
167163
$container = $this->getRawContainer();
168164
$container->loadFromExtension('security', [
169165
'providers' => [
@@ -179,6 +175,9 @@ public function testMissingProviderForListener()
179175
],
180176
]);
181177

178+
$this->expectException(InvalidConfigurationException::class);
179+
$this->expectExceptionMessage('Not configuring explicitly the provider for the "http_basic" authenticator on "ambiguous" firewall is ambiguous as there is more than one registered provider. Set the "provider" key to one of the configured providers, even if your custom authenticators don\'t use it.');
180+
182181
$container->compile();
183182
}
184183

@@ -476,31 +475,6 @@ public function testDoNotRegisterTheUserProviderAliasWithMultipleProviders()
476475
$this->assertFalse($container->has(UserProviderInterface::class));
477476
}
478477

479-
/**
480-
* @group legacy
481-
*/
482-
public function testFirewallWithNoUserProviderTriggerDeprecation()
483-
{
484-
$container = $this->getRawContainer();
485-
486-
$container->loadFromExtension('security', [
487-
'providers' => [
488-
'first' => ['id' => 'foo'],
489-
'second' => ['id' => 'foo'],
490-
],
491-
492-
'firewalls' => [
493-
'some_firewall' => [
494-
'custom_authenticator' => 'my_authenticator',
495-
],
496-
],
497-
]);
498-
499-
$this->expectDeprecation('Since symfony/security-bundle 5.4: Not configuring explicitly the provider for the "some_firewall" firewall is deprecated because it\'s ambiguous as there is more than one registered provider. Set the "provider" key to one of the configured providers, even if your custom authenticators don\'t use it.');
500-
501-
$container->compile();
502-
}
503-
504478
/**
505479
* @dataProvider acceptableIpsProvider
506480
*/
@@ -878,7 +852,7 @@ public function testNothingDoneWithEmptyConfiguration()
878852

879853
$container->loadFromExtension('security');
880854

881-
$this->expectException(InvalidArgumentException::class);
855+
$this->expectException(InvalidConfigurationException::class);
882856
$this->expectExceptionMessage('Enabling bundle "Symfony\Bundle\SecurityBundle\SecurityBundle" and not configuring it is not allowed.');
883857

884858
$container->compile();
@@ -923,13 +897,6 @@ public function authenticate(Request $request): Passport
923897
{
924898
}
925899

926-
/**
927-
* @internal for compatibility with Symfony 5.4
928-
*/
929-
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
930-
{
931-
}
932-
933900
public function createToken(Passport $passport, string $firewallName): TokenInterface
934901
{
935902
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticatorTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@
1313

1414
class AuthenticatorTest extends AbstractWebTestCase
1515
{
16-
/**
17-
* @group legacy
18-
*
19-
* @dataProvider provideEmails
20-
*/
21-
public function testLegacyGlobalUserProvider($email)
22-
{
23-
$client = $this->createClient(['test_case' => 'Authenticator', 'root_config' => 'implicit_user_provider.yml']);
24-
25-
$client->request('GET', '/profile', [], [], [
26-
'HTTP_X-USER-EMAIL' => $email,
27-
]);
28-
$this->assertJsonStringEqualsJsonString('{"email":"'.$email.'"}', $client->getResponse()->getContent());
29-
}
30-
3116
/**
3217
* @dataProvider provideEmails
3318
*/

src/Symfony/Component/Ldap/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.0
5+
---
6+
7+
* Remove `{username}` parameter, use `{user_identifier}` instead
8+
49
6.2
510
---
611

0 commit comments

Comments
 (0)
0