@@ -45,7 +45,7 @@ configuration looks like this:
45
45
# app/config/security.yml
46
46
security :
47
47
providers :
48
- in_memory :
48
+ users_in_memory :
49
49
memory : ~
50
50
51
51
firewalls :
@@ -55,6 +55,7 @@ configuration looks like this:
55
55
56
56
main :
57
57
anonymous : ~
58
+ provider : users_in_memory
58
59
59
60
.. code-block :: xml
60
61
@@ -86,7 +87,7 @@ configuration looks like this:
86
87
// app/config/security.php
87
88
$container->loadFromExtension('security', [
88
89
'providers' => [
89
- 'in_memory ' => [
90
+ 'users_in_memory ' => [
90
91
'memory' => null,
91
92
],
92
93
],
@@ -97,6 +98,7 @@ configuration looks like this:
97
98
],
98
99
'main' => [
99
100
'anonymous' => null,
101
+ 'provider' => 'users_in_memory'
100
102
],
101
103
],
102
104
]);
@@ -315,7 +317,7 @@ provider, but it's better to think of it as an "in configuration" provider:
315
317
# app/config/security.yml
316
318
security :
317
319
providers :
318
- in_memory :
320
+ users_in_memory :
319
321
memory :
320
322
users :
321
323
ryan :
@@ -352,7 +354,7 @@ provider, but it's better to think of it as an "in configuration" provider:
352
354
// app/config/security.php
353
355
$container->loadFromExtension('security', [
354
356
'providers' => [
355
- 'in_memory ' => [
357
+ 'users_in_memory ' => [
356
358
'memory' => [
357
359
'users' => [
358
360
'ryan' => [
@@ -371,9 +373,9 @@ provider, but it's better to think of it as an "in configuration" provider:
371
373
]);
372
374
373
375
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
376
+ probably only need one. If you *do * have multiple, you have to configure which
375
377
*one * provider to use for your firewall under its ``provider `` key (e.g.
376
- ``provider: in_memory ``).
378
+ ``provider: users_in_memory ``).
377
379
378
380
.. seealso ::
379
381
@@ -421,20 +423,22 @@ To fix this, add an ``encoders`` key:
421
423
.. code-block :: php
422
424
423
425
// app/config/security.php
426
+ use Symfony\Component\Security\Core\User\User;
427
+
424
428
$container->loadFromExtension('security', [
425
429
// ...
426
430
427
431
'encoders' => [
428
- 'Symfony\Component\Security\Core\ User\User' => 'plaintext',
432
+ User::class => 'plaintext',
429
433
],
430
434
// ...
431
435
]);
432
436
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 >`
437
+ User providers load user information and put it into a :class: ` Symfony \C omponent \S ecurity \C ore \ U ser\U serInterface `
438
+ implementation. If you :doc: `load users from the database </security/entity_provider >`
435
439
or :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.
440
+ use your own custom User class. But when you use the "in memory" provider type ,
441
+ it gives you a :class: ` Symfony\C omponent\S ecurity\C ore\U ser\U ser ` object.
438
442
439
443
Whatever your User class is, you need to tell Symfony what algorithm was
440
444
used to encode the passwords. In this case, the passwords are just plaintext,
@@ -449,6 +453,45 @@ you who you are and what roles you have:
449
453
Because this URL requires ``ROLE_ADMIN ``, if you had logged in as ``ryan ``,
450
454
this would deny you access. More on that later (:ref: `security-authorization-access-control `).
451
455
456
+ .. tip ::
457
+
458
+ If you have many providers and want to define the same encoder for all of
459
+ them, you can configure as follow:
460
+
461
+ .. configuration-block ::
462
+
463
+ .. code-block :: yaml
464
+
465
+ # app/config/security.yml
466
+ security:
467
+ # ...
468
+
469
+ encoders:
470
+ Symfony\C omponent\S ecurity\C ore\U ser\U serInterface: bcrypt
471
+
472
+ # would be equivalent to:
473
+ # App\E ntity\U ser: bcrypt
474
+ # Symfony\C omponent\S ecurity\C ore\U ser\U ser: bcrypt
475
+ # ...
476
+
477
+ .. code-block :: php
478
+
479
+ // app/config/security.php
480
+ use Symfony\Component\Security\Core\User\UserInterface;
481
+
482
+ $container->loadFromExtension('security', [
483
+ // ...
484
+
485
+ 'encoders' => [
486
+ UserInterface::class => 'bcrypt',
487
+
488
+ // would be equivalent to:
489
+ // App\Entity\User::class => 'bcrypt',
490
+ // Symfony\Component\Security\Core\User\User::class => 'bcrypt',
491
+ ],
492
+ // ...
493
+ ]);
494
+
452
495
Loading Users from the Database
453
496
...............................
454
497
@@ -502,11 +545,13 @@ is ``bcrypt``:
502
545
.. code-block :: php
503
546
504
547
// app/config/security.php
548
+ use Symfony\Component\Security\Core\User\User;
549
+
505
550
$container->loadFromExtension('security', [
506
551
// ...
507
552
508
553
'encoders' => [
509
- 'Symfony\Component\Security\Core\ User\User' => [
554
+ User::class => [
510
555
'algorithm' => 'bcrypt',
511
556
'cost' => 12,
512
557
]
@@ -532,7 +577,7 @@ It will give you something like this:
532
577
# ...
533
578
534
579
providers :
535
- in_memory :
580
+ users_in_memory :
536
581
memory :
537
582
users :
538
583
ryan :
@@ -571,7 +616,7 @@ It will give you something like this:
571
616
// ...
572
617
573
618
'providers' => [
574
- 'in_memory ' => [
619
+ 'users_in_memory ' => [
575
620
'memory' => [
576
621
'users' => [
577
622
'ryan' => [
0 commit comments