Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 86a9c73

Browse files
Merge branch '2.8' into 3.4
* 2.8: [Security] Fix logout #27250 limiting GET_LOCK key up to 64 char due to changes in MySQL 5.7.5 and later [Profiler] Remove propel & event_listener_loading category identifiers [Filesystem] Fix usages of error_get_last() [Debug] Fix populating error_get_last() for handled silent errors Suppress warnings when open_basedir is non-empty
2 parents 10a2d39 + a8122f8 commit 86a9c73

File tree

27 files changed

+271
-91
lines changed

27 files changed

+271
-91
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,15 @@ private function createFirewalls($config, ContainerBuilder $container)
280280

281281
$configId = 'security.firewall.map.config.'.$name;
282282

283-
list($matcher, $listeners, $exceptionListener) = $this->createFirewall($container, $name, $firewall, $authenticationProviders, $providerIds, $configId);
283+
list($matcher, $listeners, $exceptionListener, $logoutListener) = $this->createFirewall($container, $name, $firewall, $authenticationProviders, $providerIds, $configId);
284284

285285
$contextId = 'security.firewall.map.context.'.$name;
286286
$context = $container->setDefinition($contextId, new ChildDefinition('security.firewall.context'));
287287
$context
288288
->replaceArgument(0, new IteratorArgument($listeners))
289289
->replaceArgument(1, $exceptionListener)
290-
->replaceArgument(2, new Reference($configId))
290+
->replaceArgument(2, $logoutListener)
291+
->replaceArgument(3, new Reference($configId))
291292
;
292293

293294
$contextRefs[$contextId] = new Reference($contextId);
@@ -333,7 +334,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
333334

334335
// Security disabled?
335336
if (false === $firewall['security']) {
336-
return array($matcher, array(), null);
337+
return array($matcher, array(), null, null);
337338
}
338339

339340
$config->replaceArgument(4, $firewall['stateless']);
@@ -381,16 +382,15 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
381382
$config->replaceArgument(6, $contextKey);
382383

