8000 [SecurityBundle] fix setLogoutOnUserChange calls for context listeners by dmaicher · Pull Request #25272 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[SecurityBundle] fix setLogoutOnUserChange calls for context listeners #25272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,17 @@ private function createFirewalls($config, ContainerBuilder $container)
@trigger_error(sprintf('Not setting "logout_on_user_change" to true on firewall "%s" is deprecated as of 3.4, it will always be true in 4.0.', $name), E_USER_DEPRECATED);
}

$contextListenerDefinition->addMethodCall('setLogoutOnUserChange', array($firewall['logout_on_user_change']));

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

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

foreach ($listeners as $listener) {
if (0 === strpos($listenerId = (string) $listener, 'security.context_listener.')) {
$container->getDefinition($listenerId)->addMethodCall('setLogoutOnUserChange', array($firewall['logout_on_user_change']));
Copy link
Member
@chalasr chalasr Dec 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done in createContextListener by passing the option value as argument to createFirewall first (it has the whole config), or iterate over $this->contextListeners after the createFirewall loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chalasr done 😉 Will make merging into higher branches a bit harder though 😋

break;
}
}

$contextId = 'security.firewall.map.context.'.$name;
$context = $container->setDefinition($contextId, new ChildDefinition('security.firewall.context'));
$context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testDisableRoleHierarchyVoter()
* @group legacy
* @expectedDeprecation Not setting "logout_on_user_change" to true on firewall "some_firewall" is deprecated as of 3.4, it will always be true in 4.0.
*/
public function testDeprecationForUserLogout()
public function testConfiguresLogoutOnUserChangeForContextListenersCorrectly()
{
$container = $this->getRawContainer();

Expand All @@ -142,10 +142,18 @@ public function testDeprecationForUserLogout()
'http_basic' => null,
'logout_on_user_change' => false,
),
'some_other_firewall' => array(
'pattern' => '/.*',
'http_basic' => null,
'logout_on_user_change' => true,
),
),
));

$container->compile();

$this->assertEquals(array(array('setLogoutOnUserChange', array(false))), $container->getDefinition('security.context_listener.0')->getMethodCalls());
$this->assertEquals(array(array('setLogoutOnUserChange', array(true))), $container->getDefinition('security.context_listener.1')->getMethodCalls());
}

/**
Expand Down
0