Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48696d0374 | ||
|
|
77a5b81b2c | ||
|
|
c88c7851f9 | ||
|
|
b5510f5294 | ||
|
|
7854148cef | ||
|
|
6ce7b9dd5c | ||
|
|
dbf77adab4 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -31,3 +31,5 @@ build/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.DS_Store/
|
||||||
|
.DS_Store
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>com.knecon.fforesight</groupId>
|
<groupId>com.knecon.fforesight</groupId>
|
||||||
<artifactId>swagger-commons</artifactId>
|
<artifactId>swagger-commons</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.1-SNAPSHOT</version>
|
||||||
<name>swagger-commons</name>
|
<name>swagger-commons</name>
|
||||||
<description>swagger-commons</description>
|
<description>swagger-commons</description>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,7 +3,6 @@ package com.knecon.fforesight.swaggercommons;
|
|||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|||||||
@ -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.OAuthFlows;
|
||||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
|
import lombok.Value;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.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
|
@Bean
|
||||||
public CorsConfigurationSource corsConfigurationSource() {
|
public CorsConfigurationSource corsConfigurationSource() {
|
||||||
|
|
||||||
@ -135,16 +119,18 @@ public class SpringDocConfiguration {
|
|||||||
|
|
||||||
private OAuthFlows createOAuthFlows(SpringDocProperties springDocProperties) {
|
private OAuthFlows createOAuthFlows(SpringDocProperties springDocProperties) {
|
||||||
|
|
||||||
OAuthFlow flow = createAuthorizationCodeFlow(springDocProperties);
|
var codeFlow = new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth")
|
||||||
|
.tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token");
|
||||||
|
|
||||||
return new OAuthFlows().authorizationCode(flow);
|
var flows = new OAuthFlows().authorizationCode(codeFlow);
|
||||||
}
|
|
||||||
|
|
||||||
|
if (springDocProperties.isShowImplicitFlow()) {
|
||||||
|
var implicitFlow = new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/auth")
|
||||||
|
.tokenUrl(springDocProperties.getAuthServerUrl() + PROTOCOL_URL_FORMAT + "/token");
|
||||||
|
flows.implicit(implicitFlow);
|
||||||
|
}
|
||||||
|
|
||||||
private OAuthFlow createAuthorizationCodeFlow(SpringDocProperties springDocProperties) {
|
return flows;
|
||||||
|
|
||||||
return new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/auth")
|
|
||||||
.tokenUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/token");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class SpringDocCustomDocsController {
|
|||||||
|
|
||||||
private final SpringDocProperties springDocProperties;
|
private final SpringDocProperties springDocProperties;
|
||||||
|
|
||||||
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.Constants).DEFAULT_API_DOCS_URL}}")
|
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.utils.Constants).DEFAULT_API_DOCS_URL}}")
|
||||||
private String apiDocsUrl;
|
private String apiDocsUrl;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ public class SpringDocProperties {
|
|||||||
private String title ="Service Open API Documentation";
|
private String title ="Service Open API Documentation";
|
||||||
private String description ="Service Open API Documentation";
|
private String description ="Service Open API Documentation";
|
||||||
private String version = "1.0";
|
private String version = "1.0";
|
||||||
|
private boolean showImplicitFlow = true;
|
||||||
|
|
||||||
private List<String> packagesToScan = new ArrayList<>();
|
private List<String> packagesToScan = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
public class SpringDocTenantMvcConfigurer implements WebMvcConfigurer {
|
public class SpringDocTenantMvcConfigurer implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.Constants).DEFAULT_API_DOCS_URL}}")
|
@Value("${springdoc.api-docs.path:#{T(org.springdoc.core.utils.Constants).DEFAULT_API_DOCS_URL}}")
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
private final SpringDocProperties springDocProperties;
|
private final SpringDocProperties springDocProperties;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user