|
1 | 1 | .. index::
|
2 | 2 | single: Security; Custom Authenticator
|
3 | 3 |
|
4 |
| -How to create a custom Authenticator |
| 4 | +How to create a Custom Authenticator |
5 | 5 | ====================================
|
6 | 6 |
|
7 |
| -Introduction |
8 |
| ------------- |
9 |
| - |
10 | 7 | Imagine you want to allow access to your website only between 2pm and 4pm (for
|
11 | 8 | the UTC timezone). Before Symfony 2.4, you had to create a custom token, factory,
|
12 | 9 | listener and provider.
|
13 | 10 |
|
14 | 11 | The Authenticator
|
15 | 12 | -----------------
|
16 | 13 |
|
17 |
| -Thanks to new simplified authentication customization options in Symfony 2.4, |
18 |
| -you don't need to create a whole bunch of new classes, but use the |
| 14 | +But now, thanks to new simplified authentication customization options in |
| 15 | +Symfony 2.4, you don't need to create a whole bunch of new classes, but use the |
19 | 16 | :class:`Symfony\\Component\\Security\\Core\\Authentication\\SimpleFormAuthenticatorInterface`
|
20 | 17 | interface instead::
|
21 | 18 |
|
@@ -90,7 +87,7 @@ interface instead::
|
90 | 87 | .. versionadded:: 2.4
|
91 | 88 | The ``SimpleFormAuthenticatorInterface`` interface was added in Symfony 2.4.
|
92 | 89 |
|
93 |
| -How it works |
| 90 | +How it Works |
94 | 91 | ------------
|
95 | 92 |
|
96 | 93 | There are a lot of things going on:
|
@@ -131,18 +128,26 @@ Now, configure your ``TimeAuthenticator`` as a service:
|
131 | 128 | .. code-block:: xml
|
132 | 129 |
|
133 | 130 | <!-- app/config/config.xml -->
|
134 |
| - <services> |
135 |
| - <service id="time_authenticator" |
136 |
| - class="Acme\HelloBundle\Security\TimeAuthenticator"> |
137 |
| - <argument type="service" id="security.encoder_factory"/> |
138 |
| - </service> |
139 |
| - </services> |
| 131 | + <?xml version="1.0" ?> |
| 132 | + <container xmlns="http://symfony.com/schema/dic/services" |
| 133 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 134 | + xsi:schemaLocation="http://symfony.com/schema/dic/services |
| 135 | + http://symfony.com/schema/dic/services/services-1.0.xsd"> |
| 136 | + <services> |
| 137 | + <service id="time_authenticator" |
| 138 | + class="Acme\HelloBundle\Security\TimeAuthenticator"> |
| 139 | + <argument type="service" id="security.encoder_factory"/> |
| 140 | + </service> |
| 141 | + </services> |
| 142 | + </container> |
140 | 143 |
|
141 | 144 | .. code-block:: php
|
142 | 145 |
|
143 | 146 | // app/config/config.php
|
144 | 147 | use Symfony\Component\DependencyInjection\Definition;
|
145 | 148 | use Symfony\Component\DependencyInjection\Reference;
|
| 149 | + |
| 150 | + // ... |
146 | 151 |
|
147 | 152 | $container->setDefinition('time_authenticator', new Definition(
|
148 | 153 | 'Acme\HelloBundle\Security\TimeAuthenticator',
|
@@ -180,11 +185,12 @@ like this:
|
180 | 185 | xsi:schemaLocation="http://symfony.com/schema/dic/services
|
181 | 186 | http://symfony.com/schema/dic/services/services-1.0.xsd">
|
182 | 187 | <config>
|
183 |
| - <firewall name="secured_area" pattern="^/admin"> |
184 |
| - <provider name="authenticator" /> |
| 188 | + <firewall name="secured_area" |
| 189 | + pattern="^/admin" |
| 190 | + provider="authenticator"> |
185 | 191 | <simple-form authenticator="time_authenticator"
|
186 |
| - check_path="login_check" |
187 |
| - login_path="login" /> |
| 192 | + check-path="login_check" |
| 193 | + login-path="login" /> |
188 | 194 | </firewall>
|
189 | 195 | </config>
|
190 | 196 | </srv:container>
|
|
0 commit comments