Skip to content

Commit abf92f9

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

File tree

16 files changed

+28
-163
lines changed

16 files changed

+28
-163
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: 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
));

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