Skip to content

Commit 38a9aa1

Browse files
committed
Remove Deprecated PathMatchConfigurer usage
Closes gh-17052
1 parent 222faae commit 38a9aa1

12 files changed

+4
-419
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/builders/WebSecurityTests.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
import org.springframework.web.bind.annotation.RestController;
4848
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4949
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
50-
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
51-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
5250
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
5351

5452
import static org.assertj.core.api.Assertions.assertThat;
@@ -84,26 +82,6 @@ public void cleanup() {
8482
}
8583
}
8684

87-
@Test
88-
public void ignoringMvcMatcher() throws Exception {
89-
loadConfig(MvcMatcherConfig.class, LegacyMvcMatchingConfig.class);
90-
this.request.setRequestURI("/path");
91-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
92-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
93-
setup();
94-
this.request.setRequestURI("/path.html");
95-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
96-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
97-
setup();
98-
this.request.setRequestURI("/path/");
99-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
100-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
101-
setup();
102-
this.request.setRequestURI("/other");
103-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
104-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
105-
}
106-
10785
@Test
10886
public void requestRejectedHandlerInvoked() throws ServletException, IOException {
10987
loadConfig(DefaultConfig.class);
@@ -132,30 +110,6 @@ public void requestRejectedHandlerInvokedWhenOperationalObservationRegistry() th
132110
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
133111
}
134112

135-
@Test
136-
public void ignoringMvcMatcherServletPath() throws Exception {
137-
loadConfig(MvcMatcherServletPathConfig.class, LegacyMvcMatchingConfig.class);
138-
this.request.setServletPath("/spring");
139-
this.request.setRequestURI("/spring/path");
140-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
141-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
142-
setup();
143-
this.request.setServletPath("/spring");
144-
this.request.setRequestURI("/spring/path.html");
145-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
146-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
147-
setup();
148-
this.request.setServletPath("/spring");
149-
this.request.setRequestURI("/spring/path/");
150-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
151-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
152-
setup();
153-
this.request.setServletPath("/other");
154-
this.request.setRequestURI("/other/path");
155-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
156-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
157-
}
158-
159113
public void loadConfig(Class<?>... configs) {
160114
this.context = new AnnotationConfigWebApplicationContext();
161115
this.context.register(configs);
@@ -246,17 +200,6 @@ String path() {
246200

247201
}
248202

249-
@Configuration
250-
static class LegacyMvcMatchingConfig implements WebMvcConfigurer {
251-
252-
@Override
253-
public void configurePathMatch(PathMatchConfigurer configurer) {
254-
configurer.setUseSuffixPatternMatch(true);
255-
configurer.setUseTrailingSlashMatch(true);
256-
}
257-
258-
}
259-
260203
@Configuration
261204
@EnableWebSecurity
262205
static class RequestRejectedHandlerConfig {

config/src/test/java/org/springframework/security/config/annotation/web/configurers/AuthorizeRequestsTests.java

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
import org.springframework.web.bind.annotation.RestController;
4949
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
5050
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
51-
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
52-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
5351
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
5452

5553
import static org.assertj.core.api.Assertions.assertThat;
@@ -160,67 +158,6 @@ public void roleHiearchy() throws Exception {
160158
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
161159
}
162160

163-
@Test
164-
public void mvcMatcher() throws Exception {
165-
loadConfig(MvcMatcherConfig.class, LegacyMvcMatchingConfig.class);
166-
this.request.setRequestURI("/path");
167-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
168-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
169-
setup();
170-
this.request.setRequestURI("/path.html");
171-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
172-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
173-
setup();
174-
this.request.setServletPath("/path/");
175-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
176-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
177-
}
178-
179-
@Test
180-
public void requestWhenMvcMatcherDenyAllThenRespondsWithUnauthorized() throws Exception {
181-
loadConfig(MvcMatcherInLambdaConfig.class, LegacyMvcMatchingConfig.class);
182-
this.request.setRequestURI("/path");
183-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
184-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
185-
setup();
186-
this.request.setRequestURI("/path.html");
187-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
188-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
189-
setup();
190-
this.request.setServletPath("/path/");
191-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
192-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
193-
}
194-
195-
@Test
196-
public void requestWhenMvcMatcherServletPathDenyAllThenMatchesOnServletPath() throws Exception {
197-
loadConfig(MvcMatcherServletPathInLambdaConfig.class, LegacyMvcMatchingConfig.class);
198-
this.request.setServletPath("/spring");
199-
this.request.setRequestURI("/spring/path");
200-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
201-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
202-
setup();
203-
this.request.setServletPath("/spring");
204-
this.request.setRequestURI("/spring/path.html");
205-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
206-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
207-
setup();
208-
this.request.setServletPath("/spring");
209-
this.request.setRequestURI("/spring/path/");
210-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
211-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
212-
setup();
213-
this.request.setServletPath("/foo");
214-
this.request.setRequestURI("/foo/path");
215-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
216-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
217-
setup();
218-
this.request.setServletPath("/");
219-
this.request.setRequestURI("/path");
220-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
221-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
222-
}
223-
224161
@Test
225162
public void mvcMatcherPathVariables() throws Exception {
226163
loadConfig(MvcMatcherPathVariablesConfig.class);
@@ -245,35 +182,6 @@ public void requestWhenMvcMatcherPathVariablesThenMatchesOnPathVariables() throw
245182
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
246183
}
247184

248-
@Test
249-
public void mvcMatcherServletPath() throws Exception {
250-
loadConfig(MvcMatcherServletPathConfig.class, LegacyMvcMatchingConfig.class);
251-
this.request.setServletPath("/spring");
252-
this.request.setRequestURI("/spring/path");
253-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
254-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
255-
setup();
256-
this.request.setServletPath("/spring");
257-
this.request.setRequestURI("/spring/path.html");
258-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
259-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
260-
setup();
261-
this.request.setServletPath("/spring");
262-
this.request.setRequestURI("/spring/path/");
263-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
264-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
265-
setup();
266-
this.request.setServletPath("/foo");
267-
this.request.setRequestURI("/foo/path");
268-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
269-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
270-
setup();
271-
this.request.setServletPath("/");
272-
this.request.setRequestURI("/path");
273-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
274-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
275-
}
276-
277185
public void loadConfig(Class<?>... configs) {
278186
this.context = new AnnotationConfigWebApplicationContext();
279187
this.context.register(configs);
@@ -639,15 +547,4 @@ String path() {
639547

640548
}
641549

642-
@Configuration
643-
static class LegacyMvcMatchingConfig implements WebMvcConfigurer {
644-
645-
@Override
646-
public void configurePathMatch(PathMatchConfigurer configurer) {
647-
configurer.setUseSuffixPatternMatch(true);
648-
configurer.setUseTrailingSlashMatch(true);
649-
}
650-
651-
}
652-
653550
}

config/src/test/java/org/springframework/security/config/annotation/web/configurers/HttpSecurityRequestMatchersTests.java

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
import org.springframework.web.bind.annotation.RestController;
4242
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4343
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
44-
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
45-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
4644
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
4745

4846
import static org.assertj.core.api.Assertions.assertThat;
@@ -80,60 +78,12 @@ public void cleanup() {
8078
}
8179
}
8280

83-
@Test
84-
public void mvcMatcher() throws Exception {
85-
loadConfig(MvcMatcherConfig.class, LegacyMvcMatchingConfig.class);
86-
this.request.setServletPath("/path");
87-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
88-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
89-
setup();
90-
this.request.setServletPath("/path.html");
91-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
92-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
93-
setup();
94-
this.request.setServletPath("/path/");
95-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
96-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
97-
}
98-
9981
@Test
10082
public void mvcMatcherGetFiltersNoUnsupportedMethodExceptionFromDummyRequest() {
10183
loadConfig(MvcMatcherConfig.class);
10284
assertThat(this.springSecurityFilterChain.getFilters("/path")).isNotEmpty();
10385
}
10486

105-
@Test
106-
public void requestMatchersMvcMatcher() throws Exception {
107-
loadConfig(RequestMatchersMvcMatcherConfig.class, LegacyMvcMatchingConfig.class);
108-
this.request.setServletPath("/path");
109-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
110-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
111-
setup();
112-
this.request.setServletPath("/path.html");
113-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
114-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
115-
setup();
116-
this.request.setServletPath("/path/");
117-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
118-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
119-
}
120-
121-
@Test
122-
public void requestMatchersWhenMvcMatcherInLambdaThenPathIsSecured() throws Exception {
123-
loadConfig(RequestMatchersMvcMatcherInLambdaConfig.class, LegacyMvcMatchingConfig.class);
124-
this.request.setServletPath("/path");
125-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
126-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
127-
setup();
128-
this.request.setServletPath("/path.html");
129-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
130-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
131-
setup();
132-
this.request.setServletPath("/path/");
133-
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
134-
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
135-
}
136-
13787
@Test
13888
public void requestMatchersMvcMatcherServletPath() throws Exception {
13989
loadConfig(RequestMatchersMvcMatcherServeltPathConfig.class);
@@ -491,15 +441,4 @@ String path() {
491441

492442
}
493443

494-
@Configuration
495-
static class LegacyMvcMatchingConfig implements WebMvcConfigurer {
496-
497-
@Override
498-
public void configurePathMatch(PathMatchConfigurer configurer) {
499-
configurer.setUseSuffixPatternMatch(true);
500-
configurer.setUseTrailingSlashMatch(true);
501-
}
502-
503-
}
504-
505444
}

0 commit comments

Comments
 (0)