@@ -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
@@ -67,7 +68,7 @@ configuration looks like this:
67
68
https://symfony.com/schema/dic/services/services-1.0.xsd" >
68
69
69
70
<config >
70
- <provider name =" in_memory " >
71
+ <provider name =" users_in_memory " >
71
72
<memory />
72
73
</provider >
73
74
@@ -77,6 +78,7 @@ configuration looks like this:
77
78
78
79
<firewall name =" main" >
79
80
<anonymous />
81
+ <provider >users_in_memory</provider >
80
82
</firewall >
81
83
</config >
82
84
</srv : container >
@@ -86,7 +88,7 @@ configuration looks like this:
86
88
// app/config/security.php
87
89
$container->loadFromExtension('security', [
88
90
'providers' => [
89
- 'in_memory ' => [
91
+ 'users_in_memory ' => [
90
92
'memory' => null,
91
93
],
92
94
],
@@ -97,6 +99,7 @@ configuration looks like this:
97
99
],
98
100
'main' => [
99
101
'anonymous' => null,
102
+ 'provider' => 'users_in_memory'
100
103
],
101
104
],
102
105
]);
@@ -315,7 +318,7 @@ provider, but it's better to think of it as an "in configuration" provider:
315
318
# app/config/security.yml
316
319
security :
317
320
providers :
318
- in_memory :
321
+ users_in_memory :
319
322
memory :
320
323
users :
321
324
ryan :
@@ -324,7 +327,11 @@ provider, but it's better to think of it as an "in configuration" provider:
324
327
admin :
325
328
password : kitten
326
329
roles : ' ROLE_ADMIN'
327
- # ...
330
+
331
+ firewalls :
332
+ main :
333
+ provider : users_in_memory
334
+ # ...
328
335
329
336
.. code-block :: xml
330
337
@@ -337,13 +344,16 @@ provider, but it's better to think of it as an "in configuration" provider:
337
344
https://symfony.com/schema/dic/services/services-1.0.xsd" >
338
345
339
346
<config >
340
- <provider name =" in_memory " >
347
+ <provider name =" users_in_memory " >
341
348
<memory >
342
349
<user name =" ryan" password =" ryanpass" roles =" ROLE_USER" />
343
350
<user name =" admin" password =" kitten" roles =" ROLE_ADMIN" />
344
351
</memory >
345
352
</provider >
346
- <!-- ... -->
353
+ <firewall name =" main" >
354
+ <provider >users_in_memory</provider >
355
+ <!-- ... -->
356
+ </firewall >
347
357
</config >
348
358
</srv : container >
349
359
@@ -352,7 +362,7 @@ provider, but it's better to think of it as an "in configuration" provider:
352
362
// app/config/security.php
353
363
$container->loadFromExtension('security', [
354
364
'providers' => [
355
- 'in_memory ' => [
365
+ 'users_in_memory ' => [
356
366
'memory' => [
357
367
'users' => [
358
368
'ryan' => [
@@ -367,13 +377,17 @@ provider, but it's better to think of it as an "in configuration" provider:
367
377
],
368
378
],
369
379
],
370
- // ...
380
+ 'firewalls' => [
381
+ 'main' => [
382
+ 'provider' => 'users_in_memory',
383
+ ],
384
+ ],
371
385
]);
372
386
373
387
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
375
389
*one * provider to use for your firewall under its ``provider `` key (e.g.
376
- ``provider: in_memory ``).
390
+ ``provider: users_in_memory ``).
377
391
378
392
.. seealso ::
379
393
@@ -421,20 +435,22 @@ To fix this, add an ``encoders`` key:
421
435
.. code-block :: php
422
436
423
437
// app/config/security.php
438
+ use Symfony\Component\Security\Core\User\User;
439
+
424
440
$container->loadFromExtension('security', [
425
441
// ...
426
442
427
443
'encoders' => [
428
- 'Symfony\Component\Security\Core\ User\User' => 'plaintext',
444
+ User::class => 'plaintext',
429
445
],
430
446
// ...
431
447
]);
432
448
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 >`
435
451
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.
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.
438
454
439
455
Whatever your User class is, you need to tell Symfony what algorithm was
440
456
used 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:
449
465
Because this URL requires ``ROLE_ADMIN ``, if you had logged in as ``ryan ``,
450
466
this would deny you access. More on that later (:ref: `security-authorization-access-control `).
451
467
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\C omponent\S ecurity\C ore\U ser\U serInterface: bcrypt
481
+
482
+ # would be equivalent to:
483
+ AppBundle\E ntity\U ser: bcrypt
484
+ Symfony\C omponent\S ecurity\C ore\U ser\U ser: 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
+ <!-- would be 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
+ // would be 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
+
452
529
Loading Users from the Database
453
530
...............................
454
531
@@ -502,11 +579,13 @@ is ``bcrypt``:
502
579
.. code-block :: php
503
580
504
581
// app/config/security.php
582
+ use Symfony\Component\Security\Core\User\User;
583
+
505
584
$container->loadFromExtension('security', [
506
585
// ...
507
586
508
587
'encoders' => [
509
- 'Symfony\Component\Security\Core\ User\User' => [
588
+ User::class => [
510
589
'algorithm' => 'bcrypt',
511
590
'cost' => 12,
512
591
]
@@ -532,7 +611,7 @@ It will give you something like this:
532
611
# ...
533
612
534
613
providers :
535
- in_memory :
614
+ users_in_memory :
536
615
memory :
537
616
users :
538
617
ryan :
@@ -571,7 +650,7 @@ It will give you something like this:
571
650
// ...
572
651
573
652
'providers' => [
574
- 'in_memory ' => [
653
+ 'users_in_memory ' => [
575
654
'memory' => [
576
655
'users' => [
577
656
'ryan' => [
0 commit comments