383384
// Logout listener
385+
$logoutListenerId = null;
384386
if (isset($firewall['logout'])) {
385-
$listenerKeys[] = 'logout';
386-
$listenerId = 'security.logout_listener.'.$id;
387-
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.logout_listener'));
388-
$listener->replaceArgument(3, array(
387+
$logoutListenerId = 'security.logout_listener.'.$id;
388+
$logoutListener = $container->setDefinition($logoutListenerId, new ChildDefinition('security.logout_listener'));
389+
$logoutListener->replaceArgument(3, array(
389390
'csrf_parameter' => $firewall['logout']['csrf_parameter'],
390391
'csrf_token_id' => $firewall['logout']['csrf_token_id'],
391392
'logout_path' => $firewall['logout']['path'],
392393
));
393-
$listeners[] = new Reference($listenerId);
394394

395395
// add logout success handler
396396
if (isset($firewall['logout']['success_handler'])) {
@@ -400,16 +400,16 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
400400
$logoutSuccessHandler = $container->setDefinition($logoutSuccessHandlerId, new ChildDefinition('security.logout.success_handler'));
401401
$logoutSuccessHandler->replaceArgument(1, $firewall['logout']['target']);
402402
}
403-
$listener->replaceArgument(2, new Reference($logoutSuccessHandlerId));
403+
$logoutListener->replaceArgument(2, new Reference($logoutSuccessHandlerId));
404404

405405
// add CSRF provider
406406
if (isset($firewall['logout']['csrf_token_generator'])) {
407-
$listener->addArgument(new Reference($firewall['logout']['csrf_token_generator']));
407+
$logoutListener->addArgument(new Reference($firewall['logout']['csrf_token_generator']));
408408
}
409409

410410
// add session logout handler
411411
if (true === $firewall['logout']['invalidate_session'] && false === $firewall['stateless']) {
412-
$listener->addMethodCall('addHandler', array(new Reference('security.logout.handler.session')));
412+
$logoutListener->addMethodCall('addHandler', array(new Reference('security.logout.handler.session')));
413413
}
414414

415415
// add cookie logout handler
@@ -418,12 +418,12 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
418418
$cookieHandler = $container->setDefinition($cookieHandlerId, new ChildDefinition('security.logout.handler.cookie_clearing'));
419419
$cookieHandler->addArgument($firewall['logout']['delete_cookies']);
420420

421-
$listener->addMethodCall('addHandler', array(new Reference($cookieHandlerId)));
421+
$logoutListener->addMethodCall('addHandler', array(new Reference($cookieHandlerId)));
422422
}
423423

424424
// add custom handlers
425425
foreach ($firewall['logout']['handlers'] as $handlerId) {
426-
$listener->addMethodCall('addHandler', array(new Reference($handlerId)));
426+
$logoutListener->addMethodCall('addHandler', array(new Reference($handlerId)));
427427
}
428428

429429
// register with LogoutUrlGenerator
@@ -483,7 +483,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
483483
$config->replaceArgument(10, $listenerKeys);
484484
$config->replaceArgument(11, isset($firewall['switch_user']) ? $firewall['switch_user'] : null);
485485

486-
return array($matcher, $listeners, $exceptionListener);
486+
return array($matcher, $listeners, $exceptionListener, null !== $logoutListenerId ? new Reference($logoutListenerId) : null);
487487
}
488488

489489
private function createContextListener($container, $contextKey, $logoutUserOnChange)

src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
<service id="security.firewall.context" class="Symfony\Bundle\SecurityBundle\Security\FirewallContext" abstract="true">
139139
<argument type="collection" />
140140
<argument type="service" id="security.exception_listener" />
141+
<argument /> <!-- LogoutListener -->
141142
<argument /> <!-- FirewallConfig -->
142143
</service>
143144

src/Symfony/Bundle/SecurityBundle/Security/FirewallContext.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\SecurityBundle\Security;
1313

1414
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
15+
use Symfony\Component\Security\Http\Firewall\LogoutListener;
1516

1617
/**
1718
* This is a wrapper around the actual firewall configuration which allows us
@@ -23,18 +24,25 @@ class FirewallContext
2324
{
2425
private $listeners;
2526
private $exceptionListener;
27+
private $logoutListener;
2628
private $config;
2729

2830
/**
29-
* @param \Traversable|array $listeners
30-
* @param ExceptionListener|null $exceptionListener
31-
* @param FirewallConfig|null $firewallConfig
31+
* @param \Traversable|array $listeners
32+
* @param LogoutListener|null $logoutListener
3233
*/
33-
public function __construct($listeners, ExceptionListener $exceptionListener = null, FirewallConfig $config = null)
34+
public function __construct($listeners, ExceptionListener $exceptionListener = null, $logoutListener = null, FirewallConfig $config = null)
3435
{
3536
$this->listeners = $listeners;
3637
$this->exceptionListener = $exceptionListener;
37-
$this->config = $config;
38+
if ($logoutListener instanceof FirewallConfig) {
39+
$this->config = $logoutListener;
40+
} elseif (null === $logoutListener || $logoutListener instanceof LogoutListener) {
41+
$this->logoutListener = $logoutListener;
42+
$this->config = $config;
43+
} else {
44+
throw new \InvalidArgumentException(sprintf('Argument 3 passed to %s() must be instance of %s or null, %s given.', __METHOD__, LogoutListener::class, is_object($logoutListener) ? get_class($logoutListener) : gettype($logoutListener)));
45+
}
3846
}
3947

4048
public function getConfig()
@@ -49,7 +57,7 @@ public function getContext()
4957
{
5058
@trigger_error(sprintf('Method %s() is deprecated since Symfony 3.3 and will be removed in 4.0. Use %s::getListeners/getExceptionListener() instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED);
5159

52-
return array($this->getListeners(), $this->getExceptionListener());
60+
return array($this->getListeners(), $this->getExceptionListener(), $this->getLogoutListener());
5361
}
5462

5563
/**
@@ -64,4 +72,9 @@ public function getExceptionListener()
6472
{
6573
return $this->exceptionListener;
6674
}
75+
76+
public function getLogoutListener()
77+
{
78+
return $this->logoutListener;
79+
}
6780
}

src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ public function getListeners(Request $request)
121121
$context = $this->getFirewallContext($request);
122122

123123
if (null === $context) {
124-
return array(array(), null);
124+
return array(array(), null, null);
125125
}
126126

127-
return array($context->getListeners(), $context->getExceptionListener());
127+
return array($context->getListeners(), $context->getExceptionListener(), $context->getLogoutListener());
128128
}
129129

130130
/**

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testFirewalls()
8585
$arguments = $contextDef->getArguments();
8686
$listeners[] = array_map('strval', $arguments['index_0']->getValues());
8787

88-
$configDef = $container->getDefinition((string) $arguments['index_2']);
88+
$configDef = $container->getDefinition((string) $arguments['index_3']);
8989
$configs[] = array_values($configDef->getArguments());
9090
}
9191

@@ -113,7 +113,6 @@ public function testFirewalls()
113113
null,
114114
null,
115115
array(
116-
'logout',
117116
'switch_user',
118117
'x509',
119118
'remote_user',
@@ -185,7 +184,6 @@ public function testFirewalls()
185184
array(),
186185
array(
187186
'security.channel_listener',
188-
'security.logout_listener.secure',
189187
'security.authentication.listener.x509.secure',
190188
'security.authentication.listener.remote_user.secure',
191189
'security.authentication.listener.form.secure',
@@ -235,7 +233,7 @@ public function testFirewallsWithDigest()
235233
$arguments = $contextDef->getArguments();
236234
$listeners[] = array_map('strval', $arguments['index_0']->getValues());
237235

238-
$configDef = $container->getDefinition((string) $arguments['index_2']);
236+
$configDef = $container->getDefinition((string) $arguments['index_3']);
239237
$configs[] = array_values($configDef->getArguments());
240238
}
241239

@@ -263,7 +261,6 @@ public function testFirewallsWithDigest()
263261
null,
264262
null,
265263
array(
266-
'logout',
267264
'switch_user',
268265
'x509',
269266
'remote_user',
@@ -319,7 +316,6 @@ public function testFirewallsWithDigest()
319316
array(),
320317
array(
321318
'security.channel_listener',
322-
'security.logout_listener.secure',
323319
'security.authentication.listener.x509.secure',
324320
'security.authentication.listener.remote_user.secure',
325321
'security.authentication.listener.form.secure',
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Bundle\SecurityBundle\Tests\Functional;
13+
14+
class LogoutTest extends WebTestCase
15+
{
16+
public function testSessionLessRememberMeLogout()
17+
{
18+
$client = $this->createClient(array('test_case' => 'RememberMeLogout', 'root_config' => 'config.yml'));
19+
20+
$client->request('POST', '/login', array(
21+
'_username' => 'johannes',
22+
'_password' => 'test',
23+
));
24+
25+
$cookieJar = $client->getCookieJar();
26+
$cookieJar->expire(session_name());
27+
28+
$this->assertNotNull($cookieJar->get('REMEMBERME'));
29+
30+
$client->request('GET', '/logout');
31+
32+
$this->assertNull($cookieJar->get('REMEMBERME'));
33+
}
34+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
use Symfony\Bundle\SecurityBundle\SecurityBundle;
13+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
14+
15+
return array(
16+
new FrameworkBundle(),
17+
new SecurityBundle(),
18+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
imports:
2+
- { resource: ./../config/framework.yml }
3+
4+
security:
5+
encoders:
6+
Symfony\Component\Security\Core\User\User: plaintext
7+
8+
providers:
9+
in_memory:
10+
memory:
11+
users:
12+
johannes: { password: test, roles: [ROLE_USER] }
13+
14+
firewalls:
15+
default:
16+
form_login:
17+
check_path: login
18+
remember_me: true
19+
require_previous_session: false
20+
remember_me:
21+
always_remember_me: true
22+
secret: key
23+
logout: ~
24+
anonymous: ~
25+
stateless: true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
login:
2+
path: /login
3+
4+
logout:
5+
path: /logout

src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallContextTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,27 @@
1616
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
1717
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
1818
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
19+
use Symfony\Component\Security\Http\Firewall\LogoutListener;
1920

2021
class FirewallContextTest extends TestCase
2122
{
2223
public function testGetters()
2324
{
2425
$config = new FirewallConfig('main', 'user_checker', 'request_matcher');
2526
$exceptionListener = $this->getExceptionListenerMock();
27+
$logoutListener = $this->getLogoutListenerMock();
2628
$listeners = array(
2729
$this
2830
->getMockBuilder(ListenerInterface::class)
2931
->disableOriginalConstructor()
3032
->getMock(),
3133
);
3234

33-
$context = new FirewallContext($listeners, $exceptionListener, $config);
35+
$context = new FirewallContext($listeners, $exceptionListener, $logoutListener, $config);
3436

3537
$this->assertEquals($listeners, $context->getListeners());
3638
$this->assertEquals($exceptionListener, $context->getExceptionListener());
39+
$this->assertEquals($logoutListener, $context->getLogoutListener());
3740
$this->assertEquals($config, $context->getConfig());
3841
}
3942

@@ -43,10 +46,12 @@ public function testGetters()
4346
*/
4447
public function testGetContext()
4548
{
46-
$context = (new FirewallContext($listeners = array(), $exceptionListener = $this->getExceptionListenerMock(), new FirewallConfig('main', 'request_matcher', 'user_checker')))
49+
$exceptionListener = $this->getExceptionListenerMock();
50+
$logoutListener = $this->getLogoutListenerMock();
51+
$context = (new FirewallContext($listeners = array(), $exceptionListener, $logoutListener, new FirewallConfig('main', 'request_matcher', 'user_checker')))
4752
->getContext();
4853

49-
$this->assertEquals(array($listeners, $exceptionListener), $context);
54+
$this->assertEquals(array($listeners, $exceptionListener, $logoutListener), $context);
5055
}
5156

5257
private function getExceptionListenerMock()
@@ -56,4 +61,12 @@ private function getExceptionListenerMock()
5661
->disableOriginalConstructor()
5762
->getMock();
5863
}
64+
65+
private function getLogoutListenerMock()
66+
{
67+
return $this
68+
->getMockBuilder(LogoutListener::class)
69+
->disableOriginalConstructor()
70+
->getMock();
71+
}
5972
}

0 commit comments

Comments
 (0)