|
@@ -48,8 +48,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
-import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
|
|
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
@@ -160,67 +158,6 @@ public class AuthorizeRequestsTests {
|
|
|
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void mvcMatcher() throws Exception {
|
|
|
- loadConfig(MvcMatcherConfig.class, LegacyMvcMatchingConfig.class);
|
|
|
- this.request.setRequestURI("/path");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setRequestURI("/path.html");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/path/");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void requestWhenMvcMatcherDenyAllThenRespondsWithUnauthorized() throws Exception {
|
|
|
- loadConfig(MvcMatcherInLambdaConfig.class, LegacyMvcMatchingConfig.class);
|
|
|
- this.request.setRequestURI("/path");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setRequestURI("/path.html");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/path/");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void requestWhenMvcMatcherServletPathDenyAllThenMatchesOnServletPath() throws Exception {
|
|
|
- loadConfig(MvcMatcherServletPathInLambdaConfig.class, LegacyMvcMatchingConfig.class);
|
|
|
- this.request.setServletPath("/spring");
|
|
|
- this.request.setRequestURI("/spring/path");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/spring");
|
|
|
- this.request.setRequestURI("/spring/path.html");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/spring");
|
|
|
- this.request.setRequestURI("/spring/path/");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/foo");
|
|
|
- this.request.setRequestURI("/foo/path");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/");
|
|
|
- this.request.setRequestURI("/path");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
|
|
|
- }
|
|
|
-
|
|
|
@Test
|
|
|
public void mvcMatcherPathVariables() throws Exception {
|
|
|
loadConfig(MvcMatcherPathVariablesConfig.class);
|
|
@@ -245,35 +182,6 @@ public class AuthorizeRequestsTests {
|
|
|
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void mvcMatcherServletPath() throws Exception {
|
|
|
- loadConfig(MvcMatcherServletPathConfig.class, LegacyMvcMatchingConfig.class);
|
|
|
- this.request.setServletPath("/spring");
|
|
|
- this.request.setRequestURI("/spring/path");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/spring");
|
|
|
- this.request.setRequestURI("/spring/path.html");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/spring");
|
|
|
- this.request.setRequestURI("/spring/path/");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/foo");
|
|
|
- this.request.setRequestURI("/foo/path");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
|
|
|
- setup();
|
|
|
- this.request.setServletPath("/");
|
|
|
- this.request.setRequestURI("/path");
|
|
|
- this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
|
|
- assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
|
|
|
- }
|
|
|
-
|
|
|
public void loadConfig(Class<?>... configs) {
|
|
|
this.context = new AnnotationConfigWebApplicationContext();
|
|
|
this.context.register(configs);
|
|
@@ -639,15 +547,4 @@ public class AuthorizeRequestsTests {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @Configuration
|
|
|
- static class LegacyMvcMatchingConfig implements WebMvcConfigurer {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void configurePathMatch(PathMatchConfigurer configurer) {
|
|
|
- configurer.setUseSuffixPatternMatch(true);
|
|
|
- configurer.setUseTrailingSlashMatch(true);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
}
|