You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/modules/ROOT/pages/migration-7/web.adoc
+328
Original file line number
Diff line number
Diff line change
@@ -145,3 +145,331 @@ Xml::
145
145
----
146
146
======
147
147
148
+
[[use-path-pattern]]
149
+
== Use PathPatternRequestMatcher by Default
150
+
151
+
In Spring Security 7, `AntPathRequestMatcher` and `MvcRequestMatcher` are no longer supported and the Java DSL requires that all URIs be absolute (less any context root).
152
+
At that time, Spring Security 7 will use `PathPatternRequestMatcher` by default.
153
+
154
+
To check how prepared you are for this change, you can publish this bean:
This will tell the Spring Security DSL to use `PathPatternRequestMatcher` for all request matchers that it constructs.
187
+
188
+
In the event that you are directly constructing an object (as opposed to having the DSL construct it) that has a `setRequestMatcher` method. you should also proactively specify a `PathPatternRequestMatcher` there as well.
189
+
190
+
=== Migrate `exitUserUrl` and `switchUserUrl` Request Matchers in `SwitchUserFilter`
191
+
192
+
`SwitchUserFilter`, constructs an `AntPathRequestMatcher` in its `setExitUserUrl` and `setSwitchUserUrl` methods.
193
+
This will change to use `PathPatternRequestMatcher` in Spring Security 7.
194
+
195
+
To prepare for this change, call `setExitUserMatcher` and `setSwithcUserMatcher` to provide this `PathPatternRequestMatcher` in advance.
196
+
That is, change this:
197
+
198
+
[tabs]
199
+
======
200
+
Java::
201
+
+
202
+
[source,java,role="primary"]
203
+
----
204
+
SwitchUserFilter switchUser = new SwitchUserFilter();
205
+
// ... other configuration
206
+
switchUser.setExitUserUrl("/exit/impersonate");
207
+
----
208
+
209
+
Kotlin::
210
+
+
211
+
[source,kotlin,role="secondary"]
212
+
----
213
+
val switchUser = SwitchUserFilter()
214
+
// ... other configuration
215
+
switchUser.setExitUserUrl("/exit/impersonate")
216
+
----
217
+
======
218
+
219
+
to this:
220
+
221
+
[tabs]
222
+
======
223
+
Java::
224
+
+
225
+
[source,java,role="primary"]
226
+
----
227
+
SwitchUserFilter switchUser = new SwitchUserFilter();
=== Migrate `filterProcessingUrl` Request Matcher in `AbstractAuthenticationProcessingFilter` Implementations
243
+
244
+
Spring Security 6 converts any processing endpoint configured through `setFilterProcessingUrl` to an `AntPathRequestMatcher`.
245
+
In Spring Security 7, this will change to `PathPatternRequestMatcher`.
246
+
247
+
If you are directly invoking `setFilterProcessingUrl` on a filter that extends `AbstractAuthenticationProcessingFilter`, like `UsernamePasswordAuthenticationFilter`, `OAuth2LoginAuthenticationFilter`, `Saml2WebSsoAuthenticationFilter`, `OneTimeTokenAuthenticationFilter`, or `WebAuthnAuthenticationFilter`, call `setRequiredAuthenticationRequestMatcher` instead to provide this `PathPatternRequestMatcher` in advance.
248
+
249
+
That is, change this:
250
+
[tabs]
251
+
======
252
+
Java::
253
+
+
254
+
[source,java,role="primary"]
255
+
----
256
+
UsernamePasswordAuthenticationFilter usernamePassword = new UsernamePasswordAuthenticationFilter(authenticationManager);
== Include the Servlet Path Prefix in Authorization Rules
343
+
344
+
For many applications <<use-path-pattern, the above>> will make no difference since most commonly all URIs listed are matched by the default servlet.
345
+
346
+
However, if you have other servlets with servlet path prefixes, xref:servlet/authorization/authorize-http-requests.adoc[then these paths now need to be supplied separately].
347
+
348
+
For example, if I have a Spring MVC controller with `@RequestMapping("/orders")` and my MVC application is deployed to `/mvc` (instead of the default servlet), then the URI for this endpoint is `/mvc/orders`.
349
+
Historically, the Java DSL hasn't had a simple way to specify the servlet path prefix and Spring Security attempted to infer it.
350
+
351
+
Over time, we learned that these inference would surprise developers.
352
+
Instead of taking this responsibility away from developers, now it is simpler to specify the servlet path prefix like so:
Note that this doesn't address every kind of servlet since not all servlets have a path prefix.
376
+
For example, expressions that match the JSP Servlet might use an ant pattern `/**/*.jsp`.
377
+
378
+
There is not yet a general-purpose replacement for these, and so you are encouraged to use `RegexRequestMatcher`, like so: `regexMatcher("\\.jsp$")`.
379
+
380
+
For many applications this will make no difference since most commonly all URIs listed are matched by the default servlet.
381
+
382
+
[[use-redirect-to-https]]
383
+
== Use RedirectToHttps Instead of Channel Security
384
+
385
+
Years ago, HTTPS at large was enough of a performance and configuration concern that applications wanted to be able to decide which segments of an application would require HTTPS.
386
+
387
+
`requires-channel` in XML and `requiresChannel` in Java Config allowed configurating an application with that in mind:
Modern applications should either always require HTTPS.
426
+
However, there are times, like when developing locally, when one would like the application to use HTTP.
427
+
Or, you may have continuing circumstances that require part of your application to be HTTP.
428
+
429
+
In any case, you can migrate to `redirect-to-https-request-matcher-ref` and `redirectToHttps` by first constructing a `RequestMatcher` that contains all circumstances where redirecting to HTTPS is needed.
430
+
Then you can reference that request matcher like so:
0 commit comments