8000 [Security] Remove deprecated code paths · symfony/symfony@d66a550 · GitHub
[go: up one dir, main page]

Skip to content

Commit d66a550

Browse files
[Security] Remove deprecated code paths
1 parent cfd0812 commit d66a550

File tree

26 files changed

+46
-453
lines changed

26 files changed

+46
-453
lines changed

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

+10-17
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/TokenStorage.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

+1
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

-16
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
->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

-15
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,8 @@ public function getKey(): string
5050
return 'form-login';
5151
}
5252

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-
6453
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
6554
{
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-
7055
$authenticatorId = 'security.authenticator.form_login.'.$firewallName;
7156
$options = array_intersect_key($config, $this->options);
7257
$authenticator = $container

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

+2-17
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

-3
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

+1-28
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
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;
@@ -29,17 +28,6 @@
2928
use Symfony\Component\Security\Http\SecurityRequestAttributes;
3029
use Symfony\Contracts\Service\ServiceProviderInterface;
3130

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-
4331
/**
4432
* Helper class for commonly-needed security tasks.
4533
*
@@ -49,23 +37,8 @@ class InternalSecurity
4937
*
5038
* @final
5139
*/
52-
class Security extends InternalSecurity implements AuthorizationCheckerInterface
40+
class Security implements AuthorizationCheckerInterface
5341
{
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-
6942
public function __construct(
7043
private readonly ContainerInterface $container,
7144
private readonly array $authenticators = [],

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

+4-36
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
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;
@@ -162,8 +161,6 @@ public function testPerListenerProvider()
162161

163162
public function testMissingProviderForListener()
164163
{
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.');
167164
$container = $this->getRawContainer();
168165
$container->loadFromExtension('security', [
169166
'providers' => [
@@ -179,6 +176,9 @@ public function testMissingProviderForListener()
179176
],
180177
]);
181178

179+
$this->expectException(InvalidConfigurationException::class);
180+
$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.');
181+
182182
$container->compile();
183183
}
184184

@@ -476,31 +476,6 @@ public function testDoNotRegisterTheUserProviderAliasWithMultipleProviders()
476476
$this->assertFalse($container->has(UserProviderInterface::class));
477477
}
478478

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-
504479
/**
505480
* @dataProvider acceptableIpsProvider
506481
*/
@@ -878,7 +853,7 @@ public function testNothingDoneWithEmptyConfiguration()
878853

879854
$container->loadFromExtension('security');
880855

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

884859
$container->compile();
@@ -923,13 +898,6 @@ public function authenticate(Request $request): Passport
923898
{
924899
}
925900

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

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

-15
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

+5
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

src/Symfony/Component/Ldap/Security/LdapBadge.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,10 @@ class LdapBadge implements BadgeInterface
3434
public function __construct(string $ldapServiceId, string $dnString = '{user_identifier}', string $searchDn = '', string $searchPassword = '', string $queryString = null)
3535
{
3636
$this->ldapServiceId = $ldapServiceId;
37-
$dnString = str_replace('{username}', '{user_identifier}', $dnString, $replaceCount);
38-
if ($replaceCount > 0) {
39-
trigger_deprecation('symfony/ldap', '6.2', 'Using "{username}" parameter in LDAP configuration is deprecated, consider using "{user_identifier}" instead.');
40-
}
4137
$this->dnString = $dnString;
4238
$this->searchDn = $searchDn;
4339
$this->searchPassword = $searchPassword;
44-
$queryString = str_replace('{username}', '{user_identifier}', $queryString ?? '', $replaceCount);
45-
if ($replaceCount > 0) {
46-
trigger_deprecation('symfony/ldap', '6.2', 'Using "{username}" parameter in LDAP configuration is deprecated, consider using "{user_identifier}" instead.');
47-
}
48-
$this->queryString = $queryString;
40+
$this->queryString = $queryString ?? '';
4941
}
5042

5143
public function getLdapServiceId(): string

0 commit comments

Comments
 (0)
0