Skip to content

Commit 0cddf68

Browse files
committed
[#4606] Tweaks thanks entirely to stof
1 parent 97eb82a commit 0cddf68

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

Diff for: book/security.rst

+35-35
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,11 @@ before inserting them into the database? Don't worry, see
290290

291291
.. tip::
292292

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.
295298

296299
D) Configuration Done!
297300
~~~~~~~~~~~~~~~~~~~~~~
@@ -320,17 +323,20 @@ Great! Now, you need to learn how to deny access and work with the User object.
320323
This is called **authorization**, and its job is to decide if a user can
321324
access some resource (a URL, a model object, a method call, ...).
322325

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-
329326
The process of authorization has two different sides:
330327

331328
#. The user receives a specific set of roles when logging in (e.g. ``ROLE_ADMIN``).
332329
#. 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`.
334340

335341
.. _book-security-roles:
336342

@@ -344,9 +350,11 @@ in your table.
344350

345351
.. caution::
346352

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).
350358

351359
Roles are simple, and are basically strings that you invent and use as needed.
352360
For example, if you need to start limiting access to the blog admin section
@@ -363,6 +371,8 @@ it.
363371
You can also specify a :ref:`role hierarchy <security-role-hierarchy>` where
364372
some roles automatically mean that you also have other roles.
365373

374+
.. _security-role-authorization:
375+
366376
Add Code to Deny Access
367377
~~~~~~~~~~~~~~~~~~~~~~~
368378

@@ -486,24 +496,6 @@ That's it! If the user isn't logged in yet, they will be asked to login (e.g.
486496
redirected to the login page). If they *are* logged in, they'll be shown
487497
the 403 access denied page (which you can :ref:`customize <cookbook-error-pages-by-status-code>`).
488498

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-
507499
.. _book-security-template:
508500

509501
Access Control in Templates
@@ -575,16 +567,24 @@ user is logged in (you don't care about roles), then you can see ``IS_AUTHENTICA
575567
You can of course also use this in ``access_control``.
576568

577569
``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
579571
special attributes like this:
580572

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+
584582
* ``IS_AUTHENTICATED_ANONYMOUSLY``: *All* users (even anonymous ones) have
585583
this - this is useful when *whitelisting* URLs to guarantee access - some
586584
details are in :doc:`/cookbook/security/access_control`.
587585

586+
.. _security-secure-objects:
587+
588588
Access Control Lists (ACLs): Securing individual Database Objects
589589
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
590590

@@ -667,7 +667,7 @@ the User object, and use the ``isGranted`` method (or
667667
668668
}
669669

670-
Retreiving the User in a Template
670+
Retrieving the User in a Template
671671
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
672672

673673
In a Twig Template this object can be accessed via the `app.user <reference-twig-global-app>`_

0 commit comments

Comments
 (0)