Skip to content

Commit 62d5ee5

Browse files
committed
Migrate to AuthorizationFilter in Spring Security auto-config
This commit updates Servlet based Spring Security auto-configuration to use AuthorizationFilter, which is intended to superseed FilterSecurityInterceptor.
1 parent c996e43 commit 62d5ee5

File tree

33 files changed

+48
-48
lines changed

33 files changed

+48
-48
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class ManagementWebSecurityAutoConfiguration {
5858
@Bean
5959
@Order(SecurityProperties.BASIC_AUTH_ORDER)
6060
SecurityFilterChain managementSecurityFilterChain(HttpSecurity http) throws Exception {
61-
http.authorizeRequests((requests) -> {
61+
http.authorizeHttpRequests((requests) -> {
6262
requests.requestMatchers(EndpointRequest.to(HealthEndpoint.class)).permitAll();
6363
requests.anyRequest().authenticated();
6464
});

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ org.springframework.security.config.annotation.web.configuration.WebSecurityConf
177177

178178
@Override
179179
protected void configure(HttpSecurity http) throws Exception {
180-
http.authorizeRequests((requests) -> {
180+
http.authorizeHttpRequests((requests) -> {
181181
requests.requestMatchers(EndpointRequest.toLinks()).permitAll();
182182
requests.requestMatchers(EndpointRequest.to(TestEndpoint1.class)).permitAll();
183183
requests.requestMatchers(EndpointRequest.toAnyEndpoint()).authenticated();

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static class CustomSecurityConfiguration
179179

180180
@Override
181181
protected void configure(HttpSecurity http) throws Exception {
182-
http.authorizeRequests((requests) -> {
182+
http.authorizeHttpRequests((requests) -> {
183183
requests.antMatchers("/foo").permitAll();
184184
requests.anyRequest().authenticated();
185185
});
@@ -194,7 +194,7 @@ static class TestSecurityFilterChainConfig {
194194

195195
@Bean
196196
SecurityFilterChain testSecurityFilterChain(HttpSecurity http) throws Exception {
197-
return http.antMatcher("/**").authorizeRequests((authorize) -> authorize.anyRequest().authenticated())
197+
return http.antMatcher("/**").authorizeHttpRequests((authorize) -> authorize.anyRequest().authenticated())
198198
.build();
199199
}
200200

@@ -206,8 +206,8 @@ static class TestRemoteDevToolsSecurityFilterChainConfig extends TestSecurityFil
206206
@Bean
207207
@Order(SecurityProperties.BASIC_AUTH_ORDER - 1)
208208
SecurityFilterChain testRemoteDevToolsSecurityFilterChain(HttpSecurity http) throws Exception {
209-
return http.requestMatcher(new AntPathRequestMatcher("/**")).authorizeRequests().anyRequest().anonymous()
210-
.and().csrf().disable().build();
209+
return http.requestMatcher(new AntPathRequestMatcher("/**")).authorizeHttpRequests().anyRequest()
210+
.hasRole("ROLE_ANONYMOUS").and().csrf().disable().build();
211211
}
212212

213213
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2WebSecurityConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static class OAuth2SecurityFilterChainConfiguration {
5858

5959
@Bean
6060
SecurityFilterChain oauth2SecurityFilterChain(HttpSecurity http) throws Exception {
61-
http.authorizeRequests((requests) -> requests.anyRequest().authenticated());
61+
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated());
6262
http.oauth2Login(Customizer.withDefaults());
6363
http.oauth2Client();
6464
return http.build();

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerJwtConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static class OAuth2SecurityFilterChainConfiguration {
135135
@Bean
136136
@ConditionalOnBean(JwtDecoder.class)
137137
SecurityFilterChain jwtSecurityFilterChain(HttpSecurity http) throws Exception {
138-
http.authorizeRequests((requests) -> requests.anyRequest().authenticated());
138+
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated());
139139
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
140140
return http.build();
141141
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerOpaqueTokenConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static class OAuth2SecurityFilterChainConfiguration {
6060
@Bean
6161
@ConditionalOnBean(OpaqueTokenIntrospector.class)
6262
SecurityFilterChain opaqueTokenSecurityFilterChain(HttpSecurity http) throws Exception {
63-
http.authorizeRequests((requests) -> requests.anyRequest().authenticated());
63+
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated());
6464
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::opaqueToken);
6565
return http.build();
6666
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Saml2LoginConfiguration {
3737

3838
@Bean
3939
SecurityFilterChain samlSecurityFilterChain(HttpSecurity http) throws Exception {
40-
http.authorizeRequests((requests) -> requests.anyRequest().authenticated()).saml2Login();
40+
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated()).saml2Login();
4141
http.saml2Logout();
4242
return http.build();
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static class SecurityFilterChainConfiguration {
6161
@Bean
6262
@Order(SecurityProperties.BASIC_AUTH_ORDER)
6363
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
64-
http.authorizeRequests().anyRequest().authenticated();
64+
http.authorizeHttpRequests().anyRequest().authenticated();
6565
http.formLogin();
6666
http.httpBasic();
6767
return http.build();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2WebSecurityConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static class TestSecurityFilterChainConfig {
241241

242242
@Bean
243243
SecurityFilterChain testSecurityFilterChain(HttpSecurity http) throws Exception {
244-
return http.antMatcher("/**").authorizeRequests((authorize) -> authorize.anyRequest().authenticated())
244+
return http.antMatcher("/**").authorizeHttpRequests((authorize) -> authorize.anyRequest().authenticated())
245245
.build();
246246

247247
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ static class TestSecurityFilterChainConfig {
659659

660660
@Bean
661661
SecurityFilterChain testSecurityFilterChain(HttpSecurity http) throws Exception {
662-
return http.antMatcher("/**").authorizeRequests((authorize) -> authorize.anyRequest().authenticated())
662+
return http.antMatcher("/**").authorizeHttpRequests((authorize) -> authorize.anyRequest().authenticated())
663663
.build();
664664
}
665665

0 commit comments

Comments
 (0)