Skip to content

[Security] deprecate the Role and SwitchUserRole classes #22048

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

Merged
merged 1 commit into from
Feb 25, 2019

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Mar 17, 2017

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #20824
License MIT
Doc PR symfony/symfony-docs#11047

In #20801, we deprecated the RoleInterface. The next logical step would be to also deprecate the Role class. However, we currently have the SwitchUserRole class (a sub-class of Role) that acts as an indicator to check whether or not the authenticated user switched to another user.

This PR proposes an alternative solution to the usage of the special SwitchUserRole class by storing the original token inside the UsernamePasswordToken. This PR is not complete, but rather acts as a proof of concept of how we could get rid of the Role and the SwitchUserRole classes.

Please share your opinions whether you think this is a valid approach and I will be happy to finalise the PR.

@xabbuh xabbuh force-pushed the deprecate-role-class branch from 729a3aa to 71b26ae Compare March 17, 2017 22:04
@xabbuh xabbuh force-pushed the deprecate-role-class branch 2 times, most recently from a8df9f2 to 1aec9b7 Compare March 18, 2017 09:13
fabpot added a commit that referenced this pull request Mar 22, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

[Security] simplify the SwitchUserListenerTest

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

While working on #22048 I noticed that the `SwitchUserListenerTest` was more complicated than necessary by mocking a lot of stuff that didn't need to be mocked.

Commits
-------

923bbdb [Security] simplify the SwitchUserListenerTest
@nicolas-grekas nicolas-grekas added this to the 3.x milestone Mar 24, 2017
@xabbuh xabbuh changed the base branch from master to 3.4 May 18, 2017 07:16
@xabbuh
Copy link
Member Author

xabbuh commented Jul 12, 2017

@symfony/deciders I would like to hear your opinion on this topic? Do you think it's worth to finish this approach? Should we take another road?

@nicolas-grekas
Copy link
Member

@fabpot @stof you might be the best to help here?

@chalasr
Copy link
Member

chalasr commented Aug 31, 2017

IMO it's a good move. We still need to be able to get both impersonator/impersonated user from the token, I guess it's planed

@xabbuh
Copy link
Member Author

xabbuh commented Aug 31, 2017

IMO it's a good move. We still need to be able to get both impersonator/impersonated user from the token, I guess it's planed

@chalasr I guess the SwitchUserToken (or maybe better SwitchedUserToken) suggested by @HeahDude could be a good solution.

@chalasr
Copy link
Member

chalasr commented Aug 31, 2017

Agreed, that would remove the need for isUserSwitched.

@nicolas-grekas
Copy link
Member

@xabbuh will you have tome to finish this PR for 3.4?

@xabbuh
Copy link
Member Author

xabbuh commented Sep 26, 2017

Yes, I am working on it.

@nicolas-grekas
Copy link
Member

should we move to 4.1?

@xabbuh
Copy link
Member Author

xabbuh commented Oct 8, 2017

I think so.

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 8, 2017
@xabbuh xabbuh force-pushed the deprecate-role-class branch from 1aec9b7 to daf09cb Compare November 15, 2017 19:46
@xabbuh xabbuh changed the base branch from 3.4 to master November 15, 2017 19:48
@xabbuh xabbuh force-pushed the deprecate-role-class branch from daf09cb to 7194244 Compare November 15, 2017 19:51
@xabbuh xabbuh force-pushed the deprecate-role-class branch from 7194244 to 2054024 Compare November 23, 2017 09:54
@xabbuh xabbuh force-pushed the deprecate-role-class branch 3 times, most recently from b871a65 to b2cfbb3 Compare February 22, 2019 23:11
@xabbuh xabbuh force-pushed the deprecate-role-class branch from b2cfbb3 to d7aaa61 Compare February 22, 2019 23:57
@xabbuh
Copy link
Member Author

xabbuh commented Feb 22, 2019

tests pass now

Status: Needs Review

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

Nice!

@fabpot
Copy link
Member

fabpot commented Feb 25, 2019

Thank you @xabbuh.

@fabpot fabpot merged commit d7aaa61 into symfony:master Feb 25, 2019
fabpot added a commit that referenced this pull request Feb 25, 2019
…es (xabbuh)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Security] deprecate the Role and SwitchUserRole classes

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #20824
| License       | MIT
| Doc PR        | symfony/symfony-docs#11047

In #20801, we deprecated the `RoleInterface`. The next logical step would be to also deprecate the `Role` class. However, we currently have the `SwitchUserRole` class (a sub-class of `Role`) that acts as an indicator to check whether or not the authenticated user switched to another user.

This PR proposes an alternative solution to the usage of the special `SwitchUserRole` class by storing the original token inside the `UsernamePasswordToken`. This PR is not complete, but rather acts as a proof of concept of how we could get rid of the `Role` and the `SwitchUserRole` classes.

Please share your opinions whether you think this is a valid approach and I will be happy to finalise the PR.

Commits
-------

d7aaa61 deprecate the Role and SwitchUserRole classes
@xabbuh xabbuh deleted the deprecate-role-class branch February 25, 2019 16:17
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Feb 26, 2019
This PR was merged into the master branch.

Discussion
----------

document the deprecation of the role classes

see symfony/symfony#22048

Commits
-------

0fbef77 document the deprecation of the role classes
@@ -15,6 +15,8 @@
* RoleHierarchyInterface is the interface for a role hierarchy.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 4.3, to be removed in 5.0.
Copy link
Member

Choose a reason for hiding this comment

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

Why deprecating this interface instead of asking to implement the new method in it ? Removing the interface would remove a supported extension point.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't remember why I did that initially. I guess it was due to an earlier implementation. #30388 will revert this part.

symfony-splitter pushed a commit to symfony/workflow that referenced this pull request Mar 23, 2019
…buh)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Security] undeprecate the RoleHierarchyInterface

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#22048 (comment)
| License       | MIT
| Doc PR        |

Instead of deprecating the interface it is sufficient to deprecate its
getReachableRoles() method and add a new getReachableRoleNames() method
in Symfony 5.

Commits
-------

2d3f2b7a74 undeprecate the RoleHierarchyInterface
fabpot added a commit that referenced this pull request Mar 23, 2019
…buh)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Security] undeprecate the RoleHierarchyInterface

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22048 (comment)
| License       | MIT
| Doc PR        |

Instead of deprecating the interface it is sufficient to deprecate its
getReachableRoles() method and add a new getReachableRoleNames() method
in Symfony 5.

Commits
-------

2d3f2b7 undeprecate the RoleHierarchyInterface
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
* @param (Role|string)[] $roles An array of roles
* @param UserInterface $user The user!
* @param string $providerKey The provider (firewall) key
* @param string[] $roles An array of roles
Copy link
Contributor

@gmponos gmponos Jun 13, 2019

Choose a reason for hiding this comment

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

Although the Role object is deprecated the $roles argument can still accept Roles object..

this change breaks my phpstan when I have something like this:

$newToken = new PostAuthenticationGuardToken($user, 'secured_area', $user->getRoles());

would it be acceptable to revert this docblock change?

Copy link
Contributor

Choose a reason for hiding this comment

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

We normally do not document the deprecated arguments anymore. Same as if we deprecate an argument and use func_get_arg for BC. Otherwise people could think the deprecated way is still the right way and write code accordingly. So IMO we should not change that. Either fix the deprecation or ignore the phpstan error.

Copy link
Contributor

Choose a reason for hiding this comment

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

We normally do not document the deprecated arguments anymore.

I guess the same does not apply here because it is a return argument?

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be changed there as well.

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.

10 participants