@@ -9,11 +9,22 @@ result of a request matcher: the first firewall matching the request will handle
9
9
10
10
The last firewall can be configured without any matcher to handle every incoming request.
11
11
12
- Restricting by Service
13
- ----------------------
12
+ Restricting by Configuration
13
+ ----------------------------
14
14
15
- You can configure any service implementing :class: `Symfony\\ Component\\ HttpFoundation\\ RequestMatcherInterface `
16
- as ``request_matcher ``.
15
+ Most of the time you don't need to create matchers yourself as Symfony can do it for you based on the
16
+ firewall configuration.
17
+
18
+ .. note ::
19
+
20
+ You can use any of the following restrictions individually or mix them together to get
21
+ your desired firewall configuration.
22
+
23
+ Restricting by Path
24
+ ~~~~~~~~~~~~~~~~~~~
25
+
26
+ This is the default restriction and restricts a firewall to only be initialized if the request path
27
+ matches the configured ``pattern ``.
17
28
18
29
.. configuration-block ::
19
30
@@ -25,7 +36,7 @@ as ``request_matcher``.
25
36
security :
26
37
firewalls :
27
38
secured_area :
28
- request_matcher : app.firewall.secured_area.request_matcher
39
+ pattern : ^/admin
29
40
# ...
30
41
31
42
.. code-block :: xml
@@ -40,7 +51,7 @@ as ``request_matcher``.
40
51
41
52
<config >
42
53
<!-- ... -->
43
- <firewall name =" secured_area" request-matcher = " app.firewall.secured_area.request_matcher " >
54
+ <firewall name =" secured_area" pattern = " ^/admin " >
44
55
<!-- ... -->
45
56
</firewall >
46
57
</config >
@@ -54,28 +65,23 @@ as ``request_matcher``.
54
65
$container->loadFromExtension('security', [
55
66
'firewalls' => [
56
67
'secured_area' => [
57
- 'request_matcher ' => 'app.firewall.secured_area.request_matcher ',
68
+ 'pattern ' => '^/admin ',
58
69
// ...
59
70
],
60
71
],
61
72
]);
62
73
63
- However in most cases you don't need to create these matchers yourself as Symfony can do it for you based
64
- on the firewall configuration.
65
-
66
- Restricting by Configuration
67
- ----------------------------
68
-
69
- .. note ::
70
-
71
- You can use any of the following restrictions individually or mix them together to get
72
- your desired firewall configuration.
74
+ The ``pattern `` is a regular expression. In this example, the firewall will only be
75
+ activated if the path starts (due to the ``^ `` regex character) with ``/admin ``. If
76
+ the path does not match this pattern, the firewall will not be activated and subsequent
77
+ firewalls will have the opportunity to be matched for this request.
73
78
74
- Restricting by Path
79
+ Restricting by Host
75
80
~~~~~~~~~~~~~~~~~~~
76
81
77
- This is the default restriction and restricts a firewall to only be initialized if the request path
78
- matches the configured ``pattern ``.
82
+ If matching against the ``pattern `` only is not enough, the request can also be matched against
83
+ ``host ``. When the configuration option ``host `` is set, the firewall will be restricted to
84
+ only initialize if the host from the request matches against the configuration.
79
85
80
86
.. configuration-block ::
81
87
@@ -87,7 +93,7 @@ matches the configured ``pattern``.
87
93
security :
88
94
firewalls :
89
95
secured_area :
90
- pattern : ^/ admin
96
+ host : ^admin\.example\.com$
91
97
# ...
92
98
93
99
.. code-block :: xml
@@ -102,7 +108,7 @@ matches the configured ``pattern``.
102
108
103
109
<config >
104
110
<!-- ... -->
105
- <firewall name =" secured_area" pattern =" ^/ admin" >
111
+ <firewall name =" secured_area" host =" ^admin\.example\.com$ " >
106
112
<!-- ... -->
107
113
</firewall >
108
114
</config >
@@ -116,23 +122,24 @@ matches the configured ``pattern``.
116
122
$container->loadFromExtension('security', [
117
123
'firewalls' => [
118
124
'secured_area' => [
119
- 'pattern ' => '^/ admin',
125
+ 'host ' => '^admin\.example\.com$ ',
120
126
// ...
121
127
],
122
128
],
123
129
]);
124
130
125
- The ``pattern `` is a regular expression. In this example, the firewall will only be
126
- activated if the path starts (due to the ``^ `` regex character) with ``/admin ``. If
127
- the path does not match this pattern, the firewall will not be activated and subsequent
128
- firewalls will have the opportunity to be matched for this request.
131
+ The ``host `` (like the ``pattern ``) is a regular expression. In this example,
132
+ the firewall will only be activated if the host is equal exactly (due to
133
+ the ``^ `` and ``$ `` regex characters) to the hostname ``admin.example.com ``.
134
+ If the hostname does not match this pattern, the firewall will not be activated
135
+ and subsequent firewalls will have the opportunity to be matched for this
136
+ request.
129
137
130
- Restricting by Host
131
- ~~~~~~~~~~~~~~~~~~~
138
+ Restricting by HTTP Methods
139
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
140
133
- If matching against the ``pattern `` only is not enough, the request can also be matched against
134
- ``host ``. When the configuration option ``host `` is set, the firewall will be restricted to
135
- only initialize if the host from the request matches against the configuration.
141
+ The configuration option ``methods `` restricts the initialization of the firewall to
142
+ the provided HTTP methods.
136
143
137
144
.. configuration-block ::
138
145
@@ -144,7 +151,7 @@ only initialize if the host from the request matches against the configuration.
144
151
security :
145
152
firewalls :
146
153
secured_area :
147
- host : ^admin\.example\.com$
154
+ methods : [GET, POST]
148
155
# ...
149
156
150
157
.. code-block :: xml
@@ -159,7 +166,7 @@ only initialize if the host from the request matches against the configuration.
159
166
160
167
<config >
161
168
<!-- ... -->
162
- <firewall name =" secured_area" host = " ^admin\.example\.com$ " >
169
+ <firewall name =" secured_area" methods = " GET,POST " >
163
170
<!-- ... -->
164
171
</firewall >
165
172
</config >
@@ -173,24 +180,22 @@ only initialize if the host from the request matches against the configuration.
173
180
$container->loadFromExtension('security', [
174
181
'firewalls' => [
175
182
'secured_area' => [
176
- 'host ' => '^admin\.example\.com$' ,
183
+ 'methods ' => ['GET', 'POST'] ,
177
184
// ...
178
185
],
179
186
],
180
187
]);
181
188
182
- The ``host `` (like the ``pattern ``) is a regular expression. In this example,
183
- the firewall will only be activated if the host is equal exactly (due to
184
- the ``^ `` and ``$ `` regex characters) to the hostname ``admin.example.com ``.
185
- If the hostname does not match this pattern, the firewall will not be activated
186
- and subsequent firewalls will have the opportunity to be matched for this
187
- request.
189
+ In this example, the firewall will only be activated if the HTTP method of the
190
+ request is either ``GET `` or ``POST ``. If the method is not in the array of the
191
+ allowed methods, the firewall will not be activated and subsequent firewalls will again
192
+ have the opportunity to be matched for this request.
188
193
189
- Restricting by HTTP Methods
190
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
194
+ Restricting by Service
195
+ ----------------------
191
196
192
- The configuration option `` methods `` restricts the initialization of the firewall to
193
- the provided HTTP methods .
197
+ If the above options don't fit your needs you can configure any service implementing
198
+ :class: ` Symfony \\ Component \\ HttpFoundation \\ RequestMatcherInterface ` as `` request_matcher `` .
194
199
195
200
.. configuration-block ::
196
201
@@ -202,7 +207,7 @@ the provided HTTP methods.
202
207
security :
203
208
firewalls :
204
209
secured_area :
205
- methods : [GET, POST]
210
+ request_matcher : app.firewall.secured_area.request_matcher
206
211
# ...
207
212
208
213
.. code-block :: xml
@@ -217,7 +222,7 @@ the provided HTTP methods.
217
222
218
223
<config >
219
224
<!-- ... -->
220
- <firewall name =" secured_area" methods = " GET,POST " >
225
+ <firewall name =" secured_area" request-matcher = " app.firewall.secured_area.request_matcher " >
221
226
<!-- ... -->
222
227
</firewall >
223
228
</config >
@@ -231,13 +236,8 @@ the provided HTTP methods.
231
236
$container->loadFromExtension('security', [
232
237
'firewalls' => [
233
238
'secured_area' => [
234
- 'methods ' => ['GET', 'POST'] ,
239
+ 'request_matcher ' => 'app.firewall.secured_area.request_matcher' ,
235
240
// ...
236
241
],
237
242
],
238
243
]);
239
-
240
- In this example, the firewall will only be activated if the HTTP method of the
241
- request is either ``GET `` or ``POST ``. If the method is not in the array of the
242
- allowed methods, the firewall will not be activated and subsequent firewalls will again
243
- have the opportunity to be matched for this request.
0 commit comments