Skip to content

Commit def2802

Browse files
authored
Merge pull request #2492 from ossinkine/issue-2492
Inject firewall's UserChecker into LoginManager
2 parents 6344e77 + 148680e commit def2802

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\UserBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
/**
19+
* Injects firewall's UserChecker into LoginManager.
20+
*
21+
* @author Gocha Ossinkine <ossinkine@ya.ru>
22+
*/
23+
class InjectUserCheckerPass implements CompilerPassInterface
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function process(ContainerBuilder $container)
29+
{
30+
$firewallName = $container->getParameter('fos_user.firewall_name');
31+
$loginManager = $container->getDefinition('fos_user.security.login_manager');
32+
33+
if ($container->hasAlias('security.user_checker.'.$firewallName)) {
34+
$loginManager->replaceArgument(1, new Reference('security.user_checker.'.$firewallName));
35+
}
36+
}
37+
}

FOSUserBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
1616
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
1717
use FOS\UserBundle\DependencyInjection\Compiler\InjectRememberMeServicesPass;
18+
use FOS\UserBundle\DependencyInjection\Compiler\InjectUserCheckerPass;
1819
use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass;
1920
use Symfony\Component\DependencyInjection\ContainerBuilder;
2021
use Symfony\Component\HttpKernel\Bundle\Bundle;
@@ -32,6 +33,7 @@ public function build(ContainerBuilder $container)
3233
{
3334
parent::build($container);
3435
$container->addCompilerPass(new ValidationPass());
36+
$container->addCompilerPass(new InjectUserCheckerPass());
3537
$container->addCompilerPass(new InjectRememberMeServicesPass());
3638

3739
$this->addRegisterMappingsPass($container);

0 commit comments

Comments
 (0)