Merge branch 'graal-vm-conditional-adaptation' into 'main'

GraalVM for cors

See merge request fforesight/swagger-commons!1
This commit is contained in:
Timo Bejan 2023-08-30 10:14:11 +02:00
commit c88c7851f9
3 changed files with 40 additions and 19 deletions

2
.gitignore vendored
View File

@ -31,3 +31,5 @@ build/
### VS Code ###
.vscode/
.DS_Store/
.DS_Store

View File

@ -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");
}
}
}

View File

@ -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");
}
}