Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e0f483b

Browse filesBrowse files
committed
Improved the multiple user providers article
1 parent 326419c commit e0f483b
Copy full SHA for e0f483b

File tree

1 file changed

+26
-0
lines changed
Filter options

1 file changed

+26
-0
lines changed

‎security/multiple_user_providers.rst

Copy file name to clipboardExpand all lines: security/multiple_user_providers.rst
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
How to Use multiple User Providers
22
==================================
33

4+
.. note::
5+
6+
It's always better to use a specific user provider for each authentication
7+
mechanism. Chaining user providers should be avoided in most applications
8+
and used only to solve edge cases.
9+
410
Each authentication mechanism (e.g. HTTP Authentication, form login, etc)
511
uses exactly one user provider, and will use the first declared user provider
612
by default. But what if you want to specify a few users via configuration
@@ -150,5 +156,25 @@ system will use the ``in_memory`` user provider. But if the user tries to
150156
log in via the form login, the ``user_db`` provider will be used (since it's
151157
the default for the firewall as a whole).
152158

159+
If you need to check that the user being returned by your provider is a allowed
160+
to authenticate, check the returned user object::
161+
162+
use Symfony\Component\Security\Core\User;
163+
// ...
164+
165+
public function loadUserByUsername($username)
166+
{
167+
// ...
168+
169+
// you can, for example, test that the returned user is an object of a
170+
// particular class or check for certain attributes of your user objects
171+
if ($user instance User) {
172+
// the user was loaded from the main security config file. Do something.
173+
// ...
174+
}
175+
176+
return $user;
177+
}
178+
153179
For more information about user provider and firewall configuration, see
154180
the :doc:`/reference/configuration/security`.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.