Skip to content

Commit 7b34eab

Browse files
committed
improve the serialization of custom user models
1 parent 4c3367f commit 7b34eab

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

cookbook/security/entity_provider.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ focus on the most important methods that come from the
149149
{
150150
return serialize(array(
151151
$this->id,
152+
$this->username,
153+
$this->salt,
154+
$this->password,
152155
));
153156
}
154157
@@ -159,10 +162,20 @@ focus on the most important methods that come from the
159162
{
160163
list (
161164
$this->id,
165+
$this->username,
166+
$this->salt,
167+
$this->password,
162168
) = unserialize($serialized);
163169
}
164170
}
165171
172+
.. note::
173+
174+
When implementing the
175+
:class:`Symfony\\Component\\Security\\Core\\User\\EquatableInterface`,
176+
you determine yourself which properties need to be compared to distinguish
177+
your user objects.
178+
166179
.. tip::
167180

168181
:ref:`Generate the database table <book-doctrine-creating-the-database-tables-schema>`
@@ -219,7 +232,7 @@ layer is a piece of cake. Everything resides in the configuration of the
219232
:doc:`SecurityBundle </reference/configuration/security>` stored in the
220233
``app/config/security.yml`` file.
221234
222-
Below is an example of configuration where the user will enter their
235+
Below is an example of configuration where the user will enter their
223236
username and password via HTTP basic authentication. That information will
224237
then be checked against your User entity records in the database:
225238
@@ -358,7 +371,7 @@ For this example, the first three methods will return ``true`` whereas the
358371
use Doctrine\ORM\Mapping as ORM;
359372
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
360373
361-
class User implements AdvancedUserInterface, \Serializable
374+
class User implements AdvancedUserInterface, \Serializable
362375
{
363376
// ...
364377
@@ -386,7 +399,7 @@ For this example, the first three methods will return ``true`` whereas the
386399
Now, if you try to authenticate as a user who's ``is_active`` database field
387400
is set to 0, you won't be allowed.
388401
389-
The next session will focus on how to write a custom entity provider
402+
The next session will focus on how to write a custom entity provider
390403
to authenticate a user with their username or email address.
391404
392405
Authenticating Someone with a Custom Entity Provider
@@ -552,7 +565,7 @@ methods have changed::
552565
class User implements AdvancedUserInterface, \Serializable
553566
{
554567
// ...
555-
568+
556569
/**
557570
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
558571
*
@@ -568,7 +581,7 @@ methods have changed::
568581
{
569582
return $this->roles->toArray();
570583
}
571-
584+
572585
// ...
573586
574587
}
@@ -625,7 +638,7 @@ of the application::
625638
{
626639
return $this->role;
627640
}
628-
641+
629642
// ... getters and setters for each property
630643
}
631644

0 commit comments

Comments
 (0)