@@ -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 \ U ser\\ 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,73 @@ 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
+ # ...
480
+
481
+ encoders:
482
+ Symfony\C omponent\S ecurity\C ore\U ser\U serInterface: bcrypt
483
+
484
+ # would be equivalent to:
485
+ AppBundle\E ntity\U ser: bcrypt
486
+ Symfony\C omponent\S ecurity\C ore\U ser\U ser: bcrypt
487
+ # and any other type you may add in the future
488
+ # ...
489
+
490
+ .. code-block :: xml
491
+
492
+ <!-- app/config/security.xml -->
493
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
494
+ <srv : container xmlns =" http://symfony.com/schema/dic/security"
495
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
496
+ xmlns : srv =" http://symfony.com/schema/dic/services"
497
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
498
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
499
+
500
+ <config >
501
+ <!-- ... -->
502
+
503
+ <encoder class =" Symfony\Component\Security\Core\User\UserInterface"
504
+ algorithm =" bcrypt" />
505
+ <!-- would be equivalent to: -->
506
+ <encoder class =" AppBundle\Entity\User"
507
+ algorithm =" bcrypt" />
508
+ <encoder class =" Symfony\Component\Security\Core\User\User"
509
+ algorithm =" bcrypt" />
510
+ <!-- and any other type you may add in the future -->
511
+
512
+ <!-- ... -->
513
+ </config >
514
+ </srv : container >
515
+
516
+ .. code-block:: php
517
+
518
+ // app/config/security.php
519
+ use Symfony\Component\Security\Core\User\UserInterface;
520
+
521
+ $container->loadFromExtension('security', [
522
+ // ...
523
+
524
+ 'encoders' => [
525
+ UserInterface::class => 'bcrypt',
526
+
527
+ // would be equivalent to:
528
+ AppBundle\Entity\User::class => 'bcrypt',
529
+ Symfony\Component\Security\Core\User\User::class => 'bcrypt',
530
+ // and any other type you may add in the future
531
+ ],
532
+ // ...
533
+ ]);
534
+
452
535
Loading Users from the Database
453
536
...............................
454
537
@@ -502,11 +585,13 @@ is ``bcrypt``:
502
585
.. code-block :: php
503
586
504
587
// app/config/security.php
588
+ use Symfony\Component\Security\Core\User\User;
589
+
505
590
$container->loadFromExtension('security', [
506
591
// ...
507
592
508
593
'encoders' => [
509
- 'Symfony\Component\Security\Core\ User\User' => [
594
+ User::class => [
510
595
'algorithm' => 'bcrypt',
511
596
'cost' => 12,
512
597
]
@@ -532,7 +617,7 @@ It will give you something like this:
532
617
# ...
533
618
534
619
providers :
535
- in_memory :
620
+ users_in_memory :
536
621
memory :
537
622
users :
538
623
ryan :
@@ -571,7 +656,7 @@ It will give you something like this:
571
656
// ...
572
657
573
658
'providers' => [
574
- 'in_memory ' => [
659
+ 'users_in_memory ' => [
575
660
'memory' => [
576
661
'users' => [
577
662
'ryan' => [
0 commit comments