Skip to content

Commit 8223577

Browse files
committed
Pick Mvc When No Servlets
Issue spring-projectsgh-13849
1 parent 7d38686 commit 8223577

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -355,7 +355,7 @@ private static boolean isProgrammaticApiAvailable(ServletContext servletContext)
355355
private RequestMatcher resolve(AntPathRequestMatcher ant, MvcRequestMatcher mvc, ServletContext servletContext) {
356356
Map<String, ? extends ServletRegistration> registrations = mappableServletRegistrations(servletContext);
357357
if (registrations.isEmpty()) {
358-
return ant;
358+
return mvc;
359359
}
360360
if (!hasDispatcherServlet(registrations)) {
361361
return ant;

config/src/test/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherRegistryTests.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -212,12 +212,20 @@ public void requestMatchersWhenNoDispatcherServletThenAntPathRequestMatcherType(
212212
assertThat(requestMatchers).isNotEmpty();
213213
assertThat(requestMatchers).hasSize(1);
214214
assertThat(requestMatchers.get(0)).isExactlyInstanceOf(AntPathRequestMatcher.class);
215+
}
216+
217+
// gh-13849
218+
@Test
219+
public void requestMatchersWhenNoMappableServletsThenMvcRequestMatcherType() {
220+
mockMvcIntrospector(true);
221+
MockServletContext servletContext = new MockServletContext();
222+
given(this.context.getServletContext()).willReturn(servletContext);
215223
servletContext.addServlet("servletOne", Servlet.class);
216224
servletContext.addServlet("servletTwo", Servlet.class);
217-
requestMatchers = this.matcherRegistry.requestMatchers("/**");
225+
List<RequestMatcher> requestMatchers = this.matcherRegistry.requestMatchers("/**");
218226
assertThat(requestMatchers).isNotEmpty();
219227
assertThat(requestMatchers).hasSize(1);
220-
assertThat(requestMatchers.get(0)).isExactlyInstanceOf(AntPathRequestMatcher.class);
228+
assertThat(requestMatchers.get(0)).isExactlyInstanceOf(MvcRequestMatcher.class);
221229
}
222230

223231
@Test

0 commit comments

Comments
 (0)