Skip to content

Commit b00e142

Browse files
[Form] Drop remaing CsrfProviderAdapter/Interface mentions
1 parent 2809b2b commit b00e142

File tree

5 files changed

+11
-47
lines changed

5 files changed

+11
-47
lines changed

Firewall/LogoutListener.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111

1212
namespace Symfony\Component\Security\Http\Firewall;
1313

14-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1614
use Symfony\Component\HttpFoundation\Request;
1715
use Symfony\Component\HttpFoundation\Response;
1816
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1917
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
20-
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
2118
use Symfony\Component\Security\Core\Exception\LogoutException;
2219
use Symfony\Component\Security\Csrf\CsrfToken;
2320
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
@@ -49,19 +46,13 @@ class LogoutListener implements ListenerInterface
4946
* @param array $options An array of options to process a logout attempt
5047
* @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
5148
*/
52-
public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $httpUtils, LogoutSuccessHandlerInterface $successHandler, array $options = array(), $csrfTokenManager = null)
49+
public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $httpUtils, LogoutSuccessHandlerInterface $successHandler, array $options = array(), CsrfTokenManagerInterface $csrfTokenManager = null)
5350
{
54-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
55-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
56-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
57-
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
58-
}
59-
6051
$this->tokenStorage = $tokenStorage;
6152
$this->httpUtils = $httpUtils;
6253
$this->options = array_merge(array(
6354
'csrf_parameter' => '_csrf_token',
64-
'intention' => 'logout',
55+
'csrf_token_id' => 'logout',
6556
'logout_path' => '/logout',
6657
), $options);
6758
$this->successHandler = $successHandler;
@@ -101,7 +92,7 @@ public function handle(GetResponseEvent $event)
10192
if (null !== $this->csrfTokenManager) {
10293
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
10394

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

Firewall/SimpleFormAuthenticationListener.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Firewall;
1313

1414
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1715
use Symfony\Component\HttpFoundation\Request;
18-
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
1916
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
2017
use Symfony\Component\Security\Csrf\CsrfToken;
2118
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
@@ -56,28 +53,21 @@ class SimpleFormAuthenticationListener extends AbstractAuthenticationListener
5653
* @param SimpleFormAuthenticatorInterface $simpleAuthenticator A SimpleFormAuthenticatorInterface instance
5754
*
5855
* @throws \InvalidArgumentException In case no simple authenticator is provided
59-
* @throws InvalidArgumentException In case an invalid CSRF token manager is passed
6056
*/
61-
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null, SimpleFormAuthenticatorInterface $simpleAuthenticator = null)
57+
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, CsrfTokenManagerInterface $csrfTokenManager = null, SimpleFormAuthenticatorInterface $simpleAuthenticator = null)
6258
{
6359
if (!$simpleAuthenticator) {
6460
throw new \InvalidArgumentException('Missing simple authenticator');
6561
}
6662

67-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
68-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
69-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
70-
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
71-
}
72-
7363
$this->simpleAuthenticator = $simpleAuthenticator;
7464
$this->csrfTokenManager = $csrfTokenManager;
7565

7666
$options = array_merge(array(
7767
'username_parameter' => '_username',
7868
'password_parameter' => '_password',
7969
'csrf_parameter' => '_csrf_token',
80-
'intention' => 'authenticate',
70+
'csrf_token_id' => 'authenticate',
8171
'post_only' => true,
8272
), $options);
8373

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

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

Firewall/UsernamePasswordFormAuthenticationListener.php

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

1212
namespace Symfony\Component\Security\Http\Firewall;
1313

14-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1614
use Symfony\Component\HttpFoundation\Request;
1715
use Psr\Log\LoggerInterface;
1816
use Symfony\Component\Security\Csrf\CsrfToken;
@@ -25,7 +23,6 @@
2523
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
2624
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2725
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
28-
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
2926
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
3027
use Symfony\Component\Security\Core\Security;
3128
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -40,19 +37,13 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL
4037
{
4138
private $csrfTokenManager;
4239

43-
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null)
40+
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, CsrfTokenManagerInterface $csrfTokenManager = null)
4441
{
45-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
46-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
47-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
48-
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
49-
}
50-
5142
parent::__construct($tokenStorage, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, array_merge(array(
5243
'username_parameter' => '_username',
5344
'password_parameter' => '_password',
5445
'csrf_parameter' => '_csrf_token',
55-
'intention' => 'authenticate',
46+
'csrf_token_id' => 'authenticate',
5647
'post_only' => true,
5748
), $options), $logger, $dispatcher);
5849

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

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

Logout/LogoutUrlGenerator.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Security\Http\Logout;
1313

14-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1614
use Symfony\Component\HttpFoundation\RequestStack;
1715
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1816
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -47,14 +45,8 @@ public function __construct(RequestStack $requestStack = null, UrlGeneratorInter
4745
* @param string $csrfParameter The CSRF token parameter name
4846
* @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
4947
*/
50-
public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager = null)
48+
public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter, CsrfTokenManagerInterface $csrfTokenManager = null)
5149
{
52-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
53-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
54-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
55-
throw new \InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
56-
}
57-
5850
$this->listeners[$key] = array($logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager);
5951
}
6052

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)