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 3 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 @@ -276,12 +276,6 @@ private function createFirewalls($config, ContainerBuilder $container)
$customUserChecker = true;
}

if (!isset($firewall['logout_on_user_change']) || !$firewall['logout_on_user_change']) {
@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);
Copy link
Member

Choose a reason for hiding this comment

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

Those 2 lines can bu moved back to where they were, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 😉

Expand Down Expand Up @@ -370,7 +364,11 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
$contextKey = $firewall['context'];
}

$listeners[] = new Reference($this->createContextListener($container, $contextKey));
if (!isset($firewall['logout_on_user_change']) || !$firewall['logout_on_user_change']) {
@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.', $id), E_USER_DEPRECATED);
}

$listeners[] = new Reference($this->createContextListener($container, $contextKey, $firewall['logout_on_user_change']));
Copy link
Member

Choose a reason for hiding this comment

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

must be reached only if the key is set on $firewall. Also I would store the option value only instead of the whole config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

must be reached only if the key is set on $firewall.

Not sure I follow. That line was always reached before as well?

Also I would store the option value only instead of the whole config

👍

Copy link
Member

Choose a reason for hiding this comment

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

Now it's accessing $firewall['logout_on_user_change'] which might be not set.
In this case we should not register the firewall in $firewallsByContextKey, perhaps pass null to createContextListener() in order to not add the method call as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Forgot that it's a bool node, sorry for the noise!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem ;) will update the PR after work

}

$config->replaceArgument(6, $contextKey);
Expand Down Expand Up @@ -481,7 +479,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
return array($matcher, $listeners, $exceptionListener);
}

private function createContextListener($container, $contextKey)
private function createContextListener($container, $contextKey, $logoutUserOnChange)
{
if (isset($this->contextListeners[$contextKey])) {
return $this->contextListeners[$contextKey];
Expand All @@ -490,6 +488,7 @@ private function createContextListener($container, $contextKey)
$listenerId = 'security.context_listener.'.count($this->contextListeners);
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.context_listener'));
$listener->replaceArgument(2, $contextKey);
$listener->addMethodCall('setLogoutOnUserChange', array($logoutUserOnChange));

return $this->contextListeners[$contextKey] = $listenerId;
}
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