Skip to content

[Security] #25091 add target user to SwitchUserListener #25092

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 5 commits into from
Closed

[Security] #25091 add target user to SwitchUserListener #25092

wants to merge 5 commits into from

Conversation

jwmickey
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25091
License MIT
Doc PR

This patch provides the target user to the SwitchUserListener's
accessDecisionManager->decide() call as the $object parameter to
give any registered voters extra information.

CHANGELOG-4.0.md Outdated
@@ -1,6 +1,8 @@
CHANGELOG for 4.0.x
===================

* feature #25091 [Security] Add target user to SwitchUserListener (jwmickey)

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to add this, will be done automatically when the version is released after merging.

Copy link
Member

Choose a reason for hiding this comment

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

@iltar is right. But you need to add the feature to the component's changelog instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will move the changelog note to the correct file, thank you.


throw $exception;
if (false === $this->accessDecisionManager->decide($token, array($this->role), $user)) {
throw new AccessDeniedException();
}

if (null !== $this->logger) {
$this->logger->info('Attempting to switch to user.', array('username' => $username));
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this give the wrong username as result now?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder why we would need to do the change on line 129 instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it will give the wrong username, but I did notice that I removed the line that sets attributes on the exception, so I'll add that back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iltar, my apologies, the code I submitted did indeed change the username for JSON requests. The problem stemmed from me originally starting from the 2.7 branch and then rebasing to master, and I ended up changing some code from 2.7 that was different in master without realizing... in any case, lesson learned and thanks for pointing this out

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Nov 22, 2017
@xabbuh
Copy link
Member

xabbuh commented Nov 26, 2017

Can you please rebase on current master? Tests are currently failing.

This patch provides the target user to the SwitchUserListener's
accessDecisionManager->decide() call as the $object parameter to
give any registered voters extra information.
- moved message from the general changelog to the security component's
changelog
- restored exception attributes that were mistakenly removed
@jwmickey
Copy link
Contributor Author

Is there anything else I need to do for this PR?

$exception = new AccessDeniedException();
$exception->setAttributes($this->role);

Copy link
Member

Choose a reason for hiding this comment

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

this change should be reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why should this change be reverted?

Copy link
Member

Choose a reason for hiding this comment

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

Because it's not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry, I don't follow. Are you saying that the $user param does not need to be passed to the accessDecisionManager->decide() call as the 3rd parameter?

Copy link
Member

Choose a reason for hiding this comment

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

Oh that's a misunderstanding then. I was just referring to the blank line which should not have been removed.

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

apart from my minor comment

@chalasr
Copy link
Member

chalasr commented Jan 18, 2018

Thank you @jwmickey and congratz for your first contribution on Symfony!

@chalasr chalasr closed this in 6e6ac9e Jan 18, 2018
@jwmickey
Copy link
Contributor Author

Whoohoo! Thank you @chalasr, very exciting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants