From 0584625400fee31b2357da11a7fc4e36d7d3ccc0 Mon Sep 17 00:00:00 2001 From: "idriss.naji" Date: Thu, 10 Nov 2022 16:31:28 +0100 Subject: [PATCH] fix:VIC-1891 Fix Swagger UI after CVEs fixes --- pom.xml | 18 +++-------------- .../CustomSwaggerPathWebMvcConfigurer.java | 2 ++ .../api/config/SpringFoxConfig.java | 4 +--- .../CustomSwaggerApiResourceController.java | 20 +++++++++++++++++++ .../controller/CustomSwaggerController.java | 19 ------------------ src/main/resources/application.properties | 1 + .../liveservice/LiveServiceApplicationIT.java | 5 +++++ 7 files changed, 32 insertions(+), 37 deletions(-) create mode 100644 src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerApiResourceController.java delete mode 100644 src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerController.java diff --git a/pom.xml b/pom.xml index 6d4a955..58cd4c9 100644 --- a/pom.xml +++ b/pom.xml @@ -26,11 +26,9 @@ 2.17.1 0.2.3 - 3.0.0 - 3.0.0 - 3.0.0 5.7.5 5.1.1 + 3.0.0 @@ -77,18 +75,8 @@ io.springfox - springfox-swagger2 - ${springfox-swagger2.version} - - - io.springfox - springfox-bean-validators - ${springfox-bean-validators.version} - - - io.springfox - springfox-swagger-ui - ${springfox-swagger-ui.version} + springfox-boot-starter + ${springfox-boot-starter.version} diff --git a/src/main/java/de/caritas/cob/liveservice/api/config/CustomSwaggerPathWebMvcConfigurer.java b/src/main/java/de/caritas/cob/liveservice/api/config/CustomSwaggerPathWebMvcConfigurer.java index 86c22a1..4b53f0c 100644 --- a/src/main/java/de/caritas/cob/liveservice/api/config/CustomSwaggerPathWebMvcConfigurer.java +++ b/src/main/java/de/caritas/cob/liveservice/api/config/CustomSwaggerPathWebMvcConfigurer.java @@ -13,6 +13,8 @@ public class CustomSwaggerPathWebMvcConfigurer implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler(docuPath + "/swagger-ui/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); registry.addResourceHandler(docuPath + "/**") .addResourceLocations("classpath:/META-INF/resources/"); } diff --git a/src/main/java/de/caritas/cob/liveservice/api/config/SpringFoxConfig.java b/src/main/java/de/caritas/cob/liveservice/api/config/SpringFoxConfig.java index 78eba75..97c081c 100644 --- a/src/main/java/de/caritas/cob/liveservice/api/config/SpringFoxConfig.java +++ b/src/main/java/de/caritas/cob/liveservice/api/config/SpringFoxConfig.java @@ -14,13 +14,11 @@ import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * Provides the SpringFox (API documentation generation) configuration. */ @Configuration -@EnableSwagger2 @Import(BeanValidatorPluginsConfiguration.class) public class SpringFoxConfig { @@ -47,7 +45,7 @@ public class SpringFoxConfig { // without authorization public static final String[] WHITE_LIST = new String[] {"/mails/docs", "/mails/docs/**", "/v2/api-docs", "/configuration/ui", - "/swagger-resources/**", "/configuration/security", "/swagger-ui.html", "/webjars/**"}; + "/swagger-resources/**", "/configuration/security", "/swagger-ui", "/swagger-ui/**", "/webjars/**"}; @Bean public Docket apiDocket() { diff --git a/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerApiResourceController.java b/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerApiResourceController.java new file mode 100644 index 0000000..75221be --- /dev/null +++ b/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerApiResourceController.java @@ -0,0 +1,20 @@ +package de.caritas.cob.liveservice.api.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import springfox.documentation.annotations.ApiIgnore; +import springfox.documentation.swagger.web.ApiResourceController; +import springfox.documentation.swagger.web.SwaggerResourcesProvider; + +@Controller +@ApiIgnore +@RequestMapping(value = "${springfox.docuPath}" + "/swagger-resources") +public class CustomSwaggerApiResourceController extends ApiResourceController { + + public static final String SWAGGER_UI_BASE_URL = "/liveevent/docs"; + + public CustomSwaggerApiResourceController(SwaggerResourcesProvider swaggerResources) { + super(swaggerResources, SWAGGER_UI_BASE_URL); + } + +} diff --git a/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerController.java b/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerController.java deleted file mode 100644 index 5501894..0000000 --- a/src/main/java/de/caritas/cob/liveservice/api/controller/CustomSwaggerController.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.caritas.cob.liveservice.api.controller; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import springfox.documentation.annotations.ApiIgnore; - -@Controller -@ApiIgnore -public class CustomSwaggerController { - - @Value("${springfox.docuPath}") - private String docuPath; - - @RequestMapping(value = "${springfox.docuPath}") - public String index() { - return "redirect:" + docuPath + "/swagger-ui.html"; - } -} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 90447ef..2c86c14 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -17,6 +17,7 @@ springfox.docuContactEmail= springfox.docuLicense=Apache 2.0 springfox.docuLicenseUrl=http://www.apache.org/licenses/LICENSE-2.0.html springfox.docuPath=/liveevent/docs +springfox.documentation.swagger.v2.path=${springfox.docuPath}/v2/api-docs live.event.retry.send.cron=*/5 * * * * ? live.event.retry.amount=5 diff --git a/src/test/java/de/caritas/cob/liveservice/LiveServiceApplicationIT.java b/src/test/java/de/caritas/cob/liveservice/LiveServiceApplicationIT.java index 3efc5f8..c718968 100644 --- a/src/test/java/de/caritas/cob/liveservice/LiveServiceApplicationIT.java +++ b/src/test/java/de/caritas/cob/liveservice/LiveServiceApplicationIT.java @@ -20,6 +20,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; +import de.caritas.cob.liveservice.api.controller.CustomSwaggerApiResourceController; import de.caritas.cob.liveservice.api.model.LiveEventMessage; import de.caritas.cob.liveservice.api.model.VideoCallRequestDTO; import de.caritas.cob.liveservice.websocket.model.WebSocketUserSession; @@ -31,6 +32,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.messaging.simp.stomp.StompSession; import org.springframework.messaging.simp.stomp.StompSession.Subscription; import org.springframework.test.context.TestPropertySource; @@ -40,6 +42,9 @@ @TestPropertySource(properties = "spring.profiles.active=testing") class LiveServiceApplicationIT extends StompClientIntegrationTest { + @MockBean + private CustomSwaggerApiResourceController customSwaggerApiResourceController; + @Autowired private SocketUserRegistry socketUserRegistry;