1
1
.. index ::
2
- single: Security; Custom Authenticator
2
+ single: Security; Custom Password Authenticator
3
3
4
- How to create a Custom Authenticator
5
- ====================================
4
+ How to create a Custom Password Authenticator
5
+ =============================================
6
6
7
7
Imagine you want to allow access to your website only between 2pm and 4pm (for
8
8
the UTC timezone). Before Symfony 2.4, you had to create a custom token, factory,
9
9
listener and provider.
10
10
11
- The Authenticator
12
- -----------------
11
+ The Password Authenticator
12
+ --------------------------
13
+
14
+ .. versionadded :: 2.4
15
+ The ``SimpleFormAuthenticatorInterface `` interface was added in Symfony 2.4.
13
16
14
17
But now, thanks to new simplified authentication customization options in
15
18
Symfony 2.4, you don't need to create a whole bunch of new classes, but use the
@@ -84,9 +87,6 @@ interface instead::
84
87
}
85
88
}
86
89
87
- .. versionadded :: 2.4
88
- The ``SimpleFormAuthenticatorInterface `` interface was added in Symfony 2.4.
89
-
90
90
How it Works
91
91
------------
92
92
@@ -121,6 +121,8 @@ Now, configure your ``TimeAuthenticator`` as a service:
121
121
122
122
# app/config/config.yml
123
123
services :
124
+ # ...
125
+
124
126
time_authenticator :
125
127
class : Acme\HelloBundle\Security\TimeAuthenticator
126
128
arguments : [@security.encoder_factory]
@@ -134,9 +136,12 @@ Now, configure your ``TimeAuthenticator`` as a service:
134
136
xsi : schemaLocation =" http://symfony.com/schema/dic/services
135
137
http://symfony.com/schema/dic/services/services-1.0.xsd" >
136
138
<services >
139
+ <!-- ... -->
140
+
137
141
<service id =" time_authenticator"
138
- class =" Acme\HelloBundle\Security\TimeAuthenticator" >
139
- <argument type =" service" id =" security.encoder_factory" />
142
+ class =" Acme\HelloBundle\Security\TimeAuthenticator"
143
+ >
144
+ <argument type =" service" id =" security.encoder_factory" />
140
145
</service >
141
146
</services >
142
147
</container >
@@ -185,19 +190,25 @@ like this:
185
190
xsi : schemaLocation =" http://symfony.com/schema/dic/services
186
191
http://symfony.com/schema/dic/services/services-1.0.xsd" >
187
192
<config >
193
+ <!-- ... -->
194
+
188
195
<firewall name =" secured_area"
189
196
pattern =" ^/admin"
190
197
provider =" authenticator" >
191
198
<simple-form authenticator =" time_authenticator"
192
199
check-path =" login_check"
193
- login-path =" login" />
200
+ login-path =" login"
201
+ />
194
202
</firewall >
195
203
</config >
196
204
</srv : container >
197
205
198
206
.. code-block :: php
199
207
200
208
// app/config/security.php
209
+
210
+ // ..
211
+
201
212
$container->loadFromExtension('security', array(
202
213
'firewalls' => array(
203
214
'secured_area' => array(
0 commit comments