1
0
mirror of synced 2026-05-22 13:23:17 +00:00

Remove deprecated RequestMatcher methods from Java Configuration

Closes gh-11939
This commit is contained in:
Marcus Da Coregio
2022-10-05 13:29:47 -03:00
parent 9fd195d419
commit 398f5dee7f
57 changed files with 382 additions and 1308 deletions
@@ -35,6 +35,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated;
@@ -111,6 +112,7 @@ public class Sec2935Tests {
@EnableWebSecurity
@Configuration
@EnableWebMvc
static class Config {
@Bean
@@ -118,7 +120,7 @@ public class Sec2935Tests {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.httpBasic();
@@ -153,7 +153,7 @@ public class SecurityMockMvcRequestPostProcessorsOAuth2LoginTests {
// @formatter:off
http
.authorizeRequests((authorize) -> authorize
.mvcMatchers("/admin/**").hasAuthority("SCOPE_admin")
.requestMatchers("/admin/**").hasAuthority("SCOPE_admin")
.anyRequest().hasAuthority("SCOPE_read")
).oauth2Login();
return http.build();
@@ -155,7 +155,7 @@ public class SecurityMockMvcRequestPostProcessorsOidcLoginTests {
// @formatter:off
http
.authorizeRequests()
.mvcMatchers("/admin/**").hasAuthority("SCOPE_admin")
.requestMatchers("/admin/**").hasAuthority("SCOPE_admin")
.anyRequest().hasAuthority("SCOPE_read")
.and()
.oauth2Login();
@@ -127,7 +127,7 @@ public class SecurityMockMvcRequestPostProcessorsOpaqueTokenTests {
// @formatter:off
http
.authorizeRequests()
.mvcMatchers("/admin/**").hasAuthority("SCOPE_admin")
.requestMatchers("/admin/**").hasAuthority("SCOPE_admin")
.anyRequest().hasAuthority("SCOPE_read")
.and()
.oauth2ResourceServer()
@@ -99,7 +99,7 @@ public class Gh3409Tests {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/public/**").permitAll()
.requestMatchers("/public/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().and()
@@ -96,7 +96,7 @@ public class DefaultfSecurityRequestsTests {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.httpBasic();
@@ -113,7 +113,7 @@ public class SecurityRequestsTests {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin();
@@ -97,7 +97,7 @@ public class WithUserAuthenticationTests {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin();
@@ -97,7 +97,7 @@ public class WithUserClassLevelAuthenticationTests {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.httpBasic();
@@ -88,7 +88,7 @@ public class WithUserDetailsAuthenticationTests {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin();
@@ -87,7 +87,7 @@ public class WithUserDetailsClassLevelAuthenticationTests {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin();
@@ -40,6 +40,7 @@ import org.springframework.security.web.context.SecurityContextRepository;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
@@ -225,7 +226,7 @@ public class WebTestUtilsTests {
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// @formatter:off
http
.antMatcher("/willnotmatchthis");
.securityMatcher(new AntPathRequestMatcher("/willnotmatchthis"));
return http.build();
// @formatter:on
}