mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-28 14:52:24 +00:00
Add Warning Message for Missing Leading Slashes
Closes gh-16020
This commit is contained in:
parent
1d32263a83
commit
8a6e1297a1
@ -199,6 +199,12 @@ public abstract class AbstractRequestMatcherRegistry<C> {
|
|||||||
* @since 5.8
|
* @since 5.8
|
||||||
*/
|
*/
|
||||||
public C requestMatchers(HttpMethod method, String... patterns) {
|
public C requestMatchers(HttpMethod method, String... patterns) {
|
||||||
|
if (anyPathsDontStartWithLeadingSlash(patterns)) {
|
||||||
|
this.logger.warn("One of the patterns in " + Arrays.toString(patterns)
|
||||||
|
+ " is missing a leading slash. This is discouraged; please include the "
|
||||||
|
+ "leading slash in all your request matcher patterns. In future versions of "
|
||||||
|
+ "Spring Security, leaving out the leading slash will result in an exception.");
|
||||||
|
}
|
||||||
if (!mvcPresent) {
|
if (!mvcPresent) {
|
||||||
return requestMatchers(RequestMatchers.antMatchersAsArray(method, patterns));
|
return requestMatchers(RequestMatchers.antMatchersAsArray(method, patterns));
|
||||||
}
|
}
|
||||||
@ -219,6 +225,15 @@ public abstract class AbstractRequestMatcherRegistry<C> {
|
|||||||
return requestMatchers(matchers.toArray(new RequestMatcher[0]));
|
return requestMatchers(matchers.toArray(new RequestMatcher[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean anyPathsDontStartWithLeadingSlash(String... patterns) {
|
||||||
|
for (String pattern : patterns) {
|
||||||
|
if (!pattern.startsWith("/")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private RequestMatcher resolve(AntPathRequestMatcher ant, MvcRequestMatcher mvc, ServletContext servletContext) {
|
private RequestMatcher resolve(AntPathRequestMatcher ant, MvcRequestMatcher mvc, ServletContext servletContext) {
|
||||||
Map<String, ? extends ServletRegistration> registrations = mappableServletRegistrations(servletContext);
|
Map<String, ? extends ServletRegistration> registrations = mappableServletRegistrations(servletContext);
|
||||||
if (registrations.isEmpty()) {
|
if (registrations.isEmpty()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user