Skip to content

Commit 6a6c173

Browse files
committed
Consider @crossorigin(originPatterns = …).
RepositoryRestHandlerMapping's RepositoryCorsConfigurationAccessor now also evaluates @crossorigin's originPatterns into the CorsConfiguration. Fixes #2077.
1 parent 7f0b6d4 commit 6a6c173

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ private void updateCorsConfig(CorsConfiguration config, CrossOrigin annotation)
394394
config.addExposedHeader(resolveCorsAnnotationValue(header));
395395
}
396396

397+
for (String originPattern : annotation.originPatterns()) {
398+
config.addAllowedOriginPattern(originPattern);
399+
}
400+
397401
String allowCredentials = resolveCorsAnnotationValue(annotation.allowCredentials());
398402

399403
if ("true".equalsIgnoreCase(allowCredentials)) {

spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryCorsConfigurationAccessorUnitTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void createConfigurationShouldConstructCorsConfiguration() {
7070
assertThat(configuration.getMaxAge()).isEqualTo(1800L);
7171
}
7272

73-
@Test // DATAREST-573
73+
@Test // DATAREST-573, #2077
7474
void createConfigurationShouldConstructFullCorsConfiguration() {
7575

7676
CorsConfiguration configuration = accessor.createConfiguration(FullyConfiguredCorsRepository.class);
@@ -84,6 +84,7 @@ void createConfigurationShouldConstructFullCorsConfiguration() {
8484
assertThat(configuration.getAllowedMethods()).doesNotContain("DELETE");
8585
assertThat(configuration.getAllowCredentials()).isTrue();
8686
assertThat(configuration.getMaxAge()).isEqualTo(1234L);
87+
assertThat(configuration.getAllowedOriginPatterns()).containsExactly("somePattern");
8788
}
8889

8990
@Test // DATAREST-994
@@ -105,6 +106,7 @@ interface AnnotatedRepository {}
105106
allowedHeaders = "Content-type", //
106107
maxAge = 1234, exposedHeaders = "Accept", //
107108
methods = RequestMethod.PATCH, //
108-
allowCredentials = "true")
109+
allowCredentials = "true", //
110+
originPatterns = "somePattern")
109111
interface FullyConfiguredCorsRepository {}
110112
}

0 commit comments

Comments
 (0)