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.adoc
+141-1Lines changed: 141 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1374,6 +1374,7 @@ http {
1374
1374
----
1375
1375
====
1376
1376
1377
+
[[switch-filter-all-dispatcher-types]]
1377
1378
==== Switch to filter all dispatcher types
1378
1379
1379
1380
Spring Security 5.8 and earlier only xref:servlet/authorization/architecture.adoc[perform authorization] once per request.
@@ -1384,7 +1385,7 @@ As such, in 6.0, Spring Security changes this default.
1384
1385
1385
1386
So, finally, change your authorization rules to filter all dispatcher types.
1386
1387
1387
-
To do this, change:
1388
+
To do this, you should change:
1388
1389
1389
1390
====
1390
1391
.Java
@@ -1464,6 +1465,145 @@ http {
1464
1465
----
1465
1466
====
1466
1467
1468
+
And, the `FilterChainProxy` should be registered for all dispatcher types as well.
1469
+
If you are using Spring Boot, https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.security.spring.security.filter.dispatcher-types[you have to change the `spring.security.filter.dispatcher-types` property] to include all dispatcher types:
If you are xref::servlet/configuration/java.adoc#_abstractsecuritywebapplicationinitializer[using the `AbstractSecurityWebApplicationInitializer`] you should override the `getSecurityDispatcherTypes` method and return all dispatcher types:
If you are using {spring-framework-reference-url}/web.html#mvc-viewresolver[Spring MVC to resolve view names], you will need to permit `FORWARD` requests.
1502
+
This is because when Spring MVC detects a mapping between view name and the actual views, it will perform a forward to the view.
1503
+
As we saw on the <<switch-filter-all-dispatcher-types,previous section>>, Spring Security 6.0 will apply authorization to `FORWARD` requests by default.
1504
+
1505
+
Consider the following common configuration:
1506
+
1507
+
====
1508
+
.Java
1509
+
[source,java,role="primary"]
1510
+
----
1511
+
@Bean
1512
+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
1513
+
http
1514
+
.authorizeHttpRequests((authorize) -> authorize
1515
+
.shouldFilterAllDispatcherTypes(true)
1516
+
.requestMatchers("/").authenticated()
1517
+
.anyRequest().denyAll()
1518
+
)
1519
+
.formLogin((form) -> form
1520
+
.loginPage("/login")
1521
+
.permitAll()
1522
+
));
1523
+
return http.build();
1524
+
}
1525
+
----
1526
+
====
1527
+
1528
+
and one of the following equivalents MVC view mapping configurations:
1529
+
1530
+
====
1531
+
.Java
1532
+
[source,java,role="primary"]
1533
+
----
1534
+
@Controller
1535
+
public class MyController {
1536
+
1537
+
@GetMapping("/login")
1538
+
public String login() {
1539
+
return "login";
1540
+
}
1541
+
1542
+
}
1543
+
----
1544
+
====
1545
+
1546
+
====
1547
+
.Java
1548
+
[source,java,role="primary"]
1549
+
----
1550
+
@Configuration
1551
+
public class MyWebMvcConfigurer implements WebMvcConfigurer {
1552
+
1553
+
@Override
1554
+
public void addViewControllers(ViewControllerRegistry registry) {
With either configuration, when there is a request to `/login`, Spring MVC will perform a *forward* to the view `login`, which, with the default configuration, is under `src/main/resources/templates/login.html` path.
1563
+
The security configuration permits requests to `/login` but every other request will be denied, including the `FORWARD` request to the view under `/templates/login.html`.
1564
+
1565
+
To fix this, you should configure Spring Security to permit `FORWARD` requests:
==== Replace any custom filter-security ``AccessDecisionManager``s
1468
1608
1469
1609
Your application may have a custom {security-api-url}org/springframework/security/access/AccessDecisionManager.html[`AccessDecisionManager`] or {security-api-url}org/springframework/security/access/AccessDecisionVoter.html[`AccessDecisionVoter`] arrangement.
0 commit comments