Skip to content

Commit

Permalink
Consider @crossorigin(originPatterns = …).
Browse files Browse the repository at this point in the history
RepositoryRestHandlerMapping's RepositoryCorsConfigurationAccessor now also evaluates @crossorigin's originPatterns into the CorsConfiguration.

Fixes #2077.
  • Loading branch information
odrotbohm committed Oct 19, 2021
1 parent 2cb176f commit ad3a1d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ private void updateCorsConfig(CorsConfiguration config, CrossOrigin annotation)
config.addExposedHeader(resolveCorsAnnotationValue(header));
}

for (String originPattern : annotation.originPatterns()) {
config.addAllowedOriginPattern(originPattern);
}

String allowCredentials = resolveCorsAnnotationValue(annotation.allowCredentials());

if ("true".equalsIgnoreCase(allowCredentials)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void createConfigurationShouldConstructCorsConfiguration() {
assertThat(configuration.getMaxAge()).isEqualTo(1800L);
}

@Test // DATAREST-573
@Test // DATAREST-573, #2077
void createConfigurationShouldConstructFullCorsConfiguration() {

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

@Test // DATAREST-994
Expand All @@ -105,6 +106,7 @@ interface AnnotatedRepository {}
allowedHeaders = "Content-type", //
maxAge = 1234, exposedHeaders = "Accept", //
methods = RequestMethod.PATCH, //
allowCredentials = "true")
allowCredentials = "true", //
originPatterns = "somePattern")
interface FullyConfiguredCorsRepository {}
}

0 comments on commit ad3a1d0

Please sign in to comment.