diff --git a/security/experimental_authenticators.rst b/security/experimental_authenticators.rst index cdcb40b8541..321b845579a 100644 --- a/security/experimental_authenticators.rst +++ b/security/experimental_authenticators.rst @@ -56,10 +56,80 @@ The authenticator-based system can be enabled using the The new system is backwards compatible with the current authentication system, with some exceptions that will be explained in this article: +* :ref:`Access control must be used to enforce authentication ` * :ref:`Anonymous users no longer exist ` * :ref:`Configuring the authentication entry point is required when more than one authenticator is used ` * :ref:`The authentication providers are refactored into Authenticators ` +.. _authenticators-access-control: + +Use Access Control to Require Authentication +-------------------------------------------- + +Previously, if the firewall wasn't configured with ``anonymous`` support, +it automatically required users to authenticate. As the new firewall +always supports unauthenticated requests (:ref:`authenticators-removed-anonymous`), +you **must** define ``access_control`` rules to enforce authentication. +Without this, unauthenticated users can visit pages behind the firewall. + +If the application doesn't use roles, you can check for +``IS_AUTHENTICATED_REMEMBERED`` to require authentication (both normal and +remembered): + +.. configuration-block:: + + .. code-block:: yaml + + # config/packages/security.yaml + security: + enable_authenticator_manager: true + + # ... + access_control: + # require authentication for all routes under /admin + - { path: ^/admin, roles: IS_AUTHENTICATED_REMEMBERED } + + .. code-block:: xml + + + + + + + + + + + + + + + + .. code-block:: php + + // config/packages/security.php + use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter; + + $container->loadFromExtension('security', [ + 'enable_authenticator_manager' => true, + + // ... + 'access_control' => [ + // require authentication for all routes under /admin + ['path' => '^/admin', 'roles' => 'IS_AUTHENTICATED_REMEMBERED'] + ], + ]); + +.. tip:: + + If you're using Symfony 5.4 or newer, use ``IS_AUTHENTICATED`` instead. + .. _authenticators-removed-anonymous: Adding Support for Unsecured Access (i.e. Anonymous Users)