Skip to content

Commit 1375f50

Browse files
committed
Register SecurityRoleHierarchyDumpCommand in the service container
1 parent 59ea467 commit 1375f50

File tree

7 files changed

+47
-99
lines changed

7 files changed

+47
-99
lines changed

src/Symfony/Bundle/SecurityBundle/Command/SecurityRoleHierarchyDumpCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7171
$direction = $input->getOption('direction');
7272

7373
if (!MermaidDirectionEnum::tryFrom($direction)) {
74-
$io->getErrorStyle()->writeln(\sprintf('<error>Invalid direction, available options are "%s"</error>', implode('"', $this->getAvailableDirections())));
74+
$io->getErrorStyle()->writeln(\sprintf('<error>Invalid direction, available options are "%s"</error>', implode('"', $this->getAvailableDirections())));
7575

7676
return Command::FAILURE;
7777
}

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ public function load(array $configs, ContainerBuilder $container): void
186186
$container->getDefinition('security.command.user_password_hash')->replaceArgument(1, array_keys($config['password_hashers']));
187187
}
188188

189+
if ($container->hasDefinition('security.role_hierarchy')) {
190+
$loader->load('security_role_hierarchy_dump_command.php');
191+
}
192+
189193
$container->registerForAutoconfiguration(VoterInterface::class)
190194
->addTag('security.voter');
191195
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Bundle\SecurityBundle\Command\SecurityRoleHierarchyDumpCommand;
15+
16+
return static function (ContainerConfigurator $container): void {
17+
$container->services()
18+
->set('security.command.role_hierarchy_dump', SecurityRoleHierarchyDumpCommand::class)
19+
->args([
20+
service('security.role_hierarchy'),
21+
])
22+
->tag('console.command')
23+
;
24+
};

src/Symfony/Bundle/SecurityBundle/SecurityBundle.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterEntryPointPass;
2121
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterGlobalSecurityEventListenersPass;
2222
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterLdapLocatorPass;
23-
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterSecurityRoleHierarchyDumpCommandPass;
2423
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\RegisterTokenUsageTrackingPass;
2524
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\ReplaceDecoratedRememberMeHandlerPass;
2625
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\SortFirewallListenersPass;
@@ -108,7 +107,5 @@ public function build(ContainerBuilder $container): void
108107

109108
// must be registered before DecoratorServicePass
110109
$container->addCompilerPass(new MakeFirewallsEventDispatcherTraceablePass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10);
111-
112-
$container->addCompilerPass(new RegisterSecurityRoleHierarchyDumpCommandPass());
113110
}
114111
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/RegisterSecurityRoleHierarchyDumpCommandPassTest.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ public function testSwitchUserNotStatelessOnStatelessFirewall()
141141
$this->assertTrue($container->getDefinition('security.authentication.switchuser_listener.some_firewall')->getArgument(9));
142142
}
143143

144+
public function testRoleHierarchyDumpCommandIsRegisteredWithRoleHierarchy()
145+
{
146+
$container = $this->getRawContainer();
147+
$container->loadFromExtension('security', [
148+
'role_hierarchy' => [
149+
'ROLE_ADMIN' => ['ROLE_USER'],
150+
'ROLE_SUPER_ADMIN' => ['ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'],
151+
],
152+
'firewalls' => [
153+
'some_firewall' => [
154+
],
155+
],
156+
]);
157+
$container->compile();
158+
159+
$this->assertTrue($container->hasDefinition('security.command.role_hierarchy_dump'));
160+
}
161+
144162
public function testPerListenerProvider()
145163
{
146164
$container = $this->getRawContainer();

0 commit comments

Comments
 (0)