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

Skip to content

Deprecate the use of objects as security roles #20824

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
javiereguiluz opened this issue Dec 8, 2016 · 10 comments
Closed

Deprecate the use of objects as security roles #20824

javiereguiluz opened this issue Dec 8, 2016 · 10 comments

Comments

@javiereguiluz
Copy link
Member

As discussed in #20801 (comment) we're ready to deprecate the use of objects as security roles and start using simple strings as roles.

@stof
Copy link
Member

stof commented Dec 8, 2016

Note that the handling of the user switching needs to be refactored as it currently relies on a special role class. but the good news is that I implemented a similar feature at work in a way not relying on a custom role class. So I can refactor the Symfony system too.

@linaori
Copy link
Contributor

linaori commented Dec 8, 2016

That info could also be stored in the token attributes

@stof
Copy link
Member

stof commented Dec 8, 2016

@iltar this is exactly what my own implementation is doing. And it works totally fine (the hard part will be the BC layer)

@linaori
Copy link
Contributor

linaori commented Dec 8, 2016

What could be done if I'm understanding its inner workings:

  • Add the info to attributes
  • Throw a deprecation when it is an object
  • if it's not an object and matches the string variant, check the attributes, else the role and throw a deprecation that the attribute should be set instead and a string role should be used

But I have to admit, never used the user switcher before, only a system where you can absorb roles to test stuff by impersonating.

@stof
Copy link
Member

stof commented Dec 8, 2016

@iltar the complexity of the BC layer is related to the parts allowing to check whether we are currently switching or no (which should not be handled by a role at all)

@afoeder
Copy link

afoeder commented Feb 27, 2017

Just for understanding (don't want to re-ignit any discussion); why? Isn't it a step back going from objects to strings?

@linaori
Copy link
Contributor

linaori commented Feb 27, 2017

@afoeder there's no real benefit of using objects instead of strings. Eventually it just leads to overhead because you have to call Role::getRole()

@afoeder
Copy link

afoeder commented Feb 27, 2017

There totally is, Usage Search! The safety of having objects. Refactoring abilities. Maybe stuff a particular Role does. Just OO.

@althaus
Copy link
Contributor

althaus commented Jul 13, 2017

We link custom data/privileges with user roles and people can define their own roles for a complex authorization system. Do we have to rework our code and move al that stuff to custom "roles" with their own voter?

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 8, 2017
@fsmeier
Copy link

fsmeier commented Apr 17, 2018

There totally is, Usage Search! The safety of having objects. Refactoring abilities. Maybe stuff a particular Role does. Just OO.

+1 on this. In every cross-linked issue here it is pointed out, that this step was dicussed, but I can not find the discussion. With just reading the issues and comments I do not get why forcing ithe remove of the OO for roles is needed here. Afaik the role-string always needs the "ROLE_"-prefix (or is this changed?) and with this interface + class i could add this prefix to my roles which i fetched from the database.

@nicolas-grekas nicolas-grekas removed this from the 4.1 milestone Apr 20, 2018
@fabpot fabpot closed this as completed Feb 25, 2019
fabpot added a commit that referenced this issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants