8000 minor #9726 Improved the multiple user providers article (javiereguiluz) · symfony/symfony-docs@fb6e275 · GitHub
[go: up one dir, main page]

Skip to content

Commit fb6e275

Browse files
committed
minor #9726 Improved the multiple user providers article (javiereguiluz)
This PR was squashed before being merged into the 2.7 branch (closes #9726). Discussion ---------- Improved the multiple user providers article This tries to solve both #8582 and #8611. Please @xabbuh, @chalasr and @ogizanagi tell me if I did what you expected according to your comments in the related issues. Thanks! Commits ------- e0f483b Improved the multiple user providers article
2 parents 13ae5bd + e0f483b commit fb6e275

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

security/multiple_user_providers.rst

Lines 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