Skip to content

Commit 76143f0

Browse files
committed
[Security] Deprecate the intention option in authentication listeners in favour of csrf_token_id
1 parent 5f12bee commit 76143f0

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ CHANGELOG
1818
`Symfony\Component\Security\Core\Authorization\Voter\VoterInterface`.
1919
* deprecated `getSupportedAttributes()` and `getSupportedClasses()` methods of
2020
`Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter`, use `supports()` instead.
21+
* deprecated the `intention` option for all the authentication listeners,
22+
use the `csrf_token_id` option instead.
2123

2224
2.7.0
2325
-----

src/Symfony/Component/Security/Http/Firewall/LogoutListener.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $http
5757
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
5858
}
5959

60+
if (isset($options['intention'])) {
61+
@trigger_error('The "intention" option for the '.__CLASS__.' is deprecated since version 2.8 and will be removed in 3.0. Use the "csrf_token_id" option instead.', E_USER_DEPRECATED);
62+
63+
$options['csrf_token_id'] = $options['intention'];
64+
}
65+
6066
$this->tokenStorage = $tokenStorage;
6167
$this->httpUtils = $httpUtils;
6268
$this->options = array_merge(array(
6369
'csrf_parameter' => '_csrf_token',
64-
'intention' => 'logout',
70+
'csrf_token_id' => 'logout',
6571
'logout_path' => '/logout',
6672
), $options);
6773
$this->successHandler = $successHandler;
@@ -101,7 +107,7 @@ public function handle(GetResponseEvent $event)
101107
if (null !== $this->csrfTokenManager) {
102108
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
103109

104-
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
110+
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
105111
throw new LogoutException('Invalid CSRF token.');
106112
}
107113
}

src/Symfony/Component/Security/Http/Firewall/SimpleFormAuthenticationListener.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,20 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
7070
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
7171
}
7272

73+
if (isset($options['intention'])) {
74+
@trigger_error('The "intention" option for the '.__CLASS__.' is deprecated since version 2.8 and will be removed in 3.0. Use the "csrf_token_id" option instead.', E_USER_DEPRECATED);
75+
76+
$options['csrf_token_id'] = $options['intention'];
77+
}
78+
7379
$this->simpleAuthenticator = $simpleAuthenticator;
7480
$this->csrfTokenManager = $csrfTokenManager;
7581

7682
$options = array_merge(array(
7783
'username_parameter' => '_username',
7884
'password_parameter' => '_password',
7985
'csrf_parameter' => '_csrf_token',
80-
'intention' => 'authenticate',
86+
'csrf_token_id' => 'authenticate',
8187
'post_only' => true,
8288
), $options);
8389

@@ -104,7 +110,7 @@ protected function attemptAuthentication(Request $request)
104110
if (null !== $this->csrfTokenManager) {
105111
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
106112

107-
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
113+
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
108114
throw new InvalidCsrfTokenException('Invalid CSRF token.');
109115
}
110116
}

src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
4848
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
4949
}
5050

51+
if (isset($options['intention'])) {
52+
@trigger_error('The "intention" option for the '.__CLASS__.' is deprecated since version 2.8 and will be removed in 3.0. Use the "csrf_token_id" option instead.', E_USER_DEPRECATED);
53+
54+
$options['csrf_token_id'] = $options['intention'];
55+
}
56+
5157
parent::__construct($tokenStorage, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, array_merge(array(
5258
'username_parameter' => '_username',
5359
'password_parameter' => '_password',
5460
'csrf_parameter' => '_csrf_token',
55-
'intention' => 'authenticate',
61+
'csrf_token_id' => 'authenticate',
5662
'post_only' => true,
5763
), $options), $logger, $dispatcher);
5864

@@ -79,7 +85,7 @@ protected function attemptAuthentication(Request $request)
7985
if (null !== $this->csrfTokenManager) {
8086
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
8187

82-
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
88+
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
8389
throw new InvalidCsrfTokenException('Invalid CSRF token.');
8490
}
8591
}

src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private function getListener($successHandler = null, $tokenManager = null)
213213
$successHandler ?: $this->getSuccessHandler(),
214214
$options = array(
215215
'csrf_parameter' => '_csrf_token',
216-
'intention' => 'logout',
216+
'csrf_token_id' => 'logout',
217217
'logout_path' => '/logout',
218218
'target_url' => '/',
219219
),

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