Skip to content

Improved the multiple user providers article #9726

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

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 26 additions & 0 deletions security/multiple_user_providers.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
How to Use multiple User Providers
==================================

.. note::

It's always better to use a specific user provider for each authentication
mechanism. Chaining user providers should be avoided in most applications
and used only to solve edge cases.

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
Expand Down Expand Up @@ -150,5 +156,25 @@ 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).

If you need to check that the user being returned by your provider is a allowed
to authenticate, check the returned user object::

use Symfony\Component\Security\Core\User;
// ...

public function loadUserByUsername($username)
{
// ...

// you can, for example, test that the returned user is an object of a
// particular class or check for certain attributes of your user objects
if ($user instance User) {
// the user was loaded from the main security config file. Do something.
// ...
}

return $user;
}

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