Skip to content

Commit 8158d56

Browse files
committed
Quick review of the remember me article
1 parent 31e613a commit 8158d56

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

cookbook/security/remember_me.rst

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
2525
.. code-block:: xml
2626
2727
<!-- app/config/security.xml -->
28-
<config>
29-
<firewall>
30-
<remember-me
31-
key = "%secret%"
32-
lifetime = "604800" <!-- 1 week in seconds -->
33-
path = "/"
34-
/>
35-
</firewall>
36-
</config>
28+
<?xml version="1.0" encoding="utf-8" ?>
29+
<srv:container xmlns="http://symfony.com/schema/dic/security"
30+
xmlns:srv="http://symfony.com/schema/dic/services">
31+
32+
<config>
33+
<firewall>
34+
<!-- lifetime: 604800 seconds = 1 week -->
35+
<remember-me
36+
key="%secret%"
37+
lifetime="604800"
38+
path="/"
39+
/>
40+
</firewall>
41+
</config>
42+
</srv:container>
3743
3844
.. code-block:: php
3945
@@ -52,7 +58,7 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
5258
5359
The ``remember_me`` firewall defines the following configuration options:
5460

55-
``key`` (default value: ``null``)
61+
``key`` (**required**)
5662
The value used to encrypt the cookie's content. It's common to use the
5763
``secret`` value defined in the ``app/config/parameters.yml`` file.
5864

@@ -167,15 +173,18 @@ The Security component provides an easy way to do this. In addition to roles
167173
explicitly assigned to them, users are automatically given one of the following
168174
roles depending on how they are authenticated:
169175

170-
* ``IS_AUTHENTICATED_ANONYMOUSLY`` - automatically assigned to a user who is
171-
in a firewall protected part of the site but who has not actually logged in.
172-
This is only possible if anonymous access has been allowed.
176+
``IS_AUTHENTICATED_ANONYMOUSLY``
177+
Automatically assigned to a user who is in a firewall protected part of the
178+
site but who has not actually logged in. This is only possible if anonymous
179+
access has been allowed.
173180

174-
* ``IS_AUTHENTICATED_REMEMBERED`` - automatically assigned to a user who
175-
was authenticated via a remember me cookie.
181+
``IS_AUTHENTICATED_REMEMBERED``
182+
Automatically assigned to a user who was authenticated via a remember me
183+
cookie.
176184

177-
* ``IS_AUTHENTICATED_FULLY`` - automatically assigned to a user that has
178-
provided their login details during the current session.
185+
``IS_AUTHENTICATED_FULLY``
186+
Automatically assigned to a user that has provided their login details
187+
during the current session.
179188

180189
You can use these to control access beyond the explicitly assigned roles.
181190

@@ -201,23 +210,25 @@ In the following example, the action is only allowed if the user has the
201210
// ...
202211
use Symfony\Component\Security\Core\Exception\AccessDeniedException
203212
213+
// ...
204214
public function editAction()
205215
{
206-
if (false === $this->get('security.context')->isGranted(
207-
'IS_AUTHENTICATED_FULLY'
208-
)) {
216+
$isFullyAuthenticated = $this->get('security.context')
217+
->isGranted('IS_AUTHENTICATED_FULLY');
218+
219+
if (!$isFullyAuthenticated) {
209220
throw new AccessDeniedException();
210221
}
211222
212223
// ...
213224
}
214225
215226
You can also choose to install and use the optional JMSSecurityExtraBundle_,
216-
which can secure your controller using annotations:
217-
218-
.. code-block:: php
227+
which can secure your controller using annotations::
219228

229+
// ...
220230
use JMS\SecurityExtraBundle\Annotation\Secure;
231+
// ...
221232

222233
/**
223234
* @Secure(roles="IS_AUTHENTICATED_FULLY")

0 commit comments

Comments
 (0)