Compare commits

..

No commits in common. "main" and "0.5.0" have entirely different histories.
main ... 0.5.0

5 changed files with 25 additions and 49 deletions

2
.gitignore vendored
View File

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

View File

@ -10,7 +10,7 @@
</parent>
<groupId>com.knecon.fforesight</groupId>
<artifactId>swagger-commons</artifactId>
<version>0.1-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<name>swagger-commons</name>
<description>swagger-commons</description>
<properties>

View File

@ -1,35 +0,0 @@
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,7 +40,6 @@ 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
@ -88,6 +87,23 @@ 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() {
@ -119,18 +135,16 @@ public class SpringDocConfiguration {
private OAuthFlows createOAuthFlows(SpringDocProperties springDocProperties) {
var codeFlow = new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth")
.tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token");
OAuthFlow flow = createAuthorizationCodeFlow(springDocProperties);
var flows = new OAuthFlows().authorizationCode(codeFlow);
return new OAuthFlows().authorizationCode(flow);
}
if (springDocProperties.isShowImplicitFlow()) {
var implicitFlow = new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth")
.tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token");
flows.implicit(implicitFlow);
}
return flows;
private OAuthFlow createAuthorizationCodeFlow(SpringDocProperties springDocProperties) {
return new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/auth")
.tokenUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/token");
}
}

View File

@ -23,7 +23,6 @@ public class SpringDocProperties {
private String title ="Service Open API Documentation";
private String description ="Service Open API Documentation";
private String version = "1.0";
private boolean showImplicitFlow = true;
private List<String> packagesToScan = new ArrayList<>();