Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13d7a06

Browse files
[Form] Drop remaing CsrfProviderAdapter/Interface mentions
1 parent 743e670 commit 13d7a06

File tree

16 files changed

+27
-152
lines changed

16 files changed

+27
-152
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,11 @@ public function getTests()
9494
}
9595

9696
/**
97-
* Renders a CSRF token.
98-
*
99-
* @param string $intention The intention of the protected action.
100-
*
101-
* @return string A CSRF token.
97+
* {@inheritdoc}
10298
*/
103-
public function renderCsrfToken($intention)
99+
public function renderCsrfToken($tokenId)
104100
{
105-
return $this->renderer->renderCsrfToken($intention);
101+
return $this->renderer->renderCsrfToken($tokenId);
106102
}
107103

108104
/**

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function block(FormView $view, $blockName, array $variables = array())
223223
* echo $view['form']->csrfToken('rm_user_'.$user->getId());
224224
* </code>
225225
*
226-
* Check the token in your action using the same intention.
226+
* Check the token in your action using the same CSRF token id.
227227
*
228228
* <code>
229229
* $csrfProvider = $this->get('security.csrf.token_generator');
@@ -232,15 +232,15 @@ public function block(FormView $view, $blockName, array $variables = array())
232232
* }
233233
* </code>
234234
*
235-
* @param string $intention The intention of the protected action
235+
* @param string $tokenId The CSRF token id of the protected action
236236
*
237237
* @return string A CSRF token
238238
*
239239
* @throws \BadMethodCallException When no CSRF provider was injected in the constructor.
240240
*/
241-
public function csrfToken($intention)
241+
public function csrfToken($tokenId)
242242
{
243-
return $this->renderer->renderCsrfToken($intention);
243+
return $this->renderer->renderCsrfToken($tokenId);
244244
}
245245

246246
public function humanize($text)

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct()
2929
$this->addOption('username_parameter', '_username');
3030
$this->addOption('password_parameter', '_password');
3131
$this->addOption('csrf_parameter', '_csrf_token');
32-
$this->addOption('intention', 'authenticate');
32+
$this->addOption('csrf_token_id', 'authenticate');
3333
$this->addOption('post_only', true);
3434
}
3535

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
303303
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.logout_listener'));
304304
$listener->replaceArgument(3, array(
305305
'csrf_parameter' => $firewall['logout']['csrf_parameter'],
306-
'intention' => $firewall['logout']['csrf_token_id'],
306+
'csrf_token_id' => $firewall['logout']['csrf_token_id'],
307307
'logout_path' => $firewall['logout']['path'],
308308
));
309309
$listeners[] = new Reference($listenerId);

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,6 @@ public function testCsrfAliases()
9191
$this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
9292
}
9393

94-
/**
95-
* @expectedException \InvalidArgumentException
96-
*/
97-
public function testCsrfOriginalAndAliasValueCausesException()
98-
{
99-
$config = array(
100-
'firewalls' => array(
101-
'stub' => array(
102-
'logout' => array(
103-
'csrf_token_id' => 'a_token_id',
104-
'intention' => 'old_name',
105-
),
106-
),
107-
),
108-
);
109-
$config = array_merge(static::$minimalConfig, $config);
110-
111-
$processor = new Processor();
112-
$configuration = new MainConfiguration(array(), array());
113-
$processor->processConfiguration($configuration, array($config));
114-
}
115-
11694
public function testDefaultUserCheckers()
11795
{
11896
$processor = new Processor();

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7676
*/
7777
public function configureOptions(OptionsResolver $resolver)
7878
{
79-
/* Note: the form's intention must correspond to that for the form login
79+
/* Note: the form's csrf_token_id must correspond to that for the form login
8080
* listener in order for the CSRF token to validate successfully.
8181
*/
8282

8383
$resolver->setDefaults(array(
84-
'intention' => 'authenticate',
84+
'csrf_token_id' => 'authenticate',
8585
));
8686
}
8787
}

src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php

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

1212
namespace Symfony\Component\Form\Extension\Csrf;
1313

14-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
15-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1714
use Symfony\Component\Form\AbstractExtension;
1815
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
1916
use Symfony\Component\Translation\TranslatorInterface;
@@ -47,14 +44,8 @@ class CsrfExtension extends AbstractExtension
4744
* @param TranslatorInterface $translator The translator for translating error messages
4845
* @param null|string $translationDomain The translation domain for translating
4946
*/
50-
public function __construct($tokenManager, TranslatorInterface $translator = null, $translationDomain = null)
47+
public function __construct(CsrfTokenManagerInterface $tokenManager, TranslatorInterface $translator = null, $translationDomain = null)
5148
{
52-
if ($tokenManager instanceof CsrfProviderInterface) {
53-
$tokenManager = new CsrfProviderAdapter($tokenManager);
54-
} elseif (!$tokenManager instanceof CsrfTokenManagerInterface) {
55-
throw new UnexpectedTypeException($tokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
56-
}
57-
5849
$this->tokenManager = $tokenManager;
5950
$this->translator = $translator;
6051
$this->translationDomain = $translationDomain;

src/Symfony/Component/Form/Extension/Csrf/EventListener/CsrfValidationListener.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
namespace Symfony\Component\Form\Extension\Csrf\EventListener;
1313

1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
17-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1815
use Symfony\Component\Form\FormEvents;
1916
use Symfony\Component\Form\FormError;
2017
use Symfony\Component\Form\FormEvent;
@@ -75,14 +72,8 @@ public static function getSubscribedEvents()
7572
);
7673
}
7774

78-
public function __construct($fieldName, $tokenManager, $tokenId, $errorMessage, TranslatorInterface $translator = null, $translationDomain = null)
75+
public function __construct($fieldName, CsrfTokenManagerInterface $tokenManager, $tokenId, $errorMessage, TranslatorInterface $translator = null, $translationDomain = null)
7976
{
80-
if ($tokenManager instanceof CsrfProviderInterface) {
81-
$tokenManager = new CsrfProviderAdapter($tokenManager);
82-
} elseif (!$tokenManager instanceof CsrfTokenManagerInterface) {
83-
throw new UnexpectedTypeException($tokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
84-
}
85-
8677
$this->fieldName = $fieldName;
8778
$this->tokenManager = $tokenManager;
8879
$this->tokenId = $tokenId;

src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,39 +130,14 @@ public function configureOptions(OptionsResolver $resolver)
130130
return $options['intention'];
131131
};
132132

133-
// BC clause for the "csrf_provider" option
134-
$csrfTokenManager = function (Options $options) {
135-
if ($options['csrf_provider'] instanceof CsrfTokenManagerInterface) {
136-
return $options['csrf_provider'];
137-
}
138-
139-
return $options['csrf_provider'] instanceof CsrfTokenManagerAdapter
140-
? $options['csrf_provider']->getTokenManager(false)
141-
: new CsrfProviderAdapter($options['csrf_provider']);
142-
};
143-
144-
$defaultTokenManager = $this->defaultTokenManager;
145-
$csrfProviderNormalizer = function (Options $options, $csrfProvider) use ($defaultTokenManager) {
146-
if (null !== $csrfProvider) {
147-
@trigger_error('The form option "csrf_provider" is deprecated since version 2.8 and will be removed in 3.0. Use "csrf_token_manager" instead.', E_USER_DEPRECATED);
148-
149-
return $csrfProvider;
150-
}
151-
152-
return $defaultTokenManager;
153-
};
154-
155133
$resolver->setDefaults(array(
156134
'csrf_protection' => $this->defaultEnabled,
157135
'csrf_field_name' => $this->defaultFieldName,
158136
'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.',
159-
'csrf_token_manager' => $csrfTokenManager,
137+
'csrf_token_manager' => $this->defaultTokenManager,
160138
'csrf_token_id' => $csrfTokenId,
161-
'csrf_provider' => null, // deprecated
162139
'intention' => null, // deprecated
163140
));
164-
165-
$resolver->setNormalizer('csrf_provider', $csrfProviderNormalizer);
166141
}
167142

168143
/**

src/Symfony/Component/Form/Extension/Templating/TemplatingExtension.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
namespace Symfony\Component\Form\Extension\Templating;
1313

1414
use Symfony\Component\Form\AbstractExtension;
15-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
16-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
17-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1815
use Symfony\Component\Form\FormRenderer;
1916
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2017
use Symfony\Component\Templating\PhpEngine;
@@ -27,14 +24,8 @@
2724
*/
2825
class TemplatingExtension extends AbstractExtension
2926
{
30-
public function __construct(PhpEngine $engine, $csrfTokenManager = null, array $defaultThemes = array())
27+
public function __construct(PhpEngine $engine, CsrfTokenManagerInterface $csrfTokenManager = null, array $defaultThemes = array())
3128
{
32-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
33-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
34-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
35-
throw new UnexpectedTypeException($csrfTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
36-
}
37-
3829
$engine->addHelpers(array(
3930
new FormHelper(new FormRenderer(new TemplatingRendererEngine($engine, $defaultThemes), $csrfTokenManager)),
4031
));

src/Symfony/Component/Form/FormRenderer.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313

1414
use Symfony\Component\Form\Exception\LogicException;
1515
use Symfony\Component\Form\Exception\BadMethodCallException;
16-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
17-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
18-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1916
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2017

2118
/**
@@ -57,17 +54,9 @@ class FormRenderer implements FormRendererInterface
5754
*
5855
* @param FormRendererEngineInterface $engine
5956
* @param CsrfTokenManagerInterface|null $csrfTokenManager
60-
*
61-
* @throws UnexpectedTypeException
6257
*/
63-
public function __construct(FormRendererEngineInterface $engine, $csrfTokenManager = null)
58+
public function __construct(FormRendererEngineInterface $engine, CsrfTokenManagerInterface $csrfTokenManager = null)
6459
{
65-
if ($csrfTokenManager instanceof CsrfProviderInterface) {
66-
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
67-
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
68-
throw new UnexpectedTypeException($csrfTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface or null');
69-
}
70-
7160
$this->engine = $engine;
7261
$this->csrfTokenManager = $csrfTokenManager;
7362
}

src/Symfony/Component/Security/Http/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
}

src/Symfony/Component/Security/Http/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
}

0 commit comments

Comments
 (0)