@@ -56,10 +56,80 @@ The authenticator-based system can be enabled using the
5656 The new system is backwards compatible with the current authentication
5757system, with some exceptions that will be explained in this article:
5858
59+ * :ref: `Access control must be used to enforce authentication <authenticators-access-control >`
5960* :ref: `Anonymous users no longer exist <authenticators-removed-anonymous >`
6061* :ref: `Configuring the authentication entry point is required when more than one authenticator is used <authenticators-required-entry-point >`
6162* :ref: `The authentication providers are refactored into Authenticators <authenticators-removed-authentication-providers >`
6263
64+ .. _authenticators-access-control :
65+
66+ Use Access Control to Require Authentication
67+ --------------------------------------------
68+
69+ Previously, if the firewall wasn't configured with ``anonymous `` support,
70+ it automatically required users to authenticate. As the new firewall
71+ always supports unauthenticated requests (:ref: `authenticators-removed-anonymous `),
72+ you **must ** define ``access_control `` rules to enforce authentication.
73+ Without this, unauthenticated users can visit pages behind the firewall.
74+
75+ If the application doesn't use roles, you can check for
76+ ``IS_AUTHENTICATED_REMEMBERED `` to require authentication (both normal and
77+ remembered):
78+
79+ .. configuration-block ::
80+
81+ .. code-block :: yaml
82+
83+ # config/packages/security.yaml
84+ security :
85+ enable_authenticator_manager : true
86+
87+ # ...
88+ access_control :
89+ # require authentication for all routes under /admin
90+ - { path: ^/admin, roles: IS_AUTHENTICATED_REMEMBERED }
91+
92+ .. code-block :: xml
93+
94+ <!-- config/packages/security.xml -->
95+ <?xml version =" 1.0" encoding =" UTF-8" ?>
96+ <srv : container xmlns =" http://symfony.com/schema/dic/security"
97+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
98+ xmlns : srv =" http://symfony.com/schema/dic/services"
99+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
100+ https://symfony.com/schema/dic/services/services-1.0.xsd
101+ http://symfony.com/schema/dic/security
102+ https://symfony.com/schema/dic/security/security-1.0.xsd" >
103+
104+ <config enable-authenticator-manager =" true" >
105+ <!-- ... -->
106+
107+ <access-control >
108+ <!-- require authentication for all routes under /admin -->
109+ <rule path =" ^/admin" role =" IS_AUTHENTICATED_REMEMBERED" />
110+ </access-control >
111+ </config >
112+ </srv : container >
113+
114+ .. code-block :: php
115+
116+ // config/packages/security.php
117+ use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
118+
119+ $container->loadFromExtension('security', [
120+ 'enable_authenticator_manager' => true,
121+
122+ // ...
123+ 'access_control' => [
124+ // require authentication for all routes under /admin
125+ ['path' => '^/admin', 'roles' => 'IS_AUTHENTICATED_REMEMBERED']
126+ ],
127+ ]);
128+
129+ .. tip ::
130+
131+ If you're using Symfony 5.4 or newer, use ``IS_AUTHENTICATED `` instead.
132+
63133.. _authenticators-removed-anonymous :
64134
65135Adding Support for Unsecured Access (i.e. Anonymous Users)
0 commit comments