Skip to content

Commit 0a0a98a

Browse files
MatTheCatfabpot
authored andcommitted
[SecurityBundle] Rename firewalls.logout.csrf_token_generator to firewalls.logout.csrf_token_manager
1 parent 24fdf38 commit 0a0a98a

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
lines changed

UPGRADE-6.3.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ SecurityBundle
6060
Validator
6161
--------------
6262

63-
* Implementing the `ConstraintViolationInterface` without implementing the `getConstraint()` method is deprecated
63+
* Implementing the `ConstraintViolationInterface` without implementing the `getConstraint()` method is deprecated
64+
* Deprecate the `security.firewalls.logout.csrf_token_generator` config option, use `security.firewalls.logout.csrf_token_manager` instead

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* Add `StatelessAuthenticatorFactoryInterface` for authenticators targeting `stateless` firewalls only and that don't require a user provider
1010
* Modify "icon.svg" to improve accessibility for blind/low vision users
1111
* Make `Security::login()` return the authenticator response
12+
* Deprecate the `security.firewalls.logout.csrf_token_generator` config option, use `security.firewalls.logout.csrf_token_manager` instead
1213

1314
6.2
1415
---

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,20 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
217217
->treatTrueLike([])
218218
->canBeUnset()
219219
->beforeNormalization()
220-
->ifTrue(fn ($v): bool => \is_array($v) && (isset($v['csrf_token_generator']) xor isset($v['enable_csrf'])))
220+
->ifTrue(fn ($v): bool => isset($v['csrf_token_generator']) && !isset($v['csrf_token_manager']))
221221
->then(function (array $v): array {
222-
if (isset($v['csrf_token_generator'])) {
222+
$v['csrf_token_manager'] = $v['csrf_token_generator'];
223+
224+
return $v;
225+
})
226+
->end()
227+
->beforeNormalization()
228+
->ifTrue(fn ($v): bool => \is_array($v) && (isset($v['csrf_token_manager']) xor isset($v['enable_csrf'])))
229+
->then(function (array $v): array {
230+
if (isset($v['csrf_token_manager'])) {
223231
$v['enable_csrf'] = true;
224232
} elseif ($v['enable_csrf']) {
225-
$v['csrf_token_generator'] = 'security.csrf.token_manager';
233+
$v['csrf_token_manager'] = 'security.csrf.token_manager';
226234
}
227235

228236
return $v;
@@ -232,7 +240,14 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
232240
->booleanNode('enable_csrf')->defaultNull()->end()
233241
->scalarNode('csrf_token_id')->defaultValue('logout')->end()
234242
->scalarNode('csrf_parameter')->defaultValue('_csrf_token')->end()
235-
->scalarNode('csrf_token_generator')->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()
250+
->scalarNode('csrf_token_manager')->end()
236251
->scalarNode('path')->defaultValue('/logout')->end()
237252
->scalarNode('target')->defaultValue('/')->end()
238253
->booleanNode('invalidate_session')->defaultTrue()->end()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
458458

459459
// add CSRF provider
460460
if ($firewall['logout']['enable_csrf']) {
461-
$logoutListener->addArgument(new Reference($firewall['logout']['csrf_token_generator']));
461+
$logoutListener->addArgument(new Reference($firewall['logout']['csrf_token_manager']));
462462
}
463463

464464
// add session logout listener
@@ -482,7 +482,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
482482
$firewall['logout']['path'],
483483
$firewall['logout']['csrf_token_id'],
484484
$firewall['logout']['csrf_parameter'],
485-
isset($firewall['logout']['csrf_token_generator']) ? new Reference($firewall['logout']['csrf_token_generator']) : null,
485+
isset($firewall['logout']['csrf_token_manager']) ? new Reference($firewall['logout']['csrf_token_manager']) : null,
486486
false === $firewall['stateless'] && isset($firewall['context']) ? $firewall['context'] : null,
487487
])
488488
;

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testCsrfAliases()
7171
'firewalls' => [
7272
'stub' => [
7373
'logout' => [
74-
'csrf_token_generator' => 'a_token_generator',
74+
'csrf_token_manager' => 'a_token_manager',
7575
'csrf_token_id' => 'a_token_id',
7676
],
7777
],
@@ -82,8 +82,8 @@ public function testCsrfAliases()
8282
$processor = new Processor();
8383
$configuration = new MainConfiguration([], []);
8484
$processedConfig = $processor->processConfiguration($configuration, [$config]);
85-
$this->assertArrayHasKey('csrf_token_generator', $processedConfig['firewalls']['stub']['logout']);
86-
$this->assertEquals('a_token_generator', $processedConfig['firewalls']['stub']['logout']['csrf_token_generator']);
85+
$this->assertArrayHasKey('csrf_token_manager', $processedConfig['firewalls']['stub']['logout']);
86+
$this->assertEquals('a_token_manager', $processedConfig['firewalls']['stub']['logout']['csrf_token_manager']);
8787
$this->assertArrayHasKey('csrf_token_id', $processedConfig['firewalls']['stub']['logout']);
8888
$this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
8989
}
@@ -92,13 +92,13 @@ public function testLogoutCsrf()
9292
{
9393
$config = [
9494
'firewalls' => [
95-
'custom_token_generator' => [
95+
'custom_token_manager' => [
9696
'logout' => [
97-
'csrf_token_generator' => 'a_token_generator',
97+
'csrf_token_manager' => 'a_token_manager',
9898
'csrf_token_id' => 'a_token_id',
9999
],
100100
],
101-
'default_token_generator' => [
101+
'default_token_manager' => [
102102
'logout' => [
103103
'enable_csrf' => true,
104104
'csrf_token_id' => 'a_token_id',
@@ -121,18 +121,18 @@ public function testLogoutCsrf()
121121
$processedConfig = $processor->processConfiguration($configuration, [$config]);
122122

123123
$assertions = [
124-
'custom_token_generator' => [true, 'a_token_generator'],
125-
'default_token_generator' => [true, 'security.csrf.token_manager'],
124+
'custom_token_manager' => [true, 'a_token_manager'],
125+
'default_token_manager' => [true, 'security.csrf.token_manager'],
126126
'disabled_csrf' => [false, null],
127127
'empty' => [false, null],
128128
];
129-
foreach ($assertions as $firewallName => [$enabled, $tokenGenerator]) {
129+
foreach ($assertions as $firewallName => [$enabled, $tokenManager]) {
130130
$this->assertEquals($enabled, $processedConfig['firewalls'][$firewallName]['logout']['enable_csrf']);
131-
if ($tokenGenerator) {
132-
$this->assertEquals($tokenGenerator, $processedConfig['firewalls'][$firewallName]['logout']['csrf_token_generator']);
131+
if ($tokenManager) {
132+
$this->assertEquals($tokenManager, $processedConfig['firewalls'][$firewallName]['logout']['csrf_token_manager']);
133133
$this->assertEquals('a_token_id', $processedConfig['firewalls'][$firewallName]['logout']['csrf_token_id']);
134134
} else {
135-
$this->assertArrayNotHasKey('csrf_token_generator', $processedConfig['firewalls'][$firewallName]['logout']);
135+
$this->assertArrayNotHasKey('csrf_token_manager', $processedConfig['firewalls'][$firewallName]['logout']);
136136
}
137137
}
138138
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/base_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ security:
4343
logout:
4444
path: /logout_path
4545
target: /
46-
csrf_token_generator: security.csrf.token_manager
46+
csrf_token_manager: security.csrf.token_manager
4747

4848
access_control:
4949
- { path: .*, roles: IS_AUTHENTICATED_FULLY }

0 commit comments

Comments
 (0)