Commit fbfa3806 authored by Ashwani Pandey's avatar Ashwani Pandey Committed by Shrikant Garg
Browse files

Spring fox upgrade

parent ef47bd44
......@@ -28,7 +28,6 @@
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<springfox-swagger2.version>2.7.0</springfox-swagger2.version>
</properties>
<prerequisites>
......@@ -69,25 +68,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger2.version}</version>
<exclusions>
<exclusion>
<!--
Excluding com.google.guava:guava:jar:18.0, because it has security vulnerability
-->
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
......
......@@ -4,56 +4,54 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.builders.RequestParameterBuilder;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.ParameterType;
import springfox.documentation.service.RequestParameter;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang3.StringUtils.startsWithIgnoreCase;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;
@Configuration
@EnableSwagger2
@EnableOpenApi
public class SwaggerConfiguration {
private static final String BEARER_AUTH_KEY_NAME = "Bearer Authorization";
public static final String PASS_AS_HEADER = "header";
public static final String DEFAULT_INCLUDE_PATTERN = "/.*";
@Bean
public Docket api(List<Parameter> globalParameters) {
return new Docket(DocumentationType.SWAGGER_2)
public Docket api() {
RequestParameterBuilder builder = new RequestParameterBuilder();
List<RequestParameter> parameters = new ArrayList<>();
builder.name(DpsHeaders.DATA_PARTITION_ID)
.description("tenant")
.in(ParameterType.HEADER)
.required(true)
.build();
parameters.add(builder.build());
return new Docket(DocumentationType.OAS_30)
.globalRequestParameters(parameters)
.select()
.apis(RequestHandlerSelectors.basePackage("org.opengroup.osdu.crs.api"))
.paths(s -> !startsWithIgnoreCase(s, "/error"))
.build()
.globalOperationParameters(globalParameters)
.securitySchemes(singletonList(bearerAuth()))
.securityContexts(singletonList(securityContext()));
}
@Bean
public Parameter dataPatitionParameter() {
ParameterBuilder builder = new ParameterBuilder();
builder.name(DpsHeaders.DATA_PARTITION_ID)
.description("tenant")
.defaultValue("opendes")
.modelRef(new ModelRef("string"))
.parameterType(PASS_AS_HEADER)
.required(true)
.build();
return builder.build();
}
private ApiKey bearerAuth() {
return new ApiKey(BEARER_AUTH_KEY_NAME, AUTHORIZATION, PASS_AS_HEADER);
......@@ -62,7 +60,7 @@ public class SwaggerConfiguration {
private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.any())
.operationSelector(o -> PathSelectors.regex(DEFAULT_INCLUDE_PATTERN).test(o.requestMappingPattern()))
.build();
}
......
......@@ -7,6 +7,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class HomeController {
@RequestMapping(value = {"/", "/swagger"})
public String swagger() {
return "redirect:swagger-ui.html";
return "redirect:swagger-ui/index.html";
}
}
\ No newline at end of file
package org.opengroup.osdu.crs.swagger;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import springfox.documentation.oas.web.OpenApiTransformationContext;
import springfox.documentation.oas.web.WebMvcOpenApiTransformationFilter;
import springfox.documentation.spi.DocumentationType;
import javax.servlet.http.HttpServletRequest;
@Component
@Order(Ordered.LOWEST_PRECEDENCE)
public class SpringfoxSwaggerHostResolver implements WebMvcOpenApiTransformationFilter {
@Override
public boolean supports(DocumentationType delimiter) {
return delimiter == DocumentationType.OAS_30;
}
@Override
public OpenAPI transform(OpenApiTransformationContext<HttpServletRequest> context) {
OpenAPI swagger = context.getSpecification();
Server server = swagger.getServers().get(0);
if (server.getUrl().contains(":443")) {
// via the gateway
server.setUrl(server.getUrl().replace(":443",""));
}
return swagger;
}
}
......@@ -12,6 +12,7 @@
<os-core-common.version>0.13.0-rc4</os-core-common.version>
<snakeyaml.version>1.26</snakeyaml.version>
<nimbus-jose-jwt.version>7.9</nimbus-jose-jwt.version>
<springfox.version>3.0.0</springfox.version>
</properties>
<licenses>
......@@ -95,6 +96,15 @@
</dependency>
</dependencies>
</dependencyManagement>
<!--Swagger-->
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${springfox.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
......
......@@ -53,10 +53,12 @@ public class AuthSecurityConfig extends WebSecurityConfigurerAdapter implements
"/actuator/**",
"/_ah/*",
"/v2/api-docs",
"/v3/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/swagger-ui/**",
"/info",
"/webjars/**",
"/csrf",
......
......@@ -38,11 +38,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter implements Acc
"/index.html",
"/_ah/*",
"/v2/api-docs",
"/v3/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger",
"/swagger-ui.html",
"/swagger-ui/**",
"/info",
"/webjars/**",
"/csrf"
......
......@@ -53,10 +53,12 @@ public class AuthSecurityConfig extends WebSecurityConfigurerAdapter implements
"/actuator/**",
"/_ah/*",
"/v2/api-docs",
"/v3/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/swagger-ui/**",
"/info",
"/webjars/**",
"/csrf",
......
......@@ -41,10 +41,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter implements Acce
"/actuator/**",
"/_ah/*",
"/v2/api-docs",
"/v3/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/swagger-ui/**",
"/info",
"/webjars/**",
"/csrf",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment