Skip to content

Commit 58e0b57

Browse files
[Security] Remove deprecated code paths
1 parent 9e248b8 commit 58e0b57

File tree

23 files changed

+75
-394
lines changed

23 files changed

+75
-394
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/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

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.3
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
->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 & 15 deletions
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

Lines changed: 3 additions & 18 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;
@@ -91,7 +90,7 @@ public function prepend(ContainerBuilder $container): void
9190
public function load(array $configs, ContainerBuilder $container): void
9291
{
9392
if (!array_filter($configs)) {
94-
throw new InvalidArgumentException(sprintf('Enabling bundle "%s" and not configuring it is not allowed.', SecurityBundle::class));
93+
throw new InvalidConfigurationException(sprintf('Enabling bundle "%s" and not configuring it is not allowed.', SecurityBundle::class));
9594
}
9695

9796
$mainConfig = $this->getConfiguration($configs, $container);
@@ -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
/**
@@ -669,15 +658,11 @@ private function getUserProvider(ContainerBuilder $container, string $id, array
669658
return $this->createMissingUserProvider($container, $id, $factoryKey);
670659
}
671660

672-
if ('remember_me' === $factoryKey || 'anonymous' === $factoryKey || 'custom_authenticators' === $factoryKey) {
673-
if ('custom_authenticators' === $factoryKey) {
674-
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);
675-
}
676-
661+
if ('remember_me' === $factoryKey || 'anonymous' === $factoryKey) {
677662
return 'security.user_providers';
678663
}
679664

680-
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));
665+
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));
681666
}
682667

683668
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: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
1818
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
19+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
20+
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1921
use Symfony\Component\Security\Core\Exception\LogicException;
2022
use Symfony\Component\Security\Core\Exception\LogoutException;
21-
use Symfony\Component\Security\Core\Security as LegacySecurity;
2223
use Symfony\Component\Security\Core\User\UserInterface;
2324
use Symfony\Component\Security\Csrf\CsrfToken;
2425
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
@@ -36,15 +37,39 @@
3637
*
3738
* @final
3839
*/
39-
class Security extends LegacySecurity
40+
class Security implements AuthorizationCheckerInterface
4041
{
4142
public const ACCESS_DENIED_ERROR = SecurityRequestAttributes::ACCESS_DENIED_ERROR;
4243
public const AUTHENTICATION_ERROR = SecurityRequestAttributes::AUTHENTICATION_ERROR;
4344
public const LAST_USERNAME = SecurityRequestAttributes::LAST_USERNAME;
4445

45-
public function __construct(private readonly ContainerInterface $container, private readonly array $authenticators = [])
46+
public function __construct(
47+
private readonly ContainerInterface $container,
48+
private readonly array $authenticators = [],
49+
) {
50+
}
51+
52+
public function getUser(): ?UserInterface
53+
{
54+
if (!$token = $this->getToken()) {
55+
return null;
56+
}
57+
58+
return $token->getUser();
59+
}
60+
61+
/**
62+
* Checks if the attributes are granted against the current authentication token and optionally supplied subject.
63+
*/
64+
public function isGranted(mixed $attributes, mixed $subject = null): bool
65+
{
66+
return $this->container->get('security.authorization_checker')
67+
->isGranted($attributes, $subject);
68+
}
69+
70+
public function getToken(): ?TokenInterface
4671
{
47-
parent::__construct($container, false);
72+
return $this->container->get('security.token_storage')->getToken();
4873
}
4974

5075
public function getFirewallConfig(Request $request): ?FirewallConfig

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

Lines changed: 4 additions & 29 deletions
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();

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy