Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfdf2d0f

Browse files
committed
Add a ChainUserChecker to allow calling multiple user checkers for a firewall
1 parent68f5b3c commitfdf2d0f

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
useSymfony\Component\DependencyInjection\Alias;
2323
useSymfony\Component\DependencyInjection\Argument\IteratorArgument;
2424
useSymfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
25+
useSymfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
2526
useSymfony\Component\DependencyInjection\ChildDefinition;
2627
useSymfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
2728
useSymfony\Component\DependencyInjection\ContainerBuilder;
@@ -44,6 +45,7 @@
4445
useSymfony\Component\Security\Core\Authorization\Strategy\PriorityStrategy;
4546
useSymfony\Component\Security\Core\Authorization\Strategy\UnanimousStrategy;
4647
useSymfony\Component\Security\Core\Authorization\Voter\VoterInterface;
48+
useSymfony\Component\Security\Core\User\ChainUserChecker;
4749
useSymfony\Component\Security\Core\User\ChainUserProvider;
4850
useSymfony\Component\Security\Core\User\UserCheckerInterface;
4951
useSymfony\Component\Security\Core\User\UserProviderInterface;
@@ -363,6 +365,12 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
363365
$container->register($firewallEventDispatcherId, EventDispatcher::class)
364366
->addTag('event_dispatcher.dispatcher', ['name' =>$firewallEventDispatcherId]);
365367

368+
// Register Firewall-specific chained user checker
369+
if (class_exists(ChainUserChecker::class)) {
370+
$container->register('security.user_checker.chain.'.$id, ChainUserChecker::class)
371+
->addArgument(newTaggedIteratorArgument('security.user_checker.'.$id));
372+
}
373+
366374
// Register listeners
367375
$listeners = [];
368376
$listenerKeys = [];

‎src/Symfony/Component/Security/Core/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Add a`ChainUserChecker` to allow calling multiple user checkers for a firewall
8+
49
6.0
510
---
611

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
namespaceSymfony\Component\Security\Core\Tests\User;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Security\Core\User\ChainUserChecker;
16+
useSymfony\Component\Security\Core\User\UserCheckerInterface;
17+
useSymfony\Component\Security\Core\User\UserInterface;
18+
19+
finalclass ChainUserCheckerTestextends TestCase
20+
{
21+
publicfunctiontestForwardsPreAuthToAllUserCheckers()
22+
{
23+
$user =$this->createMock(UserInterface::class);
24+
25+
$checker1 =$this->createMock(UserCheckerInterface::class);
26+
$checker1->expects($this->once())
27+
->method('checkPreAuth')
28+
->with($user);
29+
30+
$checker2 =$this->createMock(UserCheckerInterface::class);
31+
$checker2->expects($this->once())
32+
->method('checkPreAuth')
33+
->with($user);
34+
35+
$checker3 =$this->createMock(UserCheckerInterface::class);
36+
$checker3->expects($this->once())
37+
->method('checkPreAuth')
38+
->with($user);
39+
40+
(newChainUserChecker([$checker1,$checker2,$checker3]))->checkPreAuth($user);
41+
}
42+
43+
publicfunctiontestForwardsPostAuthToAllUserCheckers()
44+
{
45+
$user =$this->createMock(UserInterface::class);
46+
47+
$checker1 =$this->createMock(UserCheckerInterface::class);
48+
$checker1->expects($this->once())
49+
->method('checkPostAuth')
50+
->with($user);
51+
52+
$checker2 =$this->createMock(UserCheckerInterface::class);
53+
$checker2->expects($this->once())
54+
->method('checkPostAuth')
55+
->with($user);
56+
57+
$checker3 =$this->createMock(UserCheckerInterface::class);
58+
$checker3->expects($this->once())
59+
->method('checkPostAuth')
60+
->with($user);
61+
62+
(newChainUserChecker([$checker1,$checker2,$checker3]))->checkPostAuth($user);
63+
}
64+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
namespaceSymfony\Component\Security\Core\User;
13+
14+
finalclass ChainUserCheckerimplements UserCheckerInterface
15+
{
16+
/**
17+
* @param iterable<UserCheckerInterface> $checkers
18+
*/
19+
publicfunction__construct(privatereadonlyiterable$checkers)
20+
{
21+
}
22+
23+
publicfunctioncheckPreAuth(UserInterface$user):void
24+
{
25+
foreach ($this->checkersas$checker) {
26+
$checker->checkPreAuth($user);
27+
}
28+
}
29+
30+
publicfunctioncheckPostAuth(UserInterface$user):void
31+
{
32+
foreach ($this->checkersas$checker) {
33+
$checker->checkPostAuth($user);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp