Skip to content

Commit f4cf722

Browse files
committed
Align default security filter dispatcher types with Spring Security
Fixes gh-33090
1 parent d34ccb3 commit f4cf722

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public static class Filter {
8383
/**
8484
* Security filter chain dispatcher types.
8585
*/
86-
private Set<DispatcherType> dispatcherTypes = new HashSet<>(
87-
Arrays.asList(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST));
86+
private Set<DispatcherType> dispatcherTypes = new HashSet<>(Arrays.asList(DispatcherType.ASYNC,
87+
DispatcherType.ERROR, DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE));
8888

8989
public int getOrder() {
9090
return this.order;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ void defaultFilterDispatcherTypes() {
161161
DelegatingFilterProxyRegistrationBean.class);
162162
assertThat(bean)
163163
.extracting("dispatcherTypes", InstanceOfAssertFactories.iterable(DispatcherType.class))
164-
.containsOnly(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST);
164+
.containsOnly(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST,
165+
DispatcherType.INCLUDE, DispatcherType.FORWARD);
165166
});
166167
}
167168

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/java/smoketest/security/method/SampleMethodSecurityApplication.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package smoketest.security.method;
1818

19+
import jakarta.servlet.DispatcherType;
20+
1921
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
2022
import org.springframework.boot.autoconfigure.SpringBootApplication;
2123
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -71,7 +73,10 @@ protected static class ApplicationSecurity {
7173
@Bean
7274
SecurityFilterChain configure(HttpSecurity http) throws Exception {
7375
http.csrf().disable();
74-
http.authorizeHttpRequests((requests) -> requests.anyRequest().fullyAuthenticated());
76+
http.authorizeHttpRequests((requests) -> {
77+
requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll();
78+
requests.anyRequest().fullyAuthenticated();
79+
});
7580
http.httpBasic();
7681
http.formLogin((form) -> form.loginPage("/login").permitAll());
7782
http.exceptionHandling((exceptions) -> exceptions.accessDeniedPage("/access"));

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/java/smoketest/web/secure/custom/SampleWebSecureCustomApplication.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package smoketest.web.secure.custom;
1818

19+
import jakarta.servlet.DispatcherType;
20+
1921
import org.springframework.boot.autoconfigure.SpringBootApplication;
2022
import org.springframework.boot.builder.SpringApplicationBuilder;
2123
import org.springframework.context.annotation.Bean;
@@ -44,7 +46,10 @@ protected static class ApplicationSecurity {
4446
@Bean
4547
SecurityFilterChain configure(HttpSecurity http) throws Exception {
4648
http.csrf().disable();
47-
http.authorizeHttpRequests((requests) -> requests.anyRequest().fullyAuthenticated());
49+
http.authorizeHttpRequests((requests) -> {
50+
requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll();
51+
requests.anyRequest().fullyAuthenticated();
52+
});
4853
http.formLogin((form) -> form.loginPage("/login").permitAll());
4954
return http.build();
5055
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplication.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import javax.sql.DataSource;
2020

21+
import jakarta.servlet.DispatcherType;
22+
2123
import org.springframework.boot.autoconfigure.SpringBootApplication;
2224
import org.springframework.boot.builder.SpringApplicationBuilder;
2325
import org.springframework.context.annotation.Bean;
@@ -47,7 +49,10 @@ protected static class ApplicationSecurity {
4749
@Bean
4850
SecurityFilterChain configure(HttpSecurity http) throws Exception {
4951
http.csrf().disable();
50-
http.authorizeHttpRequests((requests) -> requests.anyRequest().fullyAuthenticated());
52+
http.authorizeHttpRequests((requests) -> {
53+
requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll();
54+
requests.anyRequest().fullyAuthenticated();
55+
});
5156
http.formLogin((form) -> form.loginPage("/login").permitAll());
5257
return http.build();
5358
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleWebSecureApplicationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Collections;
2020

21+
import jakarta.servlet.DispatcherType;
2122
import org.junit.jupiter.api.Test;
2223

2324
import org.springframework.beans.factory.annotation.Autowired;
@@ -97,6 +98,7 @@ SecurityFilterChain configure(HttpSecurity http) throws Exception {
9798
http.csrf().disable();
9899
http.authorizeHttpRequests((requests) -> {
99100
requests.requestMatchers("/public/**").permitAll();
101+
requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll();
100102
requests.anyRequest().fullyAuthenticated();
101103
});
102104
http.httpBasic();

0 commit comments

Comments
 (0)