Skip to content

DATAREST-1397 - Adapt to CORS changes in AbstractHandlerMapping #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-parent</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data REST</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-rest-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-parent</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-rest-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-parent</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-rest-hal-browser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-parent</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
</parent>

<artifactId>spring-data-rest-hal-browser</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-rest-hal-explorer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-parent</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
</parent>

<artifactId>spring-data-rest-hal-explorer</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-rest-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-parent</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-rest-tests/spring-data-rest-tests-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -17,7 +17,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-rest-tests/spring-data-rest-tests-gemfire/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -17,7 +17,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests-core</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<type>test-jar</type>
</dependency>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-rest-tests/spring-data-rest-tests-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests-core</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<type>test-jar</type>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
import org.springframework.web.bind.annotation.RequestMethod;

/**
* Web integration tests specific to Cross-origin resource sharing.
* Web integration tests specific to Cross-origin resource sharing applying global CORS config defaults mixed with local
* controller/repository declarations.
*
* @author Mark Paluch
* @soundtrack 2 Unlimited - No Limit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.rest.webmvc.jpa;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import org.junit.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkRelation;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.ContextConfiguration;

/**
* Web integration tests specific to Cross-origin resource sharing using repository interface CORS configuration.
*
* @author Mark Paluch
* @soundtrack RFLKTD - Liquid Crystals
*/
@ContextConfiguration
public class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests {

static class CorsConfig extends JpaRepositoryConfig {

@Bean
RepositoryRestConfigurer repositoryRestConfigurer() {
return RepositoryRestConfigurer.withConfig(c -> {});
}
}

/**
* @see ItemRepository
*/
@Test // DATAREST-1397
public void appliesRepositoryCorsConfiguration() throws Exception {

Link findItems = client.discoverUnique(LinkRelation.of("items"));

// Preflight request
mvc.perform(options(findItems.expand().getHref()).header(HttpHeaders.ORIGIN, "http://far.far.example")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) //
.andExpect(status().isOk()) //
.andExpect(
header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS,TRACE"));
}
}
4 changes: 2 additions & 2 deletions spring-data-rest-tests/spring-data-rest-tests-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -17,7 +17,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests-core</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<type>test-jar</type>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests-core</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<type>test-jar</type>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-rest-tests/spring-data-rest-tests-shop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
</parent>

<name>Spring Data REST Tests - Shop</name>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-rest-tests/spring-data-rest-tests-solr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
</parent>

<name>Spring Data REST Tests - Solr</name>
Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-tests-core</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<type>test-jar</type>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-rest-webmvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-parent</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
<version>3.2.0.DATAREST-1397-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletReques
return super.lookupHandlerMethod(lookupPath, new CustomAcceptHeaderHttpServletRequest(request, mediaTypes));
}

/*
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.AbstractHandlerMapping#hasCorsConfigurationSource(java.lang.Object)
*/
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return true;
}

/*
* (non-Javadoc)
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#getMappingForMethod(java.lang.reflect.Method, java.lang.Class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ protected boolean isHandler(Class<?> beanType) {
return AnnotationUtils.findAnnotation(type, RepositoryRestController.class) != null;
}

/*
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.AbstractHandlerMapping#hasCorsConfigurationSource(java.lang.Object)
*/
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return true;
}

/*
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.AbstractHandlerMapping#extendInterceptors(java.util.List)
Expand Down