Skip to content

Commit 62c7f2b

Browse files
mhujerwouterj
authored andcommitted
Security: add example code which Maker Bundle generated
See #11265
1 parent 73f02f1 commit 62c7f2b

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

security.rst

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,59 @@ optional features, like :doc:`remember me </security/remember_me>` and
9696
:doc:`impersonation </security/impersonating_user>`.
9797

9898
Fortunately, the ``make:user`` command already configured one for you in your
99-
``security.yaml`` file under the ``providers`` key.
99+
``security.yaml`` file under the ``providers`` key:
100+
101+
.. configuration-block::
102+
103+
.. code-block:: yaml
104+
105+
# config/packages/security.yaml
106+
security:
107+
# ...
108+
109+
providers:
110+
# used to reload user from session & other features (e.g. switch_user)
111+
app_user_provider:
112+
entity:
113+
class: App\Entity\User
114+
property: email
115+
116+
.. code-block:: xml
117+
118+
<!-- config/packages/security.xml -->
119+
<?xml version="1.0" encoding="UTF-8"?>
120+
<srv:container xmlns="http://symfony.com/schema/dic/security"
121+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
122+
xmlns:srv="http://symfony.com/schema/dic/services"
123+
xsi:schemaLocation="http://symfony.com/schema/dic/services
124+
https://symfony.com/schema/dic/services/services-1.0.xsd">
125+
126+
<config>
127+
<!-- used to reload user from session & other features (e.g. switch-user) -->
128+
<provider name="app_user_provider">
129+
<entity class="App\Entity\User" property="email"/>
130+
</provider>
131+
</config>
132+
</srv:container>
133+
134+
.. code-block:: php
135+
136+
// config/packages/security.php
137+
use App\Entity\User;
138+
139+
$container->loadFromExtension('security', [
140+
// ...
141+
142+
'providers' => [
143+
// used to reload user from session & other features (e.g. switch_user)
144+
'app_user_provider' => [
145+
'entity' => [
146+
'class' => User::class,
147+
'property' => 'email',
148+
],
149+
],
150+
],
151+
]);
100152
101153
If your ``User`` class is an entity, you don't need to do anything else. But if
102154
your class is *not* an entity, then ``make:user`` will also have generated a

0 commit comments

Comments
 (0)