Compare commits

...

5 Commits
0.5.0 ... main

Author SHA1 Message Date
Timo Bejan
48696d0374 Merge branch 'implicitflow' into 'main'
add implicit flow for swagger

See merge request fforesight/swagger-commons!2
2024-03-12 15:10:51 +01:00
Timo Bejan
77a5b81b2c add implicit flow for swagger 2024-03-12 16:06:59 +02:00
Timo Bejan
c88c7851f9 Merge branch 'graal-vm-conditional-adaptation' into 'main'
GraalVM for cors

See merge request fforesight/swagger-commons!1
2023-08-30 10:14:11 +02:00
Timo Bejan
b5510f5294 GraalVM for cors 2023-08-30 01:27:15 +03:00
Timo Bejan
7854148cef Fixed version 2023-06-02 10:18:01 +03:00
5 changed files with 49 additions and 25 deletions

2
.gitignore vendored
View File

@ -31,3 +31,5 @@ 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>1.0-SNAPSHOT</version>
<version>0.1-SNAPSHOT</version>
<name>swagger-commons</name>
<description>swagger-commons</description>
<properties>

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() {
@ -135,16 +119,18 @@ public class SpringDocConfiguration {
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 new OAuthFlow().authorizationUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/auth")
.tokenUrl(springDocProperties.getAuthServerUrl()+PROTOCOL_URL_FORMAT + "/token");
return flows;
}
}

View File

@ -23,6 +23,7 @@ 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<>();