From aab0a4934f2f7089eb99c77c1caf05a7b766f770 Mon Sep 17 00:00:00 2001 From: Eric Degenetais Date: Tue, 12 Nov 2024 10:49:40 +0100 Subject: [PATCH 1/3] Code QA : en passant, clean unused import & commented out code. --- src/main/java/fr/ans/psc/config/OpenApiDocketConfigurer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/fr/ans/psc/config/OpenApiDocketConfigurer.java b/src/main/java/fr/ans/psc/config/OpenApiDocketConfigurer.java index 9d2eb48..acd93f6 100644 --- a/src/main/java/fr/ans/psc/config/OpenApiDocketConfigurer.java +++ b/src/main/java/fr/ans/psc/config/OpenApiDocketConfigurer.java @@ -21,7 +21,6 @@ import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.Tag; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; @@ -39,7 +38,6 @@ public Docket docket() { .license("MIT") .licenseUrl("https://opensource.org/licenses/MIT%22") .build()) -// .tags(new Tag("Note", "Endpoints for CRUD operations on notes")) .select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .build(); From 9a296c91a3ffff5db43434ee5a17461a27e12282 Mon Sep 17 00:00:00 2001 From: Eric Degenetais Date: Tue, 12 Nov 2024 10:49:53 +0100 Subject: [PATCH 2/3] FIX : we need to accept encoded slashes. --- .../fr/ans/psc/config/ASConfiguration.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/fr/ans/psc/config/ASConfiguration.java diff --git a/src/main/java/fr/ans/psc/config/ASConfiguration.java b/src/main/java/fr/ans/psc/config/ASConfiguration.java new file mode 100644 index 0000000..956dc95 --- /dev/null +++ b/src/main/java/fr/ans/psc/config/ASConfiguration.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2022-2023 Agence du Numérique en Santé (ANS) (https://esante.gouv.fr) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.ans.psc.config; + +import org.apache.tomcat.util.buf.EncodedSolidusHandling; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Tweaking the application server configuration to accept ID with embedded %2F contructs. + * + * @author edegenetais + */ +@Configuration +public class ASConfiguration { + @Bean + public WebServerFactoryCustomizer tomcatCustomizer() { + return factory -> + factory.addConnectorCustomizers( + connector -> connector.setEncodedSolidusHandling(EncodedSolidusHandling.PASS_THROUGH.getValue())); + } +} From 1eaf5096b44725032579b76965bd48834a8ad955 Mon Sep 17 00:00:00 2001 From: Eric Degenetais Date: Tue, 12 Nov 2024 12:32:13 +0100 Subject: [PATCH 3/3] We also need to force the URL decoder to NOT decode URLs. --- .../java/fr/ans/psc/config/ASConfiguration.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/fr/ans/psc/config/ASConfiguration.java b/src/main/java/fr/ans/psc/config/ASConfiguration.java index 956dc95..f26bc06 100644 --- a/src/main/java/fr/ans/psc/config/ASConfiguration.java +++ b/src/main/java/fr/ans/psc/config/ASConfiguration.java @@ -20,6 +20,9 @@ import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.util.UrlPathHelper; /** * Tweaking the application server configuration to accept ID with embedded %2F contructs. @@ -34,4 +37,17 @@ public WebServerFactoryCustomizer tomcatCustomize factory.addConnectorCustomizers( connector -> connector.setEncodedSolidusHandling(EncodedSolidusHandling.PASS_THROUGH.getValue())); } + + @Bean + public WebMvcConfigurer getWebMvcConfigurer() { + return new WebMvcConfigurer() { + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + final UrlPathHelper urlPathHelper = new UrlPathHelper(); + urlPathHelper.setUrlDecode(false); + configurer.setUrlPathHelper(urlPathHelper); + } + }; + } + }