-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
#21571 Comparing roles to detected that users has changed #31177
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
Conversation
src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
Outdated
Show resolved
Hide resolved
This looks like a new feature to me, I would target master. |
src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
Outdated
Show resolved
Hide resolved
9fa23e3
to
0ba835a
Compare
Changed to master |
Thank you, but now it should target |
8df50ce
to
71ba983
Compare
It seems that documentation needs to be improved https://symfony.com/doc/current/contributing/code/pull_requests.html#choose-the-right-branch |
71ba983
to
9104267
Compare
@OskarStark can you please explain how it should be (I'd like to prepare PR):
but why then this PR, should be pointed to 4.4? |
Currently we are in state where
The comment by @fabpot was made before the new |
New features should indeed target the 4.4 branch. It's not the master branch as we have 2 new versions at the same time: 4.4 and 5.0 (which is special as it happens only once every two years). |
Alright I've created symfony/symfony-docs#11741, so this PR can be finally reviewed. |
src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AbstractTokenCompareRoles/bundles.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
Outdated
Show resolved
Hide resolved
…ment branch instead of master for new features. (oleg-andreyev) This PR was merged into the 3.4 branch. Discussion ---------- Adding "special case" when need to select development branch instead of master for new features. As per discussion in symfony#11457 and symfony/symfony#31177 (comment) updated section on how to select branch Commits ------- 1c2bae2 added "special case"
Tests for low are broken, which means that some constraints need to be changed (SecurityBundle depends on the Security component). |
@fabpot the only way is to skip Or there is another solution for such case? |
You can bump the minimum version for the dependency on SecurityBundle. |
and it will pull changes from the current branch, right? |
@oleg-andreyev yes :) |
@xabbuh thanks for explaining, didn't know that |
I can understand this concern but theoretically we can add new role which actually limits previous roles and because we can't detect it the easiest way to ensure that ROLE will be taken into account is to logout user and force them to login again. |
1db8f89
to
00d5875
Compare
Ready for review. Travis failed with:
|
00d5875
to
0a06ce6
Compare
@nicolas-grekas @fabpot @xabbuh @OskarStark please take a look. |
@oleg-andreyev Can you squash your commits please? |
- Updated isEqualTo method to match roles as default User implements EquatableInterface - added test case - bumped symfony/security-core to 4.4
bdd4093
to
4f4c30d
Compare
Done. |
Thank you @oleg-andreyev. |
…ged (oleg-andreyev) This PR was merged into the 4.4 branch. Discussion ---------- #21571 Comparing roles to detected that users has changed | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT | Fixed tickets | #21571 (comment) | Docs | symfony/symfony-docs#11457 **Case 1:** User A has roles `foo, bar and admin`, User A is signed-in into application and token is persisted, later another User B with role `admin`, decided to restrict role `admin` for User A, so User A won't lose it's privileges until session is expired or logout, because token is persisted with `roles` and `authenticated=true` and roles are not compared. Ref. to the previous attempt: #27121 Commits ------- 4f4c30d - updated AbstractToken to compare Roles - Updated isEqualTo method to match roles as default User implements EquatableInterface - added test case - bumped symfony/security-core to 4.4
@oleg-andreyev We are doing something similar in our User entity: namespace App\Entity;
use Symfony\Component\Security\Core\User\EquatableInterface;
class User implements EquatableInterface
{
public function isEqualTo(UserInterface $user)
{
$isEqual = count($this->getRoles()) === count($user->getRoles());
if ($isEqual) {
foreach ($this->getRoles() as $role) {
$isEqual = $isEqual && in_array($role, $user->getRoles());
}
}
return $isEqual;
}
} Does that mean we can remove |
@XWB yes, results will be the same. |
@oleg-andreyev Thank you. |
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Security] Fixed AbstractToken::hasUserChanged() | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #36989 | License | MIT | Doc PR | - This PR completely reverts #35944. That PR tried to fix a BC break (ref #35941, #35509) introduced by #31177. However, this broke many authentications (ref #36989), as the User is serialized in the session (as hinted by @stof). Many applications don't include the `roles` property in the serialization (at least, the MakerBundle doesn't include it). In 5.2, we should probably deprecate having different roles in token and user, which fixes the BC breaks all together. Commits ------- f297beb [Security] Fixed AbstractToken::hasUserChanged()
Case 1:
User A has roles
foo, bar and admin
, User A is signed-in into application and token is persisted, later another User B with roleadmin
, decided to restrict roleadmin
for User A, so User A won't lose it's privileges until session is expired or logout, because token is persisted withroles
andauthenticated=true
and roles are not compared.Ref. to the previous attempt: #27121