Skip to content

Commit 442385f

Browse files
committed
Document BC Break introduced in commit 741859dc
1 parent de00067 commit 442385f

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

book/security.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,13 @@ custom user class is that it implements the :class:`Symfony\\Component\\Security
10011001
interface. This means that your concept of a "user" can be anything, as long
10021002
as it implements this interface.
10031003

1004+
.. versionadded:: 2.1
1005+
1006+
In Symfony 2.1 the ``Symfony\\Component\\Security\\Core\\User\\EquatableInterface``
1007+
was introduced, it contains single method ``isEqualTo(UserInterface $user)``.
1008+
You can implement this interface if you need to override default implementation
1009+
of comparsion logic in authentication mechanism.
1010+
10041011
.. note::
10051012

10061013
The user object will be serialized and saved in the session during requests,

cookbook/security/entity_provider.rst

+27-12
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@ To make it shorter, the getter and setter methods for each have been removed to
4040
focus on the most important methods that come from the
4141
:class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`.
4242

43+
.. versionadded:: 2.1
44+
45+
In Symfony 2.1 the ``Symfony\\Component\\Security\\Core\\User\\EquatableInterface``
46+
was introduced, it contains single method ``isEqualTo(UserInterface $user)``.
47+
You can implement this interface if you need to override default implementation
48+
of comparsion logic in authentication mechanism.
49+
4350
.. code-block:: php
4451
4552
// src/Acme/UserBundle/Entity/User.php
4653
4754
namespace Acme\UserBundle\Entity;
4855
4956
use Symfony\Component\Security\Core\User\UserInterface;
57+
use Symfony\Component\Security\Core\User\EquatableInterface;
5058
use Doctrine\ORM\Mapping as ORM;
5159
5260
/**
@@ -100,11 +108,6 @@ focus on the most important methods that come from the
100108
return array('ROLE_USER');
101109
}
102110
103-
public function equals(UserInterface $user)
104-
{
105-
return $user->getUsername() === $this->username;
106-
}
107-
108111
public function eraseCredentials()
109112
{
110113
}
@@ -123,18 +126,30 @@ focus on the most important methods that come from the
123126
{
124127
return $this->password;
125128
}
129+
130+
/**
131+
* EquatableInterface
132+
*/
133+
public function isEqualTo(UserInterface $user)
134+
{
135+
return $user->getUsername() === $this->username;
136+
}
126137
}
127138
128139
In order to use an instance of the ``AcmeUserBundle:User`` class in the Symfony
129140
security layer, the entity class must implement the
130141
:class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`. This
131-
interface forces the class to implement the six following methods: ``getRoles()``,
132-
``getPassword()``, ``getSalt()``, ``getUsername()``, ``eraseCredentials()``,
133-
``equals()``. For more details on each of these, see :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`.
134-
135-
To keep it simple, the ``equals()`` method just compares the ``username`` field
136-
but it's also possible to do more checks depending on the complexity of your
137-
data model. On the other hand, the ``eraseCredentials()`` method remains empty
142+
interface forces the class to implement the five following methods: ``getRoles()``,
143+
``getPassword()``, ``getSalt()``, ``getUsername()``, ``eraseCredentials()``.
144+
For more details on each of these, see :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`.
145+
146+
To keep it simple, the ``isEqualTo()`` method form ``EquatableInterface``
147+
just compares the ``username`` field but it's also possible to do more checks
148+
depending on the complexity of your data model, also in most cases, implementing
149+
``EquatableInterface`` is not nessesery, because security component has good default
150+
implementation, see the ``hasUserChanged()`` method of
151+
:class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\AbstractToken`.
152+
On the other hand, the ``eraseCredentials()`` method remains empty
138153
as we don't care about it in this tutorial.
139154

140155
Below is an export of my ``User`` table from MySQL. For details on how to

0 commit comments

Comments
 (0)