Skip to content

Commit 434a1de

Browse files
committed
fixed explanations about anonymous users and their authenticated status
1 parent 26a5156 commit 434a1de

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

guides/security/authentication.rst

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,10 @@ Anonymous Users
513513
~~~~~~~~~~~~~~~
514514

515515
When you disable security, no user is attached to the request anymore. If you
516-
still want one, you can activate anonymous users. An anonymous user is not
517-
authenticated and "real" authentication occurs whenever the user wants to
518-
access a resource restricted by an access control rule:
516+
still want one, you can activate anonymous users. An anonymous user is
517+
authenticated but only has the ``IS_AUTHENTICATED_ANONYMOUSLY`` role. The
518+
"real" authentication only occurs whenever the user accesses a resource
519+
restricted by a more restrictive access control rule:
519520

520521
.. configuration-block::
521522

@@ -545,15 +546,10 @@ access a resource restricted by an access control rule:
545546
),
546547
));
547548
548-
You can check if a user is fully-authenticated with the ``isAuthenticated()``
549-
of the security context:
550-
551-
$container->get('security.context')->isAuthenticated();
552-
553-
.. tip::
554-
555-
All anonymous users automatically have the 'IS_AUTHENTICATED_ANONYMOUSLY'
556-
role.
549+
As anonymous users are authenticated, the ``isAuthenticated()`` method returns
550+
``true``. To check is the user is anonymous, check for the
551+
``IS_AUTHENTICATED_ANONYMOUSLY`` role instead (note that all non-anonymous
552+
users have the ``IS_AUTHENTICATED_FULLY`` role.)
557553

558554
.. index::
559555
single: Security; Stateless Authentication

guides/security/authorization.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ user has not the needed roles or an
5656
:class:`Symfony\\Component\Security\\Exception\\AuthenticationCredentialsNotFoundException`
5757
if he is not authenticated yet.
5858

59-
.. tip::
60-
61-
``IS_AUTHENTICATED_ANONYMOUSLY`` is a special role that all anonymous
62-
users have.
63-
6459
In the example above, we match requests based on their path info, but there
6560
are many other ways as you will learn in the next section.
6661

62+
..tip::
63+
64+
Symfony2 automatically adds a special role based on the anonymous flag:
65+
``IS_AUTHENTICATED_ANONYMOUSLY`` for anonymous users and
66+
``IS_AUTHENTICATED_FULLY`` for all others.
67+
6768
Matching a Request
6869
------------------
6970

guides/security/users.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,16 @@ After authentication, the user is accessed via the security context::
396396
$user = $container->get('security.context')->getUser();
397397

398398
You can also check if the user is authenticated with the ``isAuthenticated()``
399-
method.
399+
method::
400+
401+
$container->get('security.context')->isAuthenticated();
402+
403+
.. tip::
404+
405+
Be aware that anonymous users are considered authenticated. If you want to
406+
check if a user is "fully authenticated" (non-anonymous), you need to
407+
check if the user has the special ``IS_AUTHENTICATED_FULLY`` role (or
408+
check that the user has not the ``IS_AUTHENTICATED_ANONYMOUSLY`` role).
400409

401410
.. index::
402411
single: Security; Roles

0 commit comments

Comments
 (0)