@@ -25,15 +25,21 @@ 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
+
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 >
37
43
38
44
.. code-block :: php
39
45
@@ -52,7 +58,7 @@ the session lasts using a cookie with the ``remember_me`` firewall option:
52
58
53
59
The ``remember_me `` firewall defines the following configuration options:
54
60
55
- ``key `` (default value: `` null `` )
61
+ ``key `` (** required ** )
56
62
The value used to encrypt the cookie's content. It's common to use the
57
63
``secret `` value defined in the ``app/config/parameters.yml `` file.
58
64
@@ -167,15 +173,18 @@ The Security component provides an easy way to do this. In addition to roles
167
173
explicitly assigned to them, users are automatically given one of the following
168
174
roles depending on how they are authenticated:
169
175
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.
173
180
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.
176
184
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.
179
188
180
189
You can use these to control access beyond the explicitly assigned roles.
181
190
@@ -201,23 +210,25 @@ In the following example, the action is only allowed if the user has the
201
210
// ...
202
211
use Symfony\Component\Security\Core\Exception\AccessDeniedException
203
212
213
+ // ...
204
214
public function editAction()
205
215
{
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) {
209
220
throw new AccessDeniedException();
210
221
}
211
222
212
223
// ...
213
224
}
214
225
215
226
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::
219
228
229
+ // ...
220
230
use JMS\SecurityExtraBundle\Annotation\Secure;
231
+ // ...
221
232
222
233
/**
223
234
* @Secure(roles="IS_AUTHENTICATED_FULLY")
0 commit comments