-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
#494 Implements Serializable interface in the User entity #495
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
As discussed in #494, implements Serializable interface in the User entity
Minor typo fixes to comply with .php_cs rules
Remove forgotten parenthesis
return serialize([ | ||
$this->id, | ||
$this->username, | ||
$this->password, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is adding the password here a recommended practice (from the security point of view)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the example from the documentation http://symfony.com/doc/current/security/entity_provider.html#create-your-user-entity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, the Serializable interface and its serialize() and unserialize() methods have been added to allow the User class to be serialized to the session. This may or may not be needed depending on your setup, but it's probably a good idea. In theory, only the id needs to be serialized, because the refreshUser() method refreshes the user on each request by using the id (as explained above). This gives us a "fresh" User object.
But Symfony also uses the username, salt, and password to verify that the User has not changed between requests (it also calls your AdvancedUserInterface methods if you implement it). Failing to serialize these may cause you to be logged out on each request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explanation is not very good 😕 Saying "maybe you need this ... maybe you don't" without explaining anything else doesn't look good. And then, saying "you can serialize just "id" if you want ... but maybe it doesn't work because Symfony wants more" is also confusing.
As usual, this is caused by the massive internal complexity of the security component ... so I don't know what can we do about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to agree with you, it's quite unclear. I don't know what to do either maybe someone could enlight us on this particular topic ?
@javiereguiluz What about this PR ? |
@apetitpa I've finally merged this because it's exactly the same as the Symfony Docs, so let's apply our own best practices here. Thanks! |
As discussed in #494, implements the
Serializable
interface in theUser
entity.