@@ -45,7 +45,7 @@ configuration looks like this:
4545 # app/config/security.yml
4646 security :
4747 providers :
48- in_memory :
48+ users_in_memory :
4949 memory : ~
5050
5151 firewalls :
@@ -55,6 +55,7 @@ configuration looks like this:
5555
5656 main :
5757 anonymous : ~
58+ provider : users_in_memory
5859
5960 .. code-block :: xml
6061
@@ -67,7 +68,7 @@ configuration looks like this:
6768 https://symfony.com/schema/dic/services/services-1.0.xsd" >
6869
6970 <config >
70- <provider name =" in_memory " >
71+ <provider name =" users_in_memory " >
7172 <memory />
7273 </provider >
7374
@@ -77,6 +78,7 @@ configuration looks like this:
7778
7879 <firewall name =" main" >
7980 <anonymous />
81+ <provider >users_in_memory</provider >
8082 </firewall >
8183 </config >
8284 </srv : container >
@@ -86,7 +88,7 @@ configuration looks like this:
8688 // app/config/security.php
8789 $container->loadFromExtension('security', [
8890 'providers' => [
89- 'in_memory ' => [
91+ 'users_in_memory ' => [
9092 'memory' => null,
9193 ],
9294 ],
@@ -97,6 +99,7 @@ configuration looks like this:
9799 ],
98100 'main' => [
99101 'anonymous' => null,
102+ 'provider' => 'users_in_memory'
100103 ],
101104 ],
102105 ]);
@@ -315,7 +318,7 @@ provider, but it's better to think of it as an "in configuration" provider:
315318 # app/config/security.yml
316319 security :
317320 providers :
318- in_memory :
321+ users_in_memory :
319322 memory :
320323 users :
321324 ryan :
@@ -324,7 +327,11 @@ provider, but it's better to think of it as an "in configuration" provider:
324327 admin :
325328 password : kitten
326329 roles : ' ROLE_ADMIN'
327- # ...
330+
331+ firewalls :
332+ main :
333+ provider : users_in_memory
334+ # ...
328335
329336 .. code-block :: xml
330337
@@ -337,13 +344,16 @@ provider, but it's better to think of it as an "in configuration" provider:
337344 https://symfony.com/schema/dic/services/services-1.0.xsd" >
338345
339346 <config >
340- <provider name =" in_memory " >
347+ <provider name =" users_in_memory " >
341348 <memory >
342349 <user name =" ryan" password =" ryanpass" roles =" ROLE_USER" />
343350 <user name =" admin" password =" kitten" roles =" ROLE_ADMIN" />
344351 </memory >
345352 </provider >
346- <!-- ... -->
353+ <firewall name =" main" >
354+ <provider >users_in_memory</provider >
355+ <!-- ... -->
356+ </firewall >
347357 </config >
348358 </srv : container >
349359
@@ -352,7 +362,7 @@ provider, but it's better to think of it as an "in configuration" provider:
352362 // app/config/security.php
353363 $container->loadFromExtension('security', [
354364 'providers' => [
355- 'in_memory ' => [
365+ 'users_in_memory ' => [
356366 'memory' => [
357367 'users' => [
358368 'ryan' => [
@@ -367,13 +377,17 @@ provider, but it's better to think of it as an "in configuration" provider:
367377 ],
368378 ],
369379 ],
370- // ...
380+ 'firewalls' => [
381+ 'main' => [
382+ 'provider' => 'users_in_memory',
383+ ],
384+ ],
371385 ]);
372386
373387 Like with ``firewalls ``, you can have multiple ``providers ``, but you'll
374- probably only need one. If you *do * have multiple, you can configure which
388+ probably only need one. If you *do * have multiple, you have to configure which
375389*one * provider to use for your firewall under its ``provider `` key (e.g.
376- ``provider: in_memory ``).
390+ ``provider: users_in_memory ``).
377391
378392.. seealso ::
379393
@@ -421,20 +435,22 @@ To fix this, add an ``encoders`` key:
421435 .. code-block :: php
422436
423437 // app/config/security.php
438+ use Symfony\Component\Security\Core\User\User;
439+
424440 $container->loadFromExtension('security', [
425441 // ...
426442
427443 'encoders' => [
428- 'Symfony\Component\Security\Core\ User\User' => 'plaintext',
444+ User::class => 'plaintext',
429445 ],
430446 // ...
431447 ]);
432448
433- User providers load user information and put it into a `` User `` object. If
434- you :doc: `load users from the database </security/entity_provider >`
449+ User providers load user information and put it into a :class: ` Symfony \\ Component \\ Security \\ Core \\ User\\ UserInterface `
450+ implementation. If you :doc: `load users from the database </security/entity_provider >`
435451or :doc: `some other source </security/custom_provider >`, you'll
436- use your own custom User class. But when you use the "in memory" provider,
437- it gives you a `` Symfony\Component\Security\Core\User\User ` ` object.
452+ use your own custom User class. But when you use the "in memory" provider type ,
453+ it gives you a :class: ` Symfony\\ Component\\ Security\\ Core\\ User\\ User ` object.
438454
439455Whatever your User class is, you need to tell Symfony what algorithm was
440456used to encode the passwords. In this case, the passwords are just plaintext,
@@ -449,6 +465,67 @@ you who you are and what roles you have:
449465Because this URL requires ``ROLE_ADMIN ``, if you had logged in as ``ryan ``,
450466this would deny you access. More on that later (:ref: `security-authorization-access-control `).
451467
468+ .. tip ::
469+
470+ If you have many providers and want to define the same encoder for all of
471+ them, you can configure as follow:
472+
473+ .. configuration-block ::
474+
475+ .. code-block :: yaml
476+
477+ # app/config/security.yml
478+ security :
479+ encoders :
480+ Symfony\Component\Security\Core\User\UserInterface : bcrypt
481+
482+ # is equivalent to:
483+ AppBundle\Entity\User : bcrypt
484+ Symfony\Component\Security\Core\User\User : bcrypt
485+ # and any other type you may add in the future
486+ # ...
487+
488+ .. code-block :: xml
489+
490+ <!-- app/config/security.xml -->
491+ <?xml version =" 1.0" encoding =" UTF-8" ?>
492+ <srv : container xmlns =" http://symfony.com/schema/dic/security"
493+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
494+ xmlns : srv =" http://symfony.com/schema/dic/services"
495+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
496+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
497+
498+ <config >
499+ <encoder class =" Symfony\Component\Security\Core\User\UserInterface"
500+ algorithm =" bcrypt" />
501+ <!-- is equivalent to: -->
502+ <encoder class =" AppBundle\Entity\User"
503+ algorithm =" bcrypt" />
504+ <encoder class =" Symfony\Component\Security\Core\User\User"
505+ algorithm =" bcrypt" />
506+ <!-- and any other type you may add in the future -->
507+
508+ <!-- ... -->
509+ </config >
510+ </srv : container >
511+
512+ .. code-block :: php
513+
514+ // app/config/security.php
515+ use Symfony\Component\Security\Core\User\UserInterface;
516+
517+ $container->loadFromExtension('security', [
518+ 'encoders' => [
519+ UserInterface::class => 'bcrypt',
520+
521+ // is equivalent to:
522+ AppBundle\Entity\User::class => 'bcrypt',
523+ Symfony\Component\Security\Core\User\User::class => 'bcrypt',
524+ // and any other type you may add in the future
525+ ],
526+ // ...
527+ ]);
528+
452529 Loading Users from the Database
453530...............................
454531
@@ -502,11 +579,13 @@ is ``bcrypt``:
502579 .. code-block :: php
503580
504581 // app/config/security.php
582+ use Symfony\Component\Security\Core\User\User;
583+
505584 $container->loadFromExtension('security', [
506585 // ...
507586
508587 'encoders' => [
509- 'Symfony\Component\Security\Core\ User\User' => [
588+ User::class => [
510589 'algorithm' => 'bcrypt',
511590 'cost' => 12,
512591 ]
@@ -532,7 +611,7 @@ It will give you something like this:
532611 # ...
533612
534613 providers :
535- in_memory :
614+ users_in_memory :
536615 memory :
537616 users :
538617 ryan :
@@ -571,7 +650,7 @@ It will give you something like this:
571650 // ...
572651
573652 'providers' => [
574- 'in_memory ' => [
653+ 'users_in_memory ' => [
575654 'memory' => [
576655 'users' => [
577656 'ryan' => [
0 commit comments