You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 31, 2024. It is now read-only.
feature #22048 [Security] deprecate the Role and SwitchUserRole classes (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
-------
d7aaa615b9 deprecate the Role and SwitchUserRole classes
@@ -25,7 +23,7 @@ class AnonymousToken extends AbstractToken
25
23
/**
26
24
* @param string $secret A secret used to make sure the token is created by the app and not by a malicious client
27
25
* @param string|object $user The user can be a UserInterface instance, or an object implementing a __toString method or the username as a regular string
* PreAuthenticatedToken implements a pre-authenticated token.
18
16
*
@@ -24,10 +22,10 @@ class PreAuthenticatedToken extends AbstractToken
24
22
private$providerKey;
25
23
26
24
/**
27
-
* @param string|object $user The user can be a UserInterface instance, or an object implementing a __toString method or the username as a regular string
28
-
* @param mixed $credentials The user credentials
29
-
* @param string $providerKey The provider key
30
-
* @param (Role|string)[] $roles An array of roles
25
+
* @param string|object $user The user can be a UserInterface instance, or an object implementing a __toString method or the username as a regular string
if (null !== $token && !method_exists($token, 'getRoleNames')) {
43
+
@trigger_error(sprintf('Not implementing the getRoleNames() method in %s which implements %s is deprecated since Symfony 4.3.', \get_class($token), TokenInterface::class), E_USER_DEPRECATED);
* Token representing a user who temporarily impersonates another one.
16
+
*
17
+
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
18
+
*/
19
+
class SwitchUserToken extends UsernamePasswordToken
20
+
{
21
+
private$originalToken;
22
+
23
+
/**
24
+
* @param string|object $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method
25
+
* @param mixed $credentials This usually is the password of the user
26
+
* @param string $providerKey The provider key
27
+
* @param string[] $roles An array of roles
28
+
* @param TokenInterface $originalToken The token of the user who switched to the current user
* UsernamePasswordToken implements a username and password token.
18
16
*
@@ -24,10 +22,10 @@ class UsernamePasswordToken extends AbstractToken
24
22
private$providerKey;
25
23
26
24
/**
27
-
* @param string|object $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method
28
-
* @param mixed $credentials This usually is the password of the user
29
-
* @param string $providerKey The provider key
30
-
* @param (Role|string)[] $roles An array of roles
25
+
* @param string|object $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method
26
+
* @param mixed $credentials This usually is the password of the user
if ($this->roleHierarchyinstanceof RoleHierarchy) {
96
+
if (method_exists($token, 'getRoleNames')) {
97
+
$rolesFromToken = $token->getRoleNames();
98
+
} else {
99
+
@trigger_error(sprintf('Not implementing the getRoleNames() method in %s which implements %s is deprecated since Symfony 4.3.', \get_class($token), TokenInterface::class), E_USER_DEPRECATED);
@trigger_error(sprintf('Not implementing the getRoleNames() method in %s which implements %s is deprecated since Symfony 4.3.', \get_class($token), TokenInterface::class), E_USER_DEPRECATED);
0 commit comments