Migrate to AuthorizationFilter in Spring Security auto-config
This commit updates Servlet based Spring Security auto-configuration to use AuthorizationFilter, which is intended to supersede FilterSecurityInterceptor. See gh-31255
This commit is contained in:
committed by
Andy Wilkinson
parent
5543fba57e
commit
230f2cda84
@@ -28,7 +28,7 @@ public class MySecurityConfiguration {
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.requestMatcher(EndpointRequest.toAnyEndpoint());
|
||||
http.authorizeRequests((requests) -> requests.anyRequest().permitAll());
|
||||
http.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll());
|
||||
return http.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class MySecurityConfiguration {
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.requestMatcher(EndpointRequest.toAnyEndpoint());
|
||||
http.authorizeRequests((requests) -> requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
|
||||
http.authorizeHttpRequests((requests) -> requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
|
||||
http.httpBasic(withDefaults());
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DevProfileSecurityConfiguration {
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
SecurityFilterChain h2ConsoleSecurityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.requestMatcher(PathRequest.toH2Console());
|
||||
http.authorizeRequests(yourCustomAuthorization());
|
||||
http.authorizeHttpRequests(yourCustomAuthorization());
|
||||
http.csrf((csrf) -> csrf.disable());
|
||||
http.headers((headers) -> headers.frameOptions().sameOrigin());
|
||||
return http.build();
|
||||
|
||||
@@ -30,7 +30,7 @@ public class MyConfiguration {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests((requests) -> requests.anyRequest().authenticated());
|
||||
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated());
|
||||
return http.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MySecurityConfiguration {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests((requests) -> requests.anyRequest().authenticated());
|
||||
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated());
|
||||
return http.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MyOAuthClientConfiguration {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests((requests) -> requests.anyRequest().authenticated());
|
||||
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated());
|
||||
http.oauth2Login((login) -> login.redirectionEndpoint().baseUri("custom-callback"));
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MySamlRelyingPartyConfiguration {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests().anyRequest().authenticated();
|
||||
http.authorizeHttpRequests().anyRequest().authenticated();
|
||||
http.saml2Login();
|
||||
http.saml2Logout((saml2) -> saml2.logoutRequest((request) -> request.logoutUrl("/SLOService.saml2"))
|
||||
.logoutResponse((response) -> response.logoutUrl("/SLOService.saml2")));
|
||||
|
||||
@@ -27,9 +27,9 @@ class MySecurityConfiguration {
|
||||
|
||||
@Bean
|
||||
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
|
||||
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests {
|
||||
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeHttpRequests {
|
||||
requests -> requests.anyRequest().permitAll() }
|
||||
return http.build()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ class MySecurityConfiguration {
|
||||
|
||||
@Bean
|
||||
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
|
||||
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests { requests ->
|
||||
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeHttpRequests { requests ->
|
||||
requests.anyRequest().hasRole("ENDPOINT_ADMIN")
|
||||
}
|
||||
http.httpBasic()
|
||||
return http.build()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class MyOAuthClientConfiguration {
|
||||
|
||||
@Bean
|
||||
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
|
||||
http.authorizeRequests().anyRequest().authenticated()
|
||||
http.authorizeHttpRequests().anyRequest().authenticated()
|
||||
http.oauth2Login().redirectionEndpoint().baseUri("custom-callback")
|
||||
return http.build()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user