Skip to content

Commit

Permalink
added cors
Browse files Browse the repository at this point in the history
  • Loading branch information
mschulte-tsi committed Jul 8, 2021
1 parent 55f3adf commit 936e373
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/eu/europa/ec/dgc/businessrule/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package eu.europa.ec.dgc.businessrule.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebSecurity
public class CorsConfig implements WebMvcConfigurer {

@Bean
CorsConfigurationSource corsConfigurationSource(DgcConfigProperties dgcConfigProperties) {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration().applyPermitDefaultValues();
corsConfiguration.addAllowedOrigin(dgcConfigProperties.getCorsUrl());
source.registerCorsConfiguration("/**",corsConfiguration);
return source;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class DgcConfigProperties {

private final GatewayDownload countryListDownload = new GatewayDownload();

private final String corsUrl = new String();

@Getter
@Setter
public static class GatewayDownload {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ springdoc:
api-docs:
enabled: false
dgc:
corsUrl: ${DGC_CORS_ENABLED_URL}
gateway:
connector:
enabled: true
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ springdoc:
swagger-ui:
path: /swagger
dgc:
corsUrl: https://dgc-gateway.example.com
businessRulesDownload:
timeInterval: 1800000
lockLimit: 3600000
Expand Down

0 comments on commit 936e373

Please sign in to comment.