@@ -25,15 +25,24 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
25
25
.. code-block :: xml
26
26
27
27
<!-- 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
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
32
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
33
+ http://symfony.com/schema/dic/services/services-1.0.xsd" >
34
+
35
+ <config >
36
+ <firewall >
37
+ <!-- lifetime: 604800 seconds = 1 week -->
38
+ <remember-me
39
+ key =" %secret%"
40
+ lifetime =" 604800"
41
+ path =" /"
42
+ />
43
+ </firewall >
44
+ </config >
45
+ </srv : container >
37
46
38
47
.. code-block :: php
39
48
@@ -52,7 +61,7 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
52
61
53
62
The ``remember_me `` firewall defines the following configuration options:
54
63
55
- ``key `` (default value: `` null `` )
64
+ ``key `` (** required ** )
56
65
The value used to encrypt the cookie's content. It's common to use the
57
66
``secret `` value defined in the ``app/config/parameters.yml `` file.
58
67
@@ -167,15 +176,18 @@ The Security component provides an easy way to do this. In addition to roles
167
176
explicitly assigned to them, users are automatically given one of the following
168
177
roles depending on how they are authenticated:
169
178
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.
179
+ ``IS_AUTHENTICATED_ANONYMOUSLY ``
180
+ Automatically assigned to a user who is in a firewall protected part of the
181
+ site but who has not actually logged in. This is only possible if anonymous
182
+ access has been allowed.
173
183
174
- * ``IS_AUTHENTICATED_REMEMBERED `` - automatically assigned to a user who
175
- was authenticated via a remember me cookie.
184
+ ``IS_AUTHENTICATED_REMEMBERED ``
185
+ Automatically assigned to a user who was authenticated via a remember me
186
+ cookie.
176
187
177
- * ``IS_AUTHENTICATED_FULLY `` - automatically assigned to a user that has
178
- provided their login details during the current session.
188
+ ``IS_AUTHENTICATED_FULLY ``
189
+ Automatically assigned to a user that has provided their login details
190
+ during the current session.
179
191
180
192
You can use these to control access beyond the explicitly assigned roles.
181
193
@@ -201,23 +213,25 @@ In the following example, the action is only allowed if the user has the
201
213
// ...
202
214
use Symfony\Component\Security\Core\Exception\AccessDeniedException
203
215
216
+ // ...
204
217
public function editAction()
205
218
{
206
- if (false === $this->get('security.context')->isGranted(
207
- 'IS_AUTHENTICATED_FULLY'
208
- )) {
219
+ $isFullyAuthenticated = $this->get('security.context')
220
+ ->isGranted('IS_AUTHENTICATED_FULLY');
221
+
222
+ if (!$isFullyAuthenticated) {
209
223
throw new AccessDeniedException();
210
224
}
211
225
212
226
// ...
213
227
}
214
228
215
229
You can also choose to install and use the optional JMSSecurityExtraBundle _,
216
- which can secure your controller using annotations:
217
-
218
- .. code-block :: php
230
+ which can secure your controller using annotations::
219
231
232
+ // ...
220
233
use JMS\SecurityExtraBundle\Annotation\Secure;
234
+ // ...
221
235
222
236
/**
223
237
* @Secure(roles="IS_AUTHENTICATED_FULLY")
0 commit comments