From eeee271b368966ebb1847ae3384b9d1c02458a36 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 7 May 2021 22:05:32 +0200 Subject: [PATCH] DelegatingHandlerMapping now fully implements MatchingHandlerMapping correctly. We now also implement MatchableHandlerMapping.getPatternParser() to expose the PathPatternParser we use. This is needed to detect that DelegatingHandlerMapping uses a PathPatternParser from the outside as the Spring MVC request processing pipeline treats those HandlerMappings in a special way. This is especially important in the context of spring-projects/spring-framework#26814 as that makes the HM implementations work properly in CORS preflight requests. When used with Spring Security in place, CORS preflight requests are inspected through the HandlerMappingIntrospector, that looks up the CORS configuration for the handler to serve the actual request. That lookup previously failed as Spring MVC was unable to detect that Spring Data REST's DelegatingHandlerMapping works with a PathPatternParser and didn't properly set up the processing pipeline to eventually end up in an invalid state, produce an exception that caused the handler method lookup to fail and cause Spring Security to fail with a 403, claiming the request was invalid. Fixes #2007, #2054. --- .../webmvc/config/DelegatingHandlerMapping.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/DelegatingHandlerMapping.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/DelegatingHandlerMapping.java index d5f7fcbdf..932d77d0d 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/DelegatingHandlerMapping.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/DelegatingHandlerMapping.java @@ -69,6 +69,20 @@ class DelegatingHandlerMapping return parser != null; } + /* + * (non-Javadoc) + * @see org.springframework.web.servlet.handler.MatchableHandlerMapping#getPatternParser() + */ + @Nullable + @Override + public PathPatternParser getPatternParser() { + return parser; + } + + /* + * (non-Javadoc) + * @see org.springframework.data.rest.webmvc.support.DelegatingHandlerMapping#getDelegates() + */ @SuppressWarnings("all") public List getDelegates() { return this.delegates;