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

Appearance settings

Commit 924c1f0

Browse filesBrowse files
committed
feature #21792 [Security] deprecate multiple providers in context listener (xabbuh)
This PR was squashed before being merged into the 3.3-dev branch (closes #21792). Discussion ---------- [Security] deprecate multiple providers in context listener Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Passing multiple user providers to the context listener does not make much sense. The listener is only responsible to refresh users for a particular firewall. Thus, it must only be aware of the user provider for this particular firewall. Commits ------- 53df0de [Security] deprecate multiple providers in context listener fbd9f88 [SecurityBundle] only pass relevant user provider
2 parents afff0ce + 53df0de commit 924c1f0
Copy full SHA for 924c1f0

File tree

6 files changed

+38
-10
lines changed
Filter options

6 files changed

+38
-10
lines changed

‎UPGRADE-3.3.md

Copy file name to clipboardExpand all lines: UPGRADE-3.3.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ Process
105105
Security
106106
--------
107107

108+
* Deprecated the ability to pass multiple user providers to the `ContextListener`. Pass only the user provider responsible
109+
for the active firewall instead.
110+
108111
* The `RoleInterface` has been deprecated. Extend the `Symfony\Component\Security\Core\Role\Role`
109112
class in your custom role implementations instead.
110113

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ Process
261261
Security
262262
--------
263263

264+
* Dropped support for passing multiple user providers to the `ContextListener`. Pass only the user provider responsible
265+
for the active firewall instead.
266+
264267
* The `RoleInterface` has been removed. Extend the `Symfony\Component\Security\Core\Role\Role`
265268
class instead.
266269

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ private function createContextListener($container, $contextKey, $providerId)
434434

435435
$listenerId = 'security.context_listener.'.count($this->contextListeners);
436436
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.context_listener'));
437-
$listener->replaceArgument(1, array(new Reference($providerId)));
437+
$listener->replaceArgument(1, new Reference($providerId));
438438
$listener->replaceArgument(2, $contextKey);
439439

440440
return $this->contextListeners[$contextKey] = $listenerId;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* Deprecated the ability to pass multiple user providers to the `ContextListener`. Pass only the user provider responsible
8+
for the active firewall instead.
9+
410
3.2.0
511
-----
612

‎src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Firewall/ContextListener.php
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,26 @@ class ContextListener implements ListenerInterface
4444
private $registered;
4545
private $trustResolver;
4646

47-
public function __construct(TokenStorageInterface $tokenStorage, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, AuthenticationTrustResolverInterface $trustResolver = null)
47+
/**
48+
* @param TokenStorageInterface $tokenStorage
49+
* @param UserProviderInterface|UserProviderInterface[] $userProviders
50+
* @param string $contextKey
51+
* @param LoggerInterface|null $logger
52+
* @param EventDispatcherInterface|null $dispatcher
53+
* @param AuthenticationTrustResolverInterface|null $trustResolver
54+
*/
55+
public function __construct(TokenStorageInterface $tokenStorage, $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, AuthenticationTrustResolverInterface $trustResolver = null)
4856
{
4957
if (empty($contextKey)) {
5058
throw new \InvalidArgumentException('$contextKey must not be empty.');
5159
}
5260

61+
if (is_array($userProviders)) {
62+
@trigger_error(sprintf('Being able to pass multiple user providers to the constructor of %s is deprecated since version 3.3 and will not be supported anymore in 4.0. Only pass the user provider for the current firewall context instead.', __CLASS__), E_USER_DEPRECATED);
63+
} else {
64+
$userProviders = array($userProviders);
65+
}
66+
5367
foreach ($userProviders as $userProvider) {
5468
if (!$userProvider instanceof UserProviderInterface) {
5569
throw new \InvalidArgumentException(sprintf('User provider "%s" must implement "Symfony\Component\Security\Core\User\UserProviderInterface".', get_class($userProvider)));

‎src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
2323
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
2424
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
25+
use Symfony\Component\Security\Core\User\UserProviderInterface;
2526
use Symfony\Component\Security\Http\Firewall\ContextListener;
2627
use Symfony\Component\EventDispatcher\EventDispatcher;
2728

@@ -35,12 +36,13 @@ public function testItRequiresContextKey()
3536
{
3637
new ContextListener(
3738
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(),
38-
array(),
39+
$this->getMockBuilder(UserProviderInterface::class)->getMock(),
3940
''
4041
);
4142
}
4243

4344
/**
45+
* @group legacy
4446
* @expectedException \InvalidArgumentException
4547
* @expectedExceptionMessage User provider "stdClass" must implement "Symfony\Component\Security\Core\User\UserProviderInterface
4648
*/
@@ -109,7 +111,7 @@ public function testOnKernelResponseWithoutSession()
109111
new Response()
110112
);
111113

112-
$listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
114+
$listener = new ContextListener($tokenStorage, $this->getMockBuilder(UserProviderInterface::class)->getMock(), 'session', null, new EventDispatcher());
113115
$listener->onKernelResponse($event);
114116

115117
$this->assertTrue($session->isStarted());
@@ -128,7 +130,7 @@ public function testOnKernelResponseWithoutSessionNorToken()
128130
new Response()
129131
);
130132

131-
$listener = new ContextListener(new TokenStorage(), array(), 'session', null, new EventDispatcher());
133+
$listener = new ContextListener(new TokenStorage(), $this->getMockBuilder(UserProviderInterface::class)->getMock(), 'session', null, new EventDispatcher());
132134
$listener->onKernelResponse($event);
133135

134136
$this->assertFalse($session->isStarted());
@@ -163,7 +165,7 @@ public function testInvalidTokenInSession($token)
163165
->method('setToken')
164166
->with(null);
165167

166-
$listener = new ContextListener($tokenStorage, array(), 'key123');
168+
$listener = new ContextListener($tokenStorage, $this->getMockBuilder(UserProviderInterface::class)->getMock(), 'key123');
167169
$listener->handle($event);
168170
}
169171

@@ -184,7 +186,7 @@ public function testHandleAddsKernelResponseListener()
184186
->disableOriginalConstructor()
185187
->getMock();
186188

187-
$listener = new ContextListener($tokenStorage, array(), 'key123', null, $dispatcher);
189+
$listener = new ContextListener($tokenStorage, $this->getMockBuilder(UserProviderInterface::class)->getMock(), 'key123', null, $dispatcher);
188190

189191
$event->expects($this->any())
190192
->method('isMasterRequest')
@@ -208,7 +210,7 @@ public function testOnKernelResponseListenerRemovesItself()
208210
->disableOriginalConstructor()
209211
->getMock();
210212

211-
$listener = new ContextListener($tokenStorage, array(), 'key123', null, $dispatcher);
213+
$listener = new ContextListener($tokenStorage, $this->getMockBuilder(UserProviderInterface::class)->getMock(), 'key123', null, $dispatcher);
212214

213215
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
214216
$request->expects($this->any())
@@ -242,7 +244,7 @@ public function testHandleRemovesTokenIfNoPreviousSessionWasFound()
242244
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
243245
$tokenStorage->expects($this->once())->method('setToken')->with(null);
244246

245-
$listener = new ContextListener($tokenStorage, array(), 'key123');
247+
$listener = new ContextListener($tokenStorage, $this->getMockBuilder(UserProviderInterface::class)->getMock(), 'key123');
246248
$listener->handle($event);
247249
}
248250

@@ -268,7 +270,7 @@ protected function runSessionOnKernelResponse($newToken, $original = null)
268270
new Response()
269271
);
270272

271-
$listener = new ContextListener($tokenStorage, array(), 'session', null, new EventDispatcher());
273+
$listener = new ContextListener($tokenStorage, $this->getMockBuilder(UserProviderInterface::class)->getMock(), 'session', null, new EventDispatcher());
272274
$listener->onKernelResponse($event);
273275

274276
return $session;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.