Commit 9b3224c7 authored by Shrikant Garg's avatar Shrikant Garg
Browse files

Merge branch 'springfox-upgrade' into 'master'

Springfox version upgrade to 3.0.0

See merge request !154
parents 09e91f11 8ff02f08
Pipeline #86375 passed with stages
in 34 minutes and 13 seconds
......@@ -34,12 +34,8 @@
<java.version>1.8</java.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<springfox-version>2.7.0</springfox-version>
<tomcat_embed_core_version>9.0.54</tomcat_embed_core_version>
<log4j2.version>2.17.0</log4j2.version>
<!--
<springfox-version>2.9.2</springfox-version>
-->
</properties>
<dependencies>
......@@ -176,18 +172,6 @@
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<!-- swagger dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
</dependencies>
<build>
......
package org.opengroup.osdu.dataset.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;
}
}
\ No newline at end of file
......@@ -19,25 +19,28 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
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.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 springfox.documentation.service.Parameter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Configuration
@EnableSwagger2
@EnableOpenApi
@Profile("!noswagger")
public class SwaggerDocumentationConfig {
public static final String AUTHORIZATION_HEADER = "Authorization";
......@@ -45,26 +48,23 @@ public class SwaggerDocumentationConfig {
@Bean
public Docket api() {
ParameterBuilder builder = new ParameterBuilder();
List<Parameter> parameters = new ArrayList<>();
RequestParameterBuilder builder = new RequestParameterBuilder();
List<RequestParameter> parameters = new ArrayList<>();
builder.name(DpsHeaders.DATA_PARTITION_ID)
.description("tenant")
.defaultValue("common")
.modelRef(new ModelRef("string"))
.parameterType("header")
.in(ParameterType.HEADER)
.required(true)
.build();
parameters.add(builder.build());
builder.name("frame-of-reference")
.description("reference")
.defaultValue("none")
.modelRef(new ModelRef("string"))
.parameterType("header")
.in(ParameterType.HEADER)
.required(true)
.build();
parameters.add(builder.build());
return new Docket(DocumentationType.SWAGGER_2)
.globalOperationParameters(parameters)
return new Docket(DocumentationType.OAS_30)
.globalRequestParameters(parameters)
.select()
.apis(RequestHandlerSelectors.basePackage("org.opengroup.osdu.dataset.api"))
.build()
......@@ -73,13 +73,13 @@ public class SwaggerDocumentationConfig {
}
private ApiKey apiKey() {
return new ApiKey("JWT", AUTHORIZATION_HEADER, "header");
return new ApiKey(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER, "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex(DEFAULT_INCLUDE_PATTERN))
.operationSelector(o -> PathSelectors.regex(DEFAULT_INCLUDE_PATTERN).test(o.requestMappingPattern()))
.build();
}
......@@ -89,6 +89,6 @@ public class SwaggerDocumentationConfig {
AuthorizationScope[] authorizationScopes =
new AuthorizationScope[]{authorizationScope};
return Collections.singletonList(
new SecurityReference("JWT", authorizationScopes));
new SecurityReference(AUTHORIZATION_HEADER, authorizationScopes));
}
}
......@@ -33,6 +33,7 @@
<commons-codec.version>1.14</commons-codec.version>
<nimbusds.version>7.9</nimbusds.version>
<log4j2.version>2.17.0</log4j2.version>
<springfox.version>3.0.0</springfox.version>
</properties>
<licenses>
......@@ -111,6 +112,13 @@
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<!-- swagger dependency -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${springfox.version}</version>
</dependency>
</dependencies>
<profiles>
......
......@@ -42,11 +42,13 @@ public class AADSecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests()
.antMatchers("/", "/index.html",
"/v2/api-docs",
"/v3/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger",
"/swagger-ui.html",
"/swagger-ui/**",
"/info",
"/webjars/**").permitAll()
.anyRequest().authenticated()
......
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