Skip to content

Commit 080eef0

Browse files
committed
bug symfony#37261 Fix register csrf protection listener (Ne-Lexa)
This PR was squashed before being merged into the 5.1 branch. Discussion ---------- Fix register csrf protection listener | Q | A | ------------- | --- | Branch? | 5.1.1 | Bug fix? | yes | New feature? | no | Deprecations? | np | Tickets | symfony#37254 | License | MIT Fix TypeError. Expected instance `CsrfTokenManagerInterface`, but `SessionTokenStorage` was given. ``` Uncaught Error: Argument 1 passed to Symfony\Component\Security\Http\EventListener\CsrfProtectionListener::__construct() must implement interface Symfony\Component\Security\Csrf\CsrfTokenManagerInterface, instance of Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage given Uncaught PHP Exception TypeError: "Argument 1 passed to Symfony\Component\Security\Http\EventListener\CsrfProtectionListener::__construct() must implement interface Symfony\Component\Security\Csrf\CsrfTokenManagerInterface, instance of Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage given ``` Commits ------- 485361e Fix register csrf protection listener
2 parents 86c79ce + 485361e commit 080eef0

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterCsrfFeaturesPass.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,25 @@ class RegisterCsrfFeaturesPass implements CompilerPassInterface
2727
{
2828
public function process(ContainerBuilder $container)
2929
{
30-
if (!$container->has('security.csrf.token_storage')) {
31-
return;
32-
}
33-
3430
$this->registerCsrfProtectionListener($container);
3531
$this->registerLogoutHandler($container);
3632
}
3733

3834
private function registerCsrfProtectionListener(ContainerBuilder $container)
3935
{
40-
if (!$container->has('security.authenticator.manager')) {
36+
if (!$container->has('security.authenticator.manager') || !$container->has('security.csrf.token_manager')) {
4137
return;
4238
}
4339

4440
$container->register('security.listener.csrf_protection', CsrfProtectionListener::class)
45-
->addArgument(new Reference('security.csrf.token_storage'))
41+
->addArgument(new Reference('security.csrf.token_manager'))
4642
->addTag('kernel.event_subscriber')
4743
->setPublic(false);
4844
}
4945

5046
protected function registerLogoutHandler(ContainerBuilder $container)
5147
{
52-
if (!$container->has('security.logout_listener')) {
48+
if (!$container->has('security.logout_listener') || !$container->has('security.csrf.token_storage')) {
5349
return;
5450
}
5551

0 commit comments

Comments
 (0)