DATAREST-1332 - Fixed regression in CORS request handling.
The lookup of the RequestMappingInfo in exposeEffectiveLookupPathKey(…) yields null for CORS preflight requests to resources that do not support OPTIONAL explicitly. We now guard against that to avoid a subsequent NullPointerException.
This commit is contained in:
@@ -261,6 +261,11 @@ public class RepositoryRestHandlerMapping extends BasePathAwareHandlerMapping {
|
||||
String repositoryBasePath) {
|
||||
|
||||
RequestMappingInfo mappingInfo = getMappingForMethod(method.getMethod(), method.getBeanType());
|
||||
|
||||
if (mappingInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String pattern = mappingInfo.getPatternsCondition() //
|
||||
.getMatchingCondition(request)//
|
||||
.getPatterns() //
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -287,6 +288,21 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAREST-1332
|
||||
public void handlesCorsPreflightRequestsProperly() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/people/search");
|
||||
request.addHeader(HttpHeaders.ORIGIN, "test case");
|
||||
request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
|
||||
|
||||
handlerMapping.afterPropertiesSet();
|
||||
|
||||
assertThatCode(() -> handlerMapping.lookupHandlerMethod("/people/search", request)) //
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
private static Class<?> createProxy(Object source) {
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(source);
|
||||
|
||||
Reference in New Issue
Block a user