[POC][Security] Split tokens in request token + authentication token (towards making tokens first-class citizens) #21068
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Started a long time ago with this branch, so I thought it was time to create a POC PR to get the opinion of core teammembers and contributors on this topic.
The Story: Removing
UserInterface
The Security system currently manages users with 2 types of classes:
UserInterface
andTokenInterface
. The devs using Symfony most of the time end up usingUserInterface
as their user object in the application. This has some drawbacks:getPassword()
,getSalt()
, etc.) ([Security] getUsername in UserInterface is confusing #10316)Probably more than a year back, @iltar, @weaverryan and me had a discussion about this on IRC. A nice idea was born there:
Token
the first-class citizen of the Security system. All information that the security system needs to know about the user should be saved in the token.Token
will be serialized in the sessiongetUser()
method andapp.user
var. This user object should have agetIdentifier()
method, returning an identifier for the user which is saved in the serialized token.This Pull Request
In order to store all security information in a token, the token needs to be split into 2 seperate tokens: Authentication request tokens and Authenticated tokens. The authentication request token contains all information before authenticating (such as the username and password passed through the login form). The authenticated token contains the identifier (see previous section) of the logged in user and the roles bound to this token.
Splitting the token also has other major advantages:
__toString()
" thing in the security system is removed. Users are now always an object instance ofUserInterface
in authenticated tokens.The Future
In follow-up pull requests, the rest of the story of removing the
UserInterface
can be done.