Skip to content

Update the multiple user providers article #8612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions security/multiple_user_providers.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
How to Use multiple User Providers
==================================

Each authentication mechanism (e.g. HTTP Authentication, form login, etc)
uses exactly one user provider, and will use the first declared user provider
by default. But what if you want to specify a few users via configuration
and the rest of your users in the database? This is possible by creating
a new provider that chains the two together:
Each authentication mechanism (e.g. HTTP Authentication, form login, etc.) uses
exactly one user provider. But what if you want to specify a few users via
configuration and the rest of your users in the database? This is possible by
creating a new provider that chains the two together:

.. configuration-block::

Expand Down Expand Up @@ -82,20 +81,12 @@ a new provider that chains the two together:
),
));

Now, all firewalls that explicitly define ``chain_provider`` as their user
provider will, in turn, try to load the user from both the ``in_memory`` and
``user_db`` providers.

.. versionadded:: 3.4
In previous Symfony versions, firewalls that didn't define their user provider
explicitly, used the first existing provider (``chain_provider`` in this
example). However, auto-selecting the first user provider has been deprecated
in Symfony 3.4 and will throw an exception in 4.0. Always define the provider
used by the firewall when there are multiple providers.
Now, all firewalls that define ``chain_provider`` as their user provider will,
in turn, try to load the user from both the ``in_memory`` and ``user_db``
providers.

You can also configure the firewall or individual authentication mechanisms
to use a specific provider. Again, unless a provider is specified explicitly,
the first provider is always used:
to use a specific provider:

.. configuration-block::

Expand Down Expand Up @@ -151,10 +142,10 @@ the first provider is always used:
),
));

In this example, if a user tries to log in via HTTP authentication, the authentication
system will use the ``in_memory`` user provider. But if the user tries to
log in via the form login, the ``user_db`` provider will be used (since it's
the default for the firewall as a whole).
In this example, if a user tries to log in via HTTP authentication, the
authentication system will use the ``in_memory`` user provider. But if the user
tries to log in via the form login, the ``user_db`` provider will be used (since
it's the default for the firewall as a whole).

For more information about user provider and firewall configuration, see
the :doc:`/reference/configuration/security`.