diff --git a/.gitignore b/.gitignore index 549e00a..130a092 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ build/ ### VS Code ### .vscode/ +.DS_Store/ +.DS_Store diff --git a/src/main/java/com/knecon/fforesight/swaggercommons/CorsConfigurer.java b/src/main/java/com/knecon/fforesight/swaggercommons/CorsConfigurer.java new file mode 100644 index 0000000..a264ad2 --- /dev/null +++ b/src/main/java/com/knecon/fforesight/swaggercommons/CorsConfigurer.java @@ -0,0 +1,35 @@ +package com.knecon.fforesight.swaggercommons; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +public class CorsConfigurer implements WebMvcConfigurer { + + private final boolean corsEnabled; + + + @Autowired + public CorsConfigurer(@Value("${cors.enabled:false}") boolean corsEnabled) { + + this.corsEnabled = corsEnabled; + } + + + @Override + public void addCorsMappings(CorsRegistry registry) { + + if (corsEnabled) { + log.info("Cross Origin Requests are enabled !!!"); + registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "DELETE", "PUT", "HEAD"); + } + + } + +} diff --git a/src/main/java/com/knecon/fforesight/swaggercommons/SpringDocConfiguration.java b/src/main/java/com/knecon/fforesight/swaggercommons/SpringDocConfiguration.java index 52c102e..6b66c49 100644 --- a/src/main/java/com/knecon/fforesight/swaggercommons/SpringDocConfiguration.java +++ b/src/main/java/com/knecon/fforesight/swaggercommons/SpringDocConfiguration.java @@ -40,6 +40,7 @@ import io.swagger.v3.oas.models.security.OAuthFlow; import io.swagger.v3.oas.models.security.OAuthFlows; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; +import lombok.Value; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -87,23 +88,6 @@ public class SpringDocConfiguration { } - @Bean - @ConditionalOnProperty(value = "cors.enabled", havingValue = "true") - public WebMvcConfigurer corsConfigurer() { - - return new WebMvcConfigurer() { - - @Override - public void addCorsMappings(CorsRegistry registry) { - - log.info("Cross Origin Requests are enabled !!!"); - registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "DELETE", "PUT", "HEAD"); - - } - }; - } - - @Bean public CorsConfigurationSource corsConfigurationSource() { @@ -143,8 +127,8 @@ public class SpringDocConfiguration { private OAuthFlow createAuthorizationCodeFlow(SpringDocProperties springDocProperties) { - return new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/auth") - .tokenUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/token"); + return new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth") + .tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token"); } }