8000 feature #16692 [Form] Drop remaing CsrfProviderAdapter/Interface ment… · symfony/symfony@26c17f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26c17f6

Browse files
committed
feature #16692 [Form] Drop remaing CsrfProviderAdapter/Interface mentions (nicolas-grekas)
This PR was merged into the 3.0-dev branch. Discussion ---------- [Form] Drop remaing CsrfProviderAdapter/Interface mentions | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - CsrfProviderAdapter+Interface have already been removed from master, we should not use them anymore. Let's see if tests agree. Commits ------- 5bc34d2 [Form] Drop remaing CsrfProviderAdapter/Interface mentions
2 parents 2a22d86 + 5bc34d2 commit 26c17f6

File tree

16 files changed

+28
-189
lines changed

16 files changed

+28
-189
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
6377 $listeners[] = new Reference($listenerId);

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

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

94-
/**
95-
* @group legacy
96-
*/
97-
public function testLegacyCsrfAliases()
98-
{
99-
$config = array(
100-
'firewalls' => array(
101-
'stub' => array(
102-
'logout' => array(
103-
'csrf_provider' => 'a_token_generator',
104-
'intention' => 'a_token_id',
105-
),
106-
),
107-
),
108-
);
109-
$config = array_merge(static::$minimalConfig, $config);
110-
111-
$processor = new Processor();
112-
$configuration = new MainConfiguration(array(), array());
113-
$processedConfig = $processor->processConfiguration($configuration, array($config));
114-
$this->assertTrue(isset($processedConfig['firewalls']['stub']['logout']['csrf_token_generator']));
115-
$this->assertEquals('a_token_generator', $processedConfig['firewalls']['stub']['logout']['csrf_token_generator']);
116-
$this->assertTrue(isset($processedConfig['firewalls']['stub']['logout']['csrf_token_id']));
117-
$this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
118-
}
119-
120-
/**
121-
* @expectedException \InvalidArgumentException
122-
*/
123-
public function testCsrfOriginalAndAliasValueCausesException()
124-
{
125-
$config = array(
126-
'firewalls' => array(
127-
'stub' => array(
128-
'logout' => array(
129-
'csrf_token_id' => 'a_token_id',
130-
'intention' => 'old_name',
131-
),
132-
),
133-
),
134-
);
135-
$config = array_merge(static::$minimalConfig, $config);
136-
137-
$processor = new Processor();
138-
$configuration = new MainConfiguration(array(), array());
139-
$processor->processConfiguration($configuration, array($config));
140-
}
141-
14294
public function testDefaultUserCheckers()
14395
{
14496
$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: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
namespace Symfony\Component\Form\Extension\Csrf\Type;
1313

1414
use Symfony\Component\Form\AbstractTypeExtension;
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;
18-
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfTokenManagerAdapter;
1915
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
2016
use Symfony\Component\Form\FormBuilderInterface;
2117
use Symfony\Component\Form\FormView;
@@ -55,14 +51,8 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
5551
*/
5652
private $translationDomain;
5753

58-
public function __construct($defaultTokenManager, $defaultEnabled = true, $defaultFieldName = '_token', TranslatorInterface $translator = null, $translationDomain = null)
54+
public function __construct(CsrfTokenManagerInterface $defaultTokenManager, $defaultEnabled = true, $defaultFieldName = '_token', TranslatorInterface $translator = null, $translationDomain = null)
5955
{
60-
if ($defaultTokenManager instanceof CsrfProviderInterface) {
61-
$defaultTokenManager = new CsrfProviderAdapter($defaultTokenManager);
62-
} elseif (!$defaultTokenManager instanceof CsrfTokenManagerInterface) {
63-
throw new UnexpectedTypeException($defaultTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
64-
}
65-
6656
$this->defaultTokenManager = $defaultTokenManager;
6757
$this->defaultEnabled = $defaultEnabled;
6858
$this->defaultFieldName = $defaultFieldName;
@@ -130,39 +120,14 @@ public function configureOptions(OptionsResolver $resolver)
130120
return $options['intention'];
131121
};
132122

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-
155123
$resolver->setDefaults(array(
156124
'csrf_protection' => $this->defaultEnabled,
157125
'csrf_field_name' => $this->defaultFieldName,
158126
'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.',
159-
'csrf_token_manager' => $csrfTokenManager,
127+
'csrf_token_manager' => $this->defaultTokenManager,
160128
'csrf_token_id' => $csrfTokenId,
161-
'csrf_provider' => null, // deprecated
162129
'intention' => null, // deprecated
163130
));
164-
165-
$resolver->setNormalizer('csrf_provider', $csrfProviderNormalizer);
166131
}
167132

168133
/**

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
}

0 commit comments

Comments
 (0)
0