@@ -290,8 +290,11 @@ before inserting them into the database? Don't worry, see
290
290
291
291
.. tip ::
292
292
293
- Supported algorithms for this method depend on your PHP version. A full list
294
- is available by calling the PHP function :phpfunction: `hash_algos `.
293
+ Supported algorithms for this method depend on your PHP version, but
294
+ include the algorithms returned by the PHP function :phpfunction: `hash_algos `
295
+ as well as a few others (e.g. bcrypt). See the ``encoders `` key in the
296
+ :doc: `Security Reference Section </reference/configuration/security >`
297
+ for examples.
295
298
296
299
D) Configuration Done!
297
300
~~~~~~~~~~~~~~~~~~~~~~
@@ -320,17 +323,20 @@ Great! Now, you need to learn how to deny access and work with the User object.
320
323
This is called **authorization **, and its job is to decide if a user can
321
324
access some resource (a URL, a model object, a method call, ...).
322
325
323
- .. note ::
324
-
325
- The authorization system is flexible, and can even support complex ACL's
326
- where you determine, for example, if user A can "EDIT" some object B
327
- (e.g. a Product). For details, see :doc: `/cookbook/security/voters_data_permission `.
328
-
329
326
The process of authorization has two different sides:
330
327
331
328
#. The user receives a specific set of roles when logging in (e.g. ``ROLE_ADMIN ``).
332
329
#. You add code so that a resource (e.g. URL, controller) requires a specific
333
- role in order to be accessed.
330
+ "attribute" (most commonly a role like ``ROLE_ADMIN ``) in order to be
331
+ accessed.
332
+
333
+ .. tip ::
334
+
335
+ In addition to roles (e.g. ``ROLE_ADMIN ``), you can protect a resource
336
+ using other attributes/strings (e.g. ``EDIT ``) and use voters or Symfony's
337
+ ACL system to give these meaning. This might come in handy if you need
338
+ to check if user A can "EDIT" some object B (e.g. a Product with id 5).
339
+ See :ref: `security-secure-objects `.
334
340
335
341
.. _book-security-roles :
336
342
@@ -344,9 +350,11 @@ in your table.
344
350
345
351
.. caution ::
346
352
347
- All roles **must ** begin with the ``ROLE_ `` prefix. Otherwise, they won't
348
- be handled by Symfony. If you define your own roles with a dedicated
349
- ``Role `` class (more advanced), don't use the ``ROLE_ `` prefix.
353
+ All roles you assign to a user **must ** begin with the ``ROLE_ `` prefix.
354
+ Otherwise, they won't be handled by Symfony's security system in the
355
+ normal way (i.e. unless you're doing something advanced, assigning a
356
+ role like ``FOO `` to a user and then checking for ``FOO `` as described
357
+ :ref: `below <security-role-authorization >` will not work).
350
358
351
359
Roles are simple, and are basically strings that you invent and use as needed.
352
360
For example, if you need to start limiting access to the blog admin section
363
371
You can also specify a :ref: `role hierarchy <security-role-hierarchy >` where
364
372
some roles automatically mean that you also have other roles.
365
373
374
+ .. _security-role-authorization :
375
+
366
376
Add Code to Deny Access
367
377
~~~~~~~~~~~~~~~~~~~~~~~
368
378
@@ -486,24 +496,6 @@ That's it! If the user isn't logged in yet, they will be asked to login (e.g.
486
496
redirected to the login page). If they *are * logged in, they'll be shown
487
497
the 403 access denied page (which you can :ref: `customize <cookbook-error-pages-by-status-code >`).
488
498
489
- .. _book-security-securing-controller-annotations :
490
-
491
- Thanks to the SensioFrameworkExtraBundle, you can also secure your controller
492
- using annotations::
493
-
494
- // ...
495
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
496
-
497
- /**
498
- * @Security("has_role('ROLE_ADMIN')")
499
- */
500
- public function helloAction($name)
501
- {
502
- // ...
503
- }
504
-
505
- For more information, see the `FrameworkExtraBundle documentation `_.
506
-
507
499
.. _book-security-template :
508
500
509
501
Access Control in Templates
@@ -575,16 +567,24 @@ user is logged in (you don't care about roles), then you can see ``IS_AUTHENTICA
575
567
You can of course also use this in ``access_control ``.
576
568
577
569
``IS_AUTHENTICATED_FULLY `` isn't a role, but it kind of acts like one, and every
578
- user that has successfull logged in will have this. In fact, there are thre
570
+ user that has successfully logged in will have this. In fact, there are three
579
571
special attributes like this:
580
572
581
- * ``IS_AUTHENTICATED_FULLY ``: All "logged-in" users have this;
582
- * ``IS_AUTHENTICATED_REMEMBERED ``: Similar to ``IS_AUTHENTICATED_FULLY ``
583
- but important if you're using :doc: `remember me functionality </cookbook/security/remember_me >`;
573
+ * ``IS_AUTHENTICATED_REMEMBERED ``: *All * logged in users have this, even
574
+ if they are logged in because of a "remember me cookie". Even if you don't
575
+ use the :doc: `remember me functionality </cookbook/security/remember_me >`,
576
+ you can use this to check if the user is logged in.
577
+
578
+ * ``IS_AUTHENTICATED_FULLY ``: This is similar to ``IS_AUTHENTICATED_REMEMBERED ``,
579
+ but stronger. Users who are logged in only because of a "remember me cookie"
580
+ will have ``IS_AUTHENTICATED_REMEMBERED `` but will not have ``IS_AUTHENTICATED_FULLY ``.
581
+
584
582
* ``IS_AUTHENTICATED_ANONYMOUSLY ``: *All * users (even anonymous ones) have
585
583
this - this is useful when *whitelisting * URLs to guarantee access - some
586
584
details are in :doc: `/cookbook/security/access_control `.
587
585
586
+ .. _security-secure-objects :
587
+
588
588
Access Control Lists (ACLs): Securing individual Database Objects
589
589
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
590
590
@@ -667,7 +667,7 @@ the User object, and use the ``isGranted`` method (or
667
667
668
668
}
669
669
670
- Retreiving the User in a Template
670
+ Retrieving the User in a Template
671
671
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
672
672
673
673
In a Twig Template this object can be accessed via the `app.user <reference-twig-global-app >`_
0 commit comments