diff --git a/annotations/pom.xml b/annotations/pom.xml index 5907a57..fb7fe9c 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -7,7 +7,7 @@ io.getlime.core lime-java-core-parent - 1.10.0 + 1.11.0 annotations diff --git a/audit-base/pom.xml b/audit-base/pom.xml index 5215551..4cd56a8 100644 --- a/audit-base/pom.xml +++ b/audit-base/pom.xml @@ -6,7 +6,7 @@ io.getlime.core lime-java-core-parent - 1.10.0 + 1.11.0 audit-base diff --git a/bom/pom.xml b/bom/pom.xml index aa45a5c..00301f5 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -7,7 +7,7 @@ io.getlime.core lime-java-core-parent - 1.10.0 + 1.11.0 core-bom diff --git a/http-common/pom.xml b/http-common/pom.xml index f7d9a97..e7a65ec 100644 --- a/http-common/pom.xml +++ b/http-common/pom.xml @@ -7,7 +7,7 @@ io.getlime.core lime-java-core-parent - 1.10.0 + 1.11.0 http-common diff --git a/http-common/src/main/java/com/wultra/core/http/common/headers/UserAgent.java b/http-common/src/main/java/com/wultra/core/http/common/headers/UserAgent.java index 08d328b..9134363 100644 --- a/http-common/src/main/java/com/wultra/core/http/common/headers/UserAgent.java +++ b/http-common/src/main/java/com/wultra/core/http/common/headers/UserAgent.java @@ -31,6 +31,9 @@ @Slf4j public final class UserAgent { + /** + * Device information. + */ @Data public static class Device { private String networkVersion; diff --git a/pom.xml b/pom.xml index 402acf4..f652dd7 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ Wultra - Core Java Libraries io.getlime.core lime-java-core-parent - 1.10.0 + 1.11.0 pom 2017 @@ -57,11 +57,11 @@ ${java.version} 3.13.0 - 3.3.1 + 3.5.0 3.5.0 - 3.3.2 + 3.3.4 @@ -119,7 +119,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.8.0 + 3.10.0 false @@ -135,7 +135,7 @@ org.apache.maven.plugins maven-deploy-plugin - 3.1.2 + 3.1.3 org.apache.maven.plugins diff --git a/rest-client-base/pom.xml b/rest-client-base/pom.xml index 19bc353..d148272 100644 --- a/rest-client-base/pom.xml +++ b/rest-client-base/pom.xml @@ -6,7 +6,7 @@ io.getlime.core lime-java-core-parent - 1.10.0 + 1.11.0 rest-client-base diff --git a/rest-client-base/src/main/java/com/wultra/core/rest/client/base/DefaultRestClient.java b/rest-client-base/src/main/java/com/wultra/core/rest/client/base/DefaultRestClient.java index 2b51367..a64e19c 100644 --- a/rest-client-base/src/main/java/com/wultra/core/rest/client/base/DefaultRestClient.java +++ b/rest-client-base/src/main/java/com/wultra/core/rest/client/base/DefaultRestClient.java @@ -57,6 +57,7 @@ import java.net.URISyntaxException; import java.time.Duration; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; /** @@ -839,7 +840,17 @@ private WebClient.RequestBodySpec buildUri(WebClient.RequestBodyUriSpec uriSpec, private WebClient.RequestHeadersSpec buildRequest(WebClient.RequestBodySpec requestSpec, Object request) { if (request != null) { if (request instanceof MultiValueMap) { - return requestSpec.body(BodyInserters.fromMultipartData(((MultiValueMap) request))); + final AtomicReference contentTypeReference = new AtomicReference<>(); + requestSpec.headers(httpHeaders -> contentTypeReference.set(httpHeaders.getContentType())); + final MediaType contentType = contentTypeReference.get(); + + if (MediaType.APPLICATION_FORM_URLENCODED.equals(contentType)) { + return requestSpec.body(BodyInserters.fromFormData((MultiValueMap) request)); + } else if (MediaType.MULTIPART_FORM_DATA.equals(contentType)) { + return requestSpec.body(BodyInserters.fromMultipartData(((MultiValueMap) request))); + } else { + throw new IllegalArgumentException("Unsupported content type: %s for request type of MultiValueMap".formatted(contentType)); + } } else if (request instanceof Publisher) { return requestSpec.body(BodyInserters.fromDataBuffers((Publisher) request)); } diff --git a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/DefaultRestClientTest.java b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/DefaultRestClientTest.java index 63482cc..b50e29f 100644 --- a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/DefaultRestClientTest.java +++ b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/DefaultRestClientTest.java @@ -42,6 +42,8 @@ import org.springframework.http.client.MultipartBodyBuilder; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.util.ResourceUtils; import reactor.core.publisher.Flux; @@ -662,6 +664,26 @@ void testPostWithMultipartData() throws RestClientException { assertEquals(requestData, responseEntity.getBody().getResponseObject().getResponse()); } + @Test + void testPostFormData() throws Exception { + final HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + + final MultiValueMap map = new LinkedMultiValueMap<>(); + map.add("grant_type", "authorization_code"); + map.add("client_id", "wultra"); + map.add("client_secret", "top-secret"); + + final ResponseEntity> responseEntity = + restClient.post("/form-data-request-response", map, null, headers, new ParameterizedTypeReference<>(){}); + + assertNotNull(responseEntity); + assertNotNull(responseEntity.getBody()); + assertNotNull(responseEntity.getBody().getResponseObject()); + assertEquals("OK", responseEntity.getBody().getStatus()); + assertEquals("form-data: [authorization_code, wultra, top-secret]", responseEntity.getBody().getResponseObject().getResponse()); + } + @Test void testPostOctetStream() throws Exception { final byte[] request = {1, 2}; diff --git a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/config/WebSecurityConfig.java b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/config/WebSecurityConfig.java index a558998..e9655c6 100644 --- a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/config/WebSecurityConfig.java +++ b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/config/WebSecurityConfig.java @@ -18,6 +18,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.SecurityFilterChain; @@ -53,13 +54,14 @@ private DigestAuthenticationFilter digestAuthenticationFilter() { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - return http.csrf().disable() + return http + .csrf(AbstractHttpConfigurer::disable) .exceptionHandling(e -> e.authenticationEntryPoint(authenticationEntryPoint())) .addFilter(digestAuthenticationFilter()) - .authorizeHttpRequests() - .requestMatchers("/private/**").authenticated() - .anyRequest().permitAll() - .and().build(); + .authorizeHttpRequests(authorize -> authorize + .requestMatchers("/private/**").authenticated() + .anyRequest().permitAll() + ).build(); } @Bean diff --git a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/controller/PublicTestRestController.java b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/controller/PublicTestRestController.java index 958e232..5dbdb03 100644 --- a/rest-client-base/src/test/java/com/wultra/core/rest/client/base/controller/PublicTestRestController.java +++ b/rest-client-base/src/test/java/com/wultra/core/rest/client/base/controller/PublicTestRestController.java @@ -31,6 +31,7 @@ import java.net.URI; import java.util.Arrays; import java.util.Enumeration; +import java.util.List; /** * Rest controller for tests. @@ -85,6 +86,11 @@ public ObjectResponse testPostWithMultipartRequestAndResponse(@Req return new ObjectResponse<>(testResponse); } + @PostMapping(value = "/form-data-request-response", consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE }) + public ObjectResponse testPostFormDataRequestAndResponse(@RequestParam("grant_type") final String grantType, @RequestParam("client_id") final String clientId, @RequestParam("client_secret") final String clientSecret) { + return new ObjectResponse<>(new TestResponse("form-data: " + List.of(grantType, clientId, clientSecret))); + } + @PostMapping(value = "/octet-stream", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE) public ObjectResponse testPostOctetStream(@RequestBody byte[] request) { final TestResponse testResponse = new TestResponse("length: " + request.length); diff --git a/rest-model-base/pom.xml b/rest-model-base/pom.xml index 199826a..5c28381 100644 --- a/rest-model-base/pom.xml +++ b/rest-model-base/pom.xml @@ -6,7 +6,7 @@ io.getlime.core lime-java-core-parent - 1.10.0 + 1.11.0 rest-model-base