From f90651c5f9619f156c5d04b0018a815a64d5b04e Mon Sep 17 00:00:00 2001
From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com>
Date: Sat, 18 Nov 2023 12:34:13 +0530
Subject: [PATCH 01/23] BAEL-7200 Modify Request Body Before Reaching
Controller in Spring Boot
---
spring-boot-modules/spring-boot-mvc-5/pom.xml | 12 +++
.../modifyrequest/ModifyRequestApp.java | 11 +++
.../modifyrequest/aop/EscapeHtmlAspect.java | 74 +++++++++++++++++++
.../config/WebMvcConfiguration.java | 25 +++++++
.../controller/UserController.java | 23 ++++++
.../filter/EscapeHtmlFilter.java | 27 +++++++
.../EscapeHtmlRequestInterceptor.java | 19 +++++
.../EscapeHtmlRequestWrapper.java | 68 +++++++++++++++++
.../modifyrequest/filter-sequence-design.puml | 31 ++++++++
.../interceptor-sequence-design.puml | 33 +++++++++
.../EscapeHtmlAspectIntegrationTest.java | 52 +++++++++++++
.../EscapeHtmlFilterIntegrationTest.java | 51 +++++++++++++
.../EscapeHtmlInterceptorIntegrationTest.java | 46 ++++++++++++
13 files changed, 472 insertions(+)
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/ModifyRequestApp.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/controller/UserController.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/filter/EscapeHtmlFilter.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/interceptor/EscapeHtmlRequestInterceptor.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/filter-sequence-design.puml
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/interceptor-sequence-design.puml
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
diff --git a/spring-boot-modules/spring-boot-mvc-5/pom.xml b/spring-boot-modules/spring-boot-mvc-5/pom.xml
index a516cab049..10a58a6a59 100644
--- a/spring-boot-modules/spring-boot-mvc-5/pom.xml
+++ b/spring-boot-modules/spring-boot-mvc-5/pom.xml
@@ -49,6 +49,10 @@
commons-configuration
${commons-configuration.version}
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
@@ -61,6 +65,14 @@
JAR
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 9
+ 9
+
+
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/ModifyRequestApp.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/ModifyRequestApp.java
new file mode 100644
index 0000000000..7dd937d5b8
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/ModifyRequestApp.java
@@ -0,0 +1,11 @@
+package com.baeldung.modifyrequest;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication(scanBasePackages = "com.baeldung.modifyrequest")
+public class ModifyRequestApp {
+ public static void main(String[] args) {
+ SpringApplication.run(ModifyRequestApp.class, args);
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java
new file mode 100644
index 0000000000..fb31abe11b
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java
@@ -0,0 +1,74 @@
+package com.baeldung.modifyrequest.aop;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.MethodParameter;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpInputMessage;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
+
+import java.io.*;
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+
+@RestControllerAdvice
+@Profile("aspectExample")
+public class EscapeHtmlAspect implements RequestBodyAdvice {
+ private static final Logger logger = LoggerFactory.getLogger(EscapeHtmlAspect.class);
+
+ @Override
+ public boolean supports(MethodParameter methodParameter, Type targetType, Class extends HttpMessageConverter>> converterType) {
+ //Apply this to all Controllers
+ return true;
+ }
+
+ @Override
+ public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class extends HttpMessageConverter>> converterType) throws IOException {
+ logger.info("beforeBodyRead called");
+ InputStream inputStream = inputMessage.getBody();
+ return new HttpInputMessage() {
+ @Override
+ public InputStream getBody() throws IOException {
+ return new ByteArrayInputStream(escapeHtml(inputStream).getBytes(StandardCharsets.UTF_8));
+ }
+
+ @Override
+ public HttpHeaders getHeaders() {
+ return inputMessage.getHeaders();
+ }
+ };
+ }
+
+ @Override
+ public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class extends HttpMessageConverter>> converterType) {
+ // Return the modified object after reading the body
+ return body;
+ }
+
+ @Override
+ public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class extends HttpMessageConverter>> converterType) {
+ //return the original body
+ return body;
+ }
+
+ private String escapeHtml(InputStream inputStream) throws IOException {
+ StringBuilder stringBuilder = new StringBuilder();
+ BufferedReader bufferedReader = null;
+ try (inputStream) {
+ bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+ char[] charBuffer = new char[128];
+ int bytesRead = -1;
+ while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
+ stringBuilder.append(charBuffer, 0, bytesRead);
+ }
+ }
+ String input = stringBuilder.toString();
+ // Escape HTML characters
+ return input.replaceAll("&", "&")
+ .replaceAll("<", "<")
+ .replaceAll(">", ">");
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java
new file mode 100644
index 0000000000..bd76fd5e55
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java
@@ -0,0 +1,25 @@
+package com.baeldung.modifyrequest.config;
+
+import com.baeldung.modifyrequest.interceptor.EscapeHtmlRequestInterceptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+@Profile("interceptorExample")
+public class WebMvcConfiguration implements WebMvcConfigurer {
+ private static final Logger logger = LoggerFactory.getLogger(WebMvcConfiguration.class);
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ logger.info("addInterceptors() called");
+ registry.addInterceptor(new EscapeHtmlRequestInterceptor())
+ .addPathPatterns("/save");
+
+ WebMvcConfigurer.super.addInterceptors(registry);
+ }
+}
+
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/controller/UserController.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/controller/UserController.java
new file mode 100644
index 0000000000..26450dd70d
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/controller/UserController.java
@@ -0,0 +1,23 @@
+package com.baeldung.modifyrequest.controller;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/")
+public class UserController {
+ Logger logger = LoggerFactory.getLogger(UserController.class);
+
+ @PostMapping(value = "save")
+ public ResponseEntity saveUser(@RequestBody String user) {
+ logger.info("save user info into database");
+ ResponseEntity responseEntity = new ResponseEntity<>(user, HttpStatus.CREATED);
+ return responseEntity;
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/filter/EscapeHtmlFilter.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/filter/EscapeHtmlFilter.java
new file mode 100644
index 0000000000..45cad3be1c
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/filter/EscapeHtmlFilter.java
@@ -0,0 +1,27 @@
+package com.baeldung.modifyrequest.filter;
+
+import com.baeldung.modifyrequest.requestwrapper.EscapeHtmlRequestWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+@Component
+@Order(1)
+@Profile("filterExample")
+public class EscapeHtmlFilter implements Filter {
+ Logger logger = LoggerFactory.getLogger(EscapeHtmlFilter.class);
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
+ throws IOException, ServletException {
+ logger.info("Modify the request");
+
+ filterChain.doFilter(new EscapeHtmlRequestWrapper((HttpServletRequest) servletRequest), servletResponse);
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/interceptor/EscapeHtmlRequestInterceptor.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/interceptor/EscapeHtmlRequestInterceptor.java
new file mode 100644
index 0000000000..1ad39605e5
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/interceptor/EscapeHtmlRequestInterceptor.java
@@ -0,0 +1,19 @@
+package com.baeldung.modifyrequest.interceptor;
+
+import com.baeldung.modifyrequest.requestwrapper.EscapeHtmlRequestWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class EscapeHtmlRequestInterceptor implements HandlerInterceptor {
+ private static final Logger logger = LoggerFactory.getLogger(EscapeHtmlRequestInterceptor.class);
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ EscapeHtmlRequestWrapper escapeHtmlRequestWrapper = new EscapeHtmlRequestWrapper(request);
+ return true;
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java
new file mode 100644
index 0000000000..65c758d956
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java
@@ -0,0 +1,68 @@
+package com.baeldung.modifyrequest.requestwrapper;
+
+import javax.servlet.ReadListener;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import java.io.*;
+
+public class EscapeHtmlRequestWrapper extends HttpServletRequestWrapper {
+ private String body = null;
+ public EscapeHtmlRequestWrapper(HttpServletRequest request) throws IOException {
+ super(request);
+ this.body = this.escapeHtml(request);
+ }
+
+ private String escapeHtml(HttpServletRequest request) throws IOException {
+ StringBuilder stringBuilder = new StringBuilder();
+ BufferedReader bufferedReader = null;
+ try (InputStream inputStream = request.getInputStream()) {
+ bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+ char[] charBuffer = new char[128];
+ int bytesRead = -1;
+ while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
+ stringBuilder.append(charBuffer, 0, bytesRead);
+ }
+ }
+ String input = stringBuilder.toString();
+ // Escape HTML characters
+ return input.replaceAll("&", "&")
+ .replaceAll("<", "<")
+ .replaceAll(">", ">")
+ //.replaceAll("\"", """)
+ .replaceAll("'", "'");
+ }
+
+ @Override
+ public ServletInputStream getInputStream() {
+ final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
+ ServletInputStream servletInputStream = new ServletInputStream() {
+
+ @Override
+ public int read() {
+ return byteArrayInputStream.read();
+ }
+
+ @Override
+ public boolean isFinished() {
+ return false;
+ }
+
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public void setReadListener(ReadListener listener) {
+
+ }
+ };
+ return servletInputStream;
+ }
+
+ @Override
+ public BufferedReader getReader() throws IOException {
+ return new BufferedReader(new InputStreamReader(this.getInputStream()));
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/filter-sequence-design.puml b/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/filter-sequence-design.puml
new file mode 100644
index 0000000000..41689ac723
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/filter-sequence-design.puml
@@ -0,0 +1,31 @@
+@startuml
+'https://plantuml.com/sequence-diagram
+skinparam sequenceMessageAlign direction
+skinparam handwritten true
+skinparam sequence {
+ParticipantBackgroundColor beige
+ParticipantPadding 50
+}
+
+autonumber
+
+Browser -[#63b175]> Filter: HTTP Request
+activate Browser
+activate Filter
+Filter -[#63b175]> Filter: doFilter()
+Filter -[#63b175]> DispatcherServlet: HTTP Request
+activate DispatcherServlet
+
+
+DispatcherServlet -[#63b175]> Controller: HTTP Request
+activate Controller
+Controller --[#63b175]> DispatcherServlet: HTTP Response
+deactivate Controller
+
+DispatcherServlet --[#63b175]> Filter: HTTP Response
+deactivate DispatcherServlet
+
+Filter --[#63b175]> Browser: HTTP Response
+deactivate Filter
+deactivate Browser
+@enduml
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/interceptor-sequence-design.puml b/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/interceptor-sequence-design.puml
new file mode 100644
index 0000000000..429b8182ca
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/interceptor-sequence-design.puml
@@ -0,0 +1,33 @@
+@startuml
+'https://plantuml.com/sequence-diagram
+skinparam sequenceMessageAlign direction
+skinparam handwritten true
+skinparam sequence {
+ParticipantBackgroundColor beige
+ParticipantPadding 50
+}
+
+autonumber
+
+Browser -[#63b175]> Filter: Http Request
+activate Browser
+activate Filter
+Filter -[#63b175]> DispatcherServlet: Http Request
+activate DispatcherServlet
+
+DispatcherServlet -[#63b175]> Interceptor: Http Request
+activate Interceptor
+Interceptor -[#63b175]> Interceptor: preHandle()
+Interceptor -[#63b175]> Controller: Http Request
+activate Controller
+Controller --[#63b175]> Interceptor: Http Response
+deactivate Controller
+Interceptor --[#63b175]> DispatcherServlet: Http Response
+deactivate Interceptor
+DispatcherServlet --[#63b175]> Filter: Http Response
+deactivate DispatcherServlet
+
+Filter --[#63b175]> Browser: Http Response
+deactivate Filter
+deactivate Browser
+@enduml
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
new file mode 100644
index 0000000000..665733c61b
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
@@ -0,0 +1,52 @@
+package com.baeldung.modifyrequest;
+
+import com.baeldung.modifyrequest.controller.UserController;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import java.net.URI;
+import java.util.Map;
+
+@ExtendWith(SpringExtension.class)
+@AutoConfigureMockMvc
+@WebMvcTest(UserController.class)
+@ActiveProfiles("aspectExample")
+public class EscapeHtmlAspectIntegrationTest {
+ Logger logger = LoggerFactory.getLogger(EscapeHtmlAspectIntegrationTest.class);
+
+ @Autowired
+ private MockMvc mockMvc;
+ @Test
+ void givenAspect_whenEscapeHtmlAspect_thenEscapeHtml() throws Exception {
+
+ Map requestBody = Map.of(
+ "name", "James Cameron",
+ "email", "james@gmail.com"
+ );
+
+ Map expectedResponseBody = Map.of(
+ "name", "James Cameron",
+ "email", "<script>alert()</script>james@gmail.com"
+ );
+
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status().isCreated())
+ .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(expectedResponseBody)));
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
new file mode 100644
index 0000000000..35254eb151
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
@@ -0,0 +1,51 @@
+package com.baeldung.modifyrequest;
+
+import com.baeldung.modifyrequest.controller.UserController;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import java.net.URI;
+import java.util.Map;
+
+@ExtendWith(SpringExtension.class)
+@AutoConfigureMockMvc
+@WebMvcTest(UserController.class)
+@ActiveProfiles("filterExample")
+public class EscapeHtmlFilterIntegrationTest {
+ Logger logger = LoggerFactory.getLogger(EscapeHtmlFilterIntegrationTest.class);
+
+ @Autowired
+ private MockMvc mockMvc;
+ @Test
+ void givenFilter_whenEscapeHtmlFilter_thenEscapeHtml() throws Exception {
+ Map requestBody = Map.of(
+ "name", "James Cameron",
+ "email", "james@gmail.com"
+ );
+
+ Map expectedResponseBody = Map.of(
+ "name", "James Cameron",
+ "email", "<script>alert()</script>james@gmail.com"
+ );
+
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status().isCreated())
+ .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(expectedResponseBody)));
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
new file mode 100644
index 0000000000..002481de4f
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
@@ -0,0 +1,46 @@
+package com.baeldung.modifyrequest;
+
+import com.baeldung.modifyrequest.controller.UserController;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import java.net.URI;
+import java.util.Map;
+
+
+@ExtendWith(SpringExtension.class)
+@AutoConfigureMockMvc
+@WebMvcTest(UserController.class)
+@ActiveProfiles("interceptorExample")
+public class EscapeHtmlInterceptorIntegrationTest {
+ Logger logger = LoggerFactory.getLogger(EscapeHtmlInterceptorIntegrationTest.class);
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Test
+ void givenInterceptor_whenEscapeHtmlInterceptor_thenEscapeHtml() throws Exception {
+ Map requestBody = Map.of(
+ "name", "James Cameron",
+ "email", "james@gmail.com"
+ );
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status().is4xxClientError());
+ }
+}
From 7deec4a5e050c91e783669f0aebd6a0724f776fb Mon Sep 17 00:00:00 2001
From: Vladyslav Chernov
Date: Wed, 22 Nov 2023 16:06:21 -0800
Subject: [PATCH 02/23] BAEL-5755: indention update
---
.../baeldung/xml/xml2csv/Xml2CsvExample.java | 18 +++++++++---------
.../xml/xml2csv/Xml2CsvExampleUnitTest.java | 4 ++--
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/xml/src/main/java/com/baeldung/xml/xml2csv/Xml2CsvExample.java b/xml/src/main/java/com/baeldung/xml/xml2csv/Xml2CsvExample.java
index 99e5c7c0cb..84098b33f8 100644
--- a/xml/src/main/java/com/baeldung/xml/xml2csv/Xml2CsvExample.java
+++ b/xml/src/main/java/com/baeldung/xml/xml2csv/Xml2CsvExample.java
@@ -40,7 +40,7 @@ public class Xml2CsvExample {
protected static void convertXml2CsvXslt(String xslPath, String xmlPath, String csvPath) throws IOException, TransformerException {
StreamSource styleSource = new StreamSource(new File(xslPath));
Transformer transformer = TransformerFactory.newInstance()
- .newTransformer(styleSource);
+ .newTransformer(styleSource);
Source source = new StreamSource(new File(xmlPath));
Result outputTarget = new StreamResult(new File(csvPath));
transformer.transform(source, outputTarget);
@@ -68,26 +68,26 @@ public class Xml2CsvExample {
if ("Bookstore".equals(currentElement)) {
bookstoreInfo.setLength(0);
bookstoreInfo.append(reader.getAttributeValue(null, "id"))
- .append(",");
+ .append(",");
}
if ("Book".equals(currentElement)) {
csvRow.append(bookstoreInfo)
- .append(reader.getAttributeValue(null, "id"))
- .append(",")
- .append(reader.getAttributeValue(null, "category"))
- .append(",");
+ .append(reader.getAttributeValue(null, "id"))
+ .append(",")
+ .append(reader.getAttributeValue(null, "category"))
+ .append(",");
}
if ("Author".equals(currentElement)) {
csvRow.append(reader.getAttributeValue(null, "id"))
- .append(",");
+ .append(",");
}
break;
case XMLStreamConstants.CHARACTERS:
if (!reader.isWhiteSpace()) {
csvRow.append(reader.getText()
- .trim())
- .append(",");
+ .trim())
+ .append(",");
}
break;
diff --git a/xml/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java b/xml/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java
index 3fa44b427c..181d284b2d 100644
--- a/xml/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java
+++ b/xml/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java
@@ -91,7 +91,7 @@ public class Xml2CsvExampleUnitTest {
Xml2CsvExample.convertXml2CsvXslt(STYLE_XSL, DATA_XML, TEMP_OUTPUT_CSV);
File csvFile = new File(TEMP_OUTPUT_CSV);
- try(BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
+ try (BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
String line;
boolean isFirstLine = true;
while ((line = reader.readLine()) != null) {
@@ -113,7 +113,7 @@ public class Xml2CsvExampleUnitTest {
Xml2CsvExample.convertXml2CsvStax(DATA_XML, TEMP_OUTPUT_CSV);
File csvFile = new File(TEMP_OUTPUT_CSV);
- try(BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
+ try (BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
String line;
boolean isFirstLine = true;
while ((line = reader.readLine()) != null) {
From 81fe96721a53dff2a8c3ecc28ba53984bb98fd16 Mon Sep 17 00:00:00 2001
From: Kai Yuan
Date: Thu, 23 Nov 2023 13:03:09 +0100
Subject: [PATCH 03/23] [negate-int] negate an int in java
---
.../baeldung/negate/NegateIntUnitTest.java | 62 +++++++++++++++++++
1 file changed, 62 insertions(+)
create mode 100644 core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
new file mode 100644
index 0000000000..15fffde6ed
--- /dev/null
+++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
@@ -0,0 +1,62 @@
+package com.baeldung.negate;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class NegateIntUnitTest {
+ @Test
+ void whenUsingUnaryMinusOperator_thenGetExpectedResult() {
+ int x = 42;
+ assertEquals(-42, -x);
+
+ int z = 0;
+ assertEquals(0, -z);
+
+ int n = -42;
+ assertEquals(42, -n);
+ }
+
+ @Test
+ void whenUsingBitwiseComplementOperator_thenGetExpectedResult() {
+ int x = 42;
+ assertEquals(-42, ~x + 1);
+
+ int z = 0;
+ assertEquals(0, ~z + 1);
+
+ int n = -42;
+ assertEquals(42, ~n + 1);
+ }
+
+ @Test
+ void whenUsingUnaryMinusOperatorWithMinInt_thenCannotGetExpectedResult() {
+ int min = Integer.MIN_VALUE;
+ System.out.println("The value of '-min' is: " + -min);
+ assertFalse((-min) > 0);
+ }
+
+ @Test
+ void whenUsingBitwiseComplementOperatorWithMinInt_thenCannotGetExpectedResult() {
+ int min = Integer.MIN_VALUE;
+ int result = ~min + 1;
+ System.out.println("The value of '~min + 1' is: " + result);
+ assertFalse(result > 0);
+ }
+
+
+ @Test
+ void whenUsingUnaryMinusOperatorWithMinInt_thenGetExpectedResult() {
+ int x = 42;
+ assertEquals(-42, Math.negateExact(x));
+
+ int z = 0;
+ assertEquals(0, Math.negateExact(z));
+
+ int n = -42;
+ assertEquals(42, Math.negateExact(n));
+
+ int min = Integer.MIN_VALUE;
+ assertThrowsExactly(ArithmeticException.class, () -> Math.negateExact(min));
+ }
+}
\ No newline at end of file
From 8d440a419b62770092e4a0a4082763f2031b8609 Mon Sep 17 00:00:00 2001
From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com>
Date: Thu, 23 Nov 2023 21:26:53 +0530
Subject: [PATCH 04/23] BAEL-7200 fixed formatting. Used default intellij
formatting for Fluent API style.
---
.../modifyrequest/EscapeHtmlAspectIntegrationTest.java | 8 ++++----
.../modifyrequest/EscapeHtmlFilterIntegrationTest.java | 8 ++++----
.../EscapeHtmlInterceptorIntegrationTest.java | 6 +++---
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
index 665733c61b..12520b7e67 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
@@ -44,9 +44,9 @@ public class EscapeHtmlAspectIntegrationTest {
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(requestBody)))
- .andExpect(MockMvcResultMatchers.status().isCreated())
- .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(expectedResponseBody)));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status().isCreated())
+ .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(expectedResponseBody)));
}
}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
index 35254eb151..3ab7618b05 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
@@ -43,9 +43,9 @@ public class EscapeHtmlFilterIntegrationTest {
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(requestBody)))
- .andExpect(MockMvcResultMatchers.status().isCreated())
- .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(expectedResponseBody)));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status().isCreated())
+ .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(expectedResponseBody)));
}
}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
index 002481de4f..d855339bd9 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
@@ -39,8 +39,8 @@ public class EscapeHtmlInterceptorIntegrationTest {
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(requestBody)))
- .andExpect(MockMvcResultMatchers.status().is4xxClientError());
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status().is4xxClientError());
}
}
From 7df2f25fdb836be6b6057ad824ec30931cd00179 Mon Sep 17 00:00:00 2001
From: anuragkumawat
Date: Sat, 25 Nov 2023 16:35:00 +0530
Subject: [PATCH 05/23] JAVA-26737 Upgarde hibernate ehcache version in
spring-hibernate-5 module
---
persistence-modules/spring-hibernate-5/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml
index e559fe1394..d3ba647af2 100644
--- a/persistence-modules/spring-hibernate-5/pom.xml
+++ b/persistence-modules/spring-hibernate-5/pom.xml
@@ -131,7 +131,7 @@
1.10.6.RELEASE
4.2.1.RELEASE
- 5.2.10.Final
+ 5.6.15.Final
5.8.2.Final
8.0.7-dmr
9.0.0.M26
From ad7f1c7486cc2948af1d09e1512737982c125038 Mon Sep 17 00:00:00 2001
From: anuragkumawat
Date: Sat, 25 Nov 2023 16:43:03 +0530
Subject: [PATCH 06/23] JAVA-26737 Upgrade hibernate ehcache version in
hibernate-libraries module
---
persistence-modules/hibernate-libraries/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/persistence-modules/hibernate-libraries/pom.xml b/persistence-modules/hibernate-libraries/pom.xml
index 3f4da28296..d701487676 100644
--- a/persistence-modules/hibernate-libraries/pom.xml
+++ b/persistence-modules/hibernate-libraries/pom.xml
@@ -162,7 +162,7 @@
1.6
2.9.7
- 5.4.14.Final
+ 5.6.15.Final
3.27.0-GA
2.3.1
2.0.0
From 65676eb275409ded4484e487b4cbde472a5e6793 Mon Sep 17 00:00:00 2001
From: gaepi
Date: Sun, 26 Nov 2023 12:50:53 +0100
Subject: [PATCH 07/23] Java-27655 | removing WebSecurityConfigurerAdapter from
httpclient4 module
---
.../filter/CustomWebSecurityConfigurerAdapter.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/apache-httpclient4/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java b/apache-httpclient4/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java
index fb597e46c8..eaf166a091 100644
--- a/apache-httpclient4/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java
+++ b/apache-httpclient4/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java
@@ -7,14 +7,14 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
@Configuration
@EnableWebSecurity
-public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
+public class CustomWebSecurityConfigurerAdapter {
@Autowired private RestAuthenticationEntryPoint authenticationEntryPoint;
@@ -27,8 +27,8 @@ public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAda
.authorities("ROLE_USER");
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/securityNone")
@@ -40,6 +40,8 @@ public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAda
.authenticationEntryPoint(authenticationEntryPoint);
http.addFilterAfter(new CustomFilter(), BasicAuthenticationFilter.class);
+
+ return http.build();
}
@Bean
From 033fff1e5ef9e00cec85028a9861c5baf4c51dbc Mon Sep 17 00:00:00 2001
From: gaepi
Date: Sun, 26 Nov 2023 13:12:19 +0100
Subject: [PATCH 08/23] Java-27655 | moved jenkins module to more recent
implementation of web security
---
.../WebSecurityConfiguration.java | 56 ++++++++-----------
1 file changed, 24 insertions(+), 32 deletions(-)
diff --git a/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java b/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java
index 8700dc3df4..033281e07f 100644
--- a/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java
+++ b/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java
@@ -1,52 +1,44 @@
package com.baeldung.configuration;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.provisioning.InMemoryUserDetailsManager;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
-public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
+public class WebSecurityConfiguration {
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
-
+ @Bean
+ public InMemoryUserDetailsManager userDetailsService() {
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
-
- auth.inMemoryAuthentication()
- .withUser("admin").password(encoder.encode("admin")).roles("USER", "ADMIN")
- .and()
- .withUser("user1").password(encoder.encode("password1")).roles("USER")
- .and()
- .withUser("user2").password(encoder.encode("password2")).roles("USER")
- .and()
- .withUser("user3").password(encoder.encode("password3")).roles("USER")
- .and()
- .withUser("user4").password(encoder.encode("password4")).roles("USER")
- .and()
- .withUser("user5").password(encoder.encode("password5")).roles("USER")
- .and()
- .withUser("user6").password(encoder.encode("password6")).roles("USER")
- .and()
- .withUser("user7").password(encoder.encode("password7")).roles("USER")
- .and()
- .withUser("user8").password(encoder.encode("password8")).roles("USER")
- .and()
- .withUser("user9").password(encoder.encode("password9")).roles("USER")
- .and()
- .withUser("user10").password(encoder.encode("password10")).roles("USER");
+
+ Set users = new HashSet<>();
+ users.add(User.withUsername("admin").password(encoder.encode("admin")).roles("USER", "ADMIN").build());
+ for(int i=1;i<=10;i++){
+ users.add(User.withUsername("user"+i).password(encoder.encode("password")+i).roles("USER").build());
+ }
+
+ return new InMemoryUserDetailsManager(users);
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
-
+ @Bean
+ public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
+
http
.authorizeRequests()
.antMatchers("/secured/**").authenticated()
.anyRequest().permitAll()
.and()
.httpBasic();
+
+ return http.build();
}
}
From 0973a63e5c2e312c2bf9839c6da8d1f91a13ade3 Mon Sep 17 00:00:00 2001
From: gaepi
Date: Sun, 26 Nov 2023 13:33:08 +0100
Subject: [PATCH 09/23] Java-27655 | removed deprecated
WebSecurityConfigAdapter from security-modules/jjwt module
---
.../jjwtfun/config/WebSecurityConfig.java | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java
index 687a827448..e453f33d5e 100644
--- a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java
+++ b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java
@@ -4,9 +4,11 @@ import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.jjwtfun.service.SecretService;
import org.springframework.beans.factory.annotation.Autowired;
+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.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.security.web.csrf.CsrfTokenRepository;
@@ -21,19 +23,19 @@ import java.io.IOException;
import java.util.Arrays;
@Configuration
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+public class WebSecurityConfig {
@Autowired
- CsrfTokenRepository jwtCsrfTokenRepository;
+ private CsrfTokenRepository jwtCsrfTokenRepository;
@Autowired
- SecretService secretService;
+ private SecretService secretService;
// ordered so we can use binary search below
- private String[] ignoreCsrfAntMatchers = { "/dynamic-builder-compress", "/dynamic-builder-general", "/dynamic-builder-specific", "/set-secrets" };
+ private final String[] ignoreCsrfAntMatchers = { "/dynamic-builder-compress", "/dynamic-builder-general", "/dynamic-builder-specific", "/set-secrets" };
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.addFilterAfter(new JwtCsrfValidatorFilter(), CsrfFilter.class)
.csrf()
.csrfTokenRepository(jwtCsrfTokenRepository)
@@ -42,6 +44,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests()
.antMatchers("/**")
.permitAll();
+
+ return http.build();
}
private class JwtCsrfValidatorFilter extends OncePerRequestFilter {
From 0b2981b94e48a35ea0ad46c0a4091b0ae4f3eba8 Mon Sep 17 00:00:00 2001
From: Kai Yuan
Date: Sun, 26 Nov 2023 19:10:19 +0100
Subject: [PATCH 10/23] [negate-int] using logger instead of sys.print.out
---
.../com/baeldung/negate/NegateIntUnitTest.java | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
index 15fffde6ed..3cb93d243d 100644
--- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
+++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
@@ -1,10 +1,14 @@
package com.baeldung.negate;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.*;
public class NegateIntUnitTest {
+ private static Logger LOG = LoggerFactory.getLogger(NegateIntUnitTest.class);
+
@Test
void whenUsingUnaryMinusOperator_thenGetExpectedResult() {
int x = 42;
@@ -30,18 +34,20 @@ public class NegateIntUnitTest {
}
@Test
- void whenUsingUnaryMinusOperatorWithMinInt_thenCannotGetExpectedResult() {
+ void givenIntMinValue_whenUsingUnaryMinusOperator_thenCannotGetExpectedResult() {
int min = Integer.MIN_VALUE;
- System.out.println("The value of '-min' is: " + -min);
- assertFalse((-min) > 0);
+ LOG.info("The value of '-min' is: " + -min);
+
+ assertTrue((-min) < 0);
}
@Test
- void whenUsingBitwiseComplementOperatorWithMinInt_thenCannotGetExpectedResult() {
+ void givenIntMinValue_whenUsingBitwiseComplementOperator_thenCannotGetExpectedResult() {
int min = Integer.MIN_VALUE;
int result = ~min + 1;
- System.out.println("The value of '~min + 1' is: " + result);
- assertFalse(result > 0);
+ LOG.info("The value of '~min + 1' is: " + result);
+
+ assertTrue(result < 0);
}
From 62cc5adfbbce8379f7dd5ec8f39162262b133f94 Mon Sep 17 00:00:00 2001
From: Kai Yuan
Date: Sun, 26 Nov 2023 20:59:53 +0100
Subject: [PATCH 11/23] [negate-int] add an empty line
---
.../src/test/java/com/baeldung/negate/NegateIntUnitTest.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
index 3cb93d243d..444f4931d3 100644
--- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
+++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
@@ -7,7 +7,8 @@ import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.*;
public class NegateIntUnitTest {
- private static Logger LOG = LoggerFactory.getLogger(NegateIntUnitTest.class);
+
+ private static final Logger LOG = LoggerFactory.getLogger(NegateIntUnitTest.class);
@Test
void whenUsingUnaryMinusOperator_thenGetExpectedResult() {
From d58102e32c745da8eb903b60aef4ad18e6f3c78f Mon Sep 17 00:00:00 2001
From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com>
Date: Mon, 27 Nov 2023 10:54:21 +0530
Subject: [PATCH 12/23] BAEL-7200 fixed formatting
---
.../modifyrequest/aop/EscapeHtmlAspect.java | 14 +++++++++-----
.../config/WebMvcConfiguration.java | 3 ++-
.../EscapeHtmlRequestWrapper.java | 7 +++----
.../EscapeHtmlAspectIntegrationTest.java | 10 ++++++----
.../EscapeHtmlFilterIntegrationTest.java | 18 ++++++++++--------
.../EscapeHtmlInterceptorIntegrationTest.java | 11 ++++++-----
6 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java
index fb31abe11b..d4533dcf0b 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java
@@ -17,6 +17,7 @@ import java.nio.charset.StandardCharsets;
@RestControllerAdvice
@Profile("aspectExample")
public class EscapeHtmlAspect implements RequestBodyAdvice {
+
private static final Logger logger = LoggerFactory.getLogger(EscapeHtmlAspect.class);
@Override
@@ -26,7 +27,8 @@ public class EscapeHtmlAspect implements RequestBodyAdvice {
}
@Override
- public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class extends HttpMessageConverter>> converterType) throws IOException {
+ public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
+ Class extends HttpMessageConverter>> converterType) throws IOException {
logger.info("beforeBodyRead called");
InputStream inputStream = inputMessage.getBody();
return new HttpInputMessage() {
@@ -43,13 +45,15 @@ public class EscapeHtmlAspect implements RequestBodyAdvice {
}
@Override
- public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class extends HttpMessageConverter>> converterType) {
+ public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
+ Class extends HttpMessageConverter>> converterType) {
// Return the modified object after reading the body
return body;
}
@Override
- public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class extends HttpMessageConverter>> converterType) {
+ public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
+ Class extends HttpMessageConverter>> converterType) {
//return the original body
return body;
}
@@ -68,7 +72,7 @@ public class EscapeHtmlAspect implements RequestBodyAdvice {
String input = stringBuilder.toString();
// Escape HTML characters
return input.replaceAll("&", "&")
- .replaceAll("<", "<")
- .replaceAll(">", ">");
+ .replaceAll("<", "<")
+ .replaceAll(">", ">");
}
}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java
index bd76fd5e55..2fc1fbc310 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java
@@ -1,6 +1,7 @@
package com.baeldung.modifyrequest.config;
import com.baeldung.modifyrequest.interceptor.EscapeHtmlRequestInterceptor;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
@@ -17,7 +18,7 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
logger.info("addInterceptors() called");
registry.addInterceptor(new EscapeHtmlRequestInterceptor())
- .addPathPatterns("/save");
+ .addPathPatterns("/save");
WebMvcConfigurer.super.addInterceptors(registry);
}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java
index 65c758d956..e7b3abbc1f 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java
@@ -27,10 +27,9 @@ public class EscapeHtmlRequestWrapper extends HttpServletRequestWrapper {
String input = stringBuilder.toString();
// Escape HTML characters
return input.replaceAll("&", "&")
- .replaceAll("<", "<")
- .replaceAll(">", ">")
- //.replaceAll("\"", """)
- .replaceAll("'", "'");
+ .replaceAll("<", "<")
+ .replaceAll(">", ">")
+ .replaceAll("'", "'");
}
@Override
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
index 12520b7e67..ef18591ccb 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
@@ -44,9 +44,11 @@ public class EscapeHtmlAspectIntegrationTest {
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(requestBody)))
- .andExpect(MockMvcResultMatchers.status().isCreated())
- .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(expectedResponseBody)));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status()
+ .isCreated())
+ .andExpect(MockMvcResultMatchers.content()
+ .json(objectMapper.writeValueAsString(expectedResponseBody)));
}
}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
index 3ab7618b05..d84ced5e1a 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
@@ -31,21 +31,23 @@ public class EscapeHtmlFilterIntegrationTest {
@Test
void givenFilter_whenEscapeHtmlFilter_thenEscapeHtml() throws Exception {
Map requestBody = Map.of(
- "name", "James Cameron",
- "email", "james@gmail.com"
+ "name", "James Cameron",
+ "email", "james@gmail.com"
);
Map expectedResponseBody = Map.of(
- "name", "James Cameron",
- "email", "<script>alert()</script>james@gmail.com"
+ "name", "James Cameron",
+ "email", "<script>alert()</script>james@gmail.com"
);
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(requestBody)))
- .andExpect(MockMvcResultMatchers.status().isCreated())
- .andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(expectedResponseBody)));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status()
+ .isCreated())
+ .andExpect(MockMvcResultMatchers.content()
+ .json(objectMapper.writeValueAsString(expectedResponseBody)));
}
}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
index d855339bd9..06aff5db3b 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
@@ -33,14 +33,15 @@ public class EscapeHtmlInterceptorIntegrationTest {
@Test
void givenInterceptor_whenEscapeHtmlInterceptor_thenEscapeHtml() throws Exception {
Map requestBody = Map.of(
- "name", "James Cameron",
- "email", "james@gmail.com"
+ "name", "James Cameron",
+ "email", "james@gmail.com"
);
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(requestBody)))
- .andExpect(MockMvcResultMatchers.status().is4xxClientError());
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status()
+ .is4xxClientError());
}
}
From 526a90bc8c8340925f04628eafaa3155077cdd05 Mon Sep 17 00:00:00 2001
From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com>
Date: Mon, 27 Nov 2023 10:58:12 +0530
Subject: [PATCH 13/23] BAEL-7200 fixed formatting
---
.../modifyrequest/EscapeHtmlFilterIntegrationTest.java | 10 ++++------
.../EscapeHtmlInterceptorIntegrationTest.java | 7 +++----
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
index d84ced5e1a..c813827422 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
@@ -43,11 +43,9 @@ public class EscapeHtmlFilterIntegrationTest {
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(requestBody)))
- .andExpect(MockMvcResultMatchers.status()
- .isCreated())
- .andExpect(MockMvcResultMatchers.content()
- .json(objectMapper.writeValueAsString(expectedResponseBody)));
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody))).andExpect(MockMvcResultMatchers.status()
+ .isCreated()).andExpect(MockMvcResultMatchers.content()
+ .json(objectMapper.writeValueAsString(expectedResponseBody)));
}
}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
index 06aff5db3b..9afc7f7e5a 100644
--- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
@@ -39,9 +39,8 @@ public class EscapeHtmlInterceptorIntegrationTest {
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
- .contentType(MediaType.APPLICATION_JSON)
- .content(objectMapper.writeValueAsString(requestBody)))
- .andExpect(MockMvcResultMatchers.status()
- .is4xxClientError());
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody))).andExpect(MockMvcResultMatchers.status()
+ .is4xxClientError());
}
}
From 2e6b17b85336d0338afb8426ae53188812407edc Mon Sep 17 00:00:00 2001
From: gaepi
Date: Mon, 27 Nov 2023 11:31:41 +0100
Subject: [PATCH 14/23] JAVA-27656 | spring-boot-modules fix
---
.../baeldung/caffeine/SecurityConfiguration.java | 13 +++++++------
.../boot/management/logging/SecurityConfig.java | 14 ++++++++------
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/caffeine/SecurityConfiguration.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/caffeine/SecurityConfiguration.java
index 7f3ad7988f..e63726c926 100644
--- a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/caffeine/SecurityConfiguration.java
+++ b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/caffeine/SecurityConfiguration.java
@@ -1,9 +1,10 @@
package com.baeldung.caffeine;
+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.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
/**
* Because the POM imports Spring Security, we need a simple security
@@ -11,14 +12,14 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
*/
@Configuration
@EnableWebSecurity
-public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
+public class SecurityConfiguration {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
http.csrf().disable();
- http.authorizeRequests()
+ return http.authorizeRequests()
.antMatchers("/**")
- .permitAll();
+ .permitAll().and().build();
}
}
diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/spring/boot/management/logging/SecurityConfig.java b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/spring/boot/management/logging/SecurityConfig.java
index 45cc1ebb33..6870f4e6bb 100644
--- a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/spring/boot/management/logging/SecurityConfig.java
+++ b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/spring/boot/management/logging/SecurityConfig.java
@@ -1,14 +1,16 @@
package com.baeldung.spring.boot.management.logging;
+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.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
-public class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.csrf()
- .ignoringAntMatchers("/actuator/**");
+public class SecurityConfig {
+ @Bean
+ public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
+ return http.csrf()
+ .ignoringAntMatchers("/actuator/**").and()
+ .build();
}
}
From 8dd4651db582818e56bcd2c812ee76ef8996db47 Mon Sep 17 00:00:00 2001
From: gaepi
Date: Mon, 27 Nov 2023 11:48:10 +0100
Subject: [PATCH 15/23] JAVA-27656 | removing WebSecurityConfigurerAdapter from
spring-web-modules/spring-thymeleaf
---
.../thymeleaf/config/WebMVCSecurity.java | 41 ++++++++-----------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java
index ea51ca3cd9..074cc20be1 100644
--- a/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java
+++ b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java
@@ -2,42 +2,37 @@ package com.baeldung.thymeleaf.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.provisioning.InMemoryUserDetailsManager;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
-public class WebMVCSecurity extends WebSecurityConfigurerAdapter {
+public class WebMVCSecurity {
@Bean
- @Override
- public AuthenticationManager authenticationManagerBean() throws Exception {
- return super.authenticationManagerBean();
+ public InMemoryUserDetailsManager userDetailsService() {
+ UserDetails user = User.withUsername("user1")
+ .password("{noop}user1Pass")
+ .authorities("USER")
+ .build();
+ return new InMemoryUserDetailsManager(user);
}
- public WebMVCSecurity() {
- super();
+ @Bean
+ public WebSecurityCustomizer webSecurityCustomizer() {
+ return (web) -> web.ignoring().antMatchers("/resources/**");
}
- @Override
- protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
- auth.inMemoryAuthentication().withUser("user1").password("{noop}user1Pass").authorities("ROLE_USER");
- }
-
- @Override
- public void configure(final WebSecurity web) throws Exception {
- web.ignoring().antMatchers("/resources/**");
- }
-
- @Override
- protected void configure(final HttpSecurity http) throws Exception {
- http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
+ @Bean
+ public SecurityFilterChain filterChain(final HttpSecurity http) throws Exception {
+ return http.authorizeRequests().anyRequest().authenticated().and().httpBasic().and().build();
}
}
From 4151b9ce706ae13764d445df9c28d28f8488ecb3 Mon Sep 17 00:00:00 2001
From: gaepi
Date: Mon, 27 Nov 2023 12:00:26 +0100
Subject: [PATCH 16/23] JAVA-27656 | removing WebSecurityConfigurerAdapter
---
.../OAuth2WebSecurityConfigurerAdapter.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/spring-cloud-modules/spring-cloud-openfeign/src/main/java/com/baeldung/cloud/openfeign/oauthfeign/OAuth2WebSecurityConfigurerAdapter.java b/spring-cloud-modules/spring-cloud-openfeign/src/main/java/com/baeldung/cloud/openfeign/oauthfeign/OAuth2WebSecurityConfigurerAdapter.java
index af60c3849b..6efacc03b1 100644
--- a/spring-cloud-modules/spring-cloud-openfeign/src/main/java/com/baeldung/cloud/openfeign/oauthfeign/OAuth2WebSecurityConfigurerAdapter.java
+++ b/spring-cloud-modules/spring-cloud-openfeign/src/main/java/com/baeldung/cloud/openfeign/oauthfeign/OAuth2WebSecurityConfigurerAdapter.java
@@ -1,19 +1,23 @@
package com.baeldung.cloud.openfeign.oauthfeign;
+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.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
-public class OAuth2WebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
+public class OAuth2WebSecurityConfigurerAdapter {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.oauth2Client();
+
http
.authorizeRequests().anyRequest().permitAll();
+
+ return http.build();
}
}
From cf74ed5628699d725c5994604a60c33b03d64d8f Mon Sep 17 00:00:00 2001
From: panos-kakos
Date: Mon, 27 Nov 2023 13:15:33 +0200
Subject: [PATCH 17/23] [JAVA-27818]
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index c6abc0d4d8..f5aedd091e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -701,7 +701,7 @@
apache-kafka
apache-libraries-2
apache-libraries
- apache-olingo
+ apache-olingo
apache-poi-2
apache-poi-3
apache-poi
@@ -945,7 +945,7 @@
apache-kafka
apache-libraries-2
apache-libraries
- apache-olingo
+ apache-olingo
apache-poi-2
apache-poi-3
apache-poi
From 6164b9c0bafd9fe7080d0429c3a1af07ea5ebf35 Mon Sep 17 00:00:00 2001
From: Sameer
Date: Tue, 28 Nov 2023 03:47:00 +0530
Subject: [PATCH 18/23] string vs stringBuffer comparison (#15306)
Co-authored-by: Sahil
---
.../stringbuffer/ComparePerformance.java | 63 +++++++++++++++++++
.../com/baeldung/stringbuffer/HashCode.java | 24 +++++++
.../stringIterator/StringIteratorTest.java | 4 +-
.../stringbuffer/ComparePerformanceTest.java | 32 ++++++++++
.../baeldung/stringbuffer/HashCodeTest.java | 24 +++++++
5 files changed, 145 insertions(+), 2 deletions(-)
create mode 100644 core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java
create mode 100644 core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/HashCode.java
create mode 100644 core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/ComparePerformanceTest.java
create mode 100644 core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/HashCodeTest.java
diff --git a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java
new file mode 100644
index 0000000000..28cd2e64e9
--- /dev/null
+++ b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java
@@ -0,0 +1,63 @@
+package com.baeldung.stringbuffer;
+
+import java.util.concurrent.TimeUnit;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+@BenchmarkMode(Mode.SingleShotTime)
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@Measurement(batchSize = 10000, iterations = 10)
+@Warmup(batchSize = 1000, iterations = 10)
+@State(Scope.Thread)
+public class ComparePerformance {
+
+ String strInitial = "springframework";
+ String strFinal = "";
+ String replacement = "java-";
+
+ @Benchmark
+ public String benchmarkStringConcatenation() {
+ strFinal += strInitial;
+ return strFinal;
+ }
+
+ @Benchmark
+ public StringBuffer benchmarkStringBufferConcatenation() {
+ StringBuffer stringBuffer = new StringBuffer(strFinal);
+ stringBuffer.append(strInitial);
+ return stringBuffer;
+ }
+
+ @Benchmark
+ public String benchmarkStringReplacement() {
+ strFinal = strInitial.replaceFirst("spring", replacement);
+ return strFinal;
+ }
+
+ @Benchmark
+ public StringBuffer benchmarkStringBufferReplacement() {
+ StringBuffer stringBuffer = new StringBuffer(strInitial);
+ stringBuffer.replace(0,6, replacement);
+ return stringBuffer;
+ }
+
+ public static void main(String[] args) throws RunnerException {
+ Options options = new OptionsBuilder()
+ .include(ComparePerformance.class.getSimpleName()).threads(1)
+ .forks(1).shouldFailOnError(true)
+ .shouldDoGC(true)
+ .jvmArgs("-server").build();
+ new Runner(options).run();
+ }
+}
diff --git a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/HashCode.java b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/HashCode.java
new file mode 100644
index 0000000000..65f17263a9
--- /dev/null
+++ b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/HashCode.java
@@ -0,0 +1,24 @@
+package com.baeldung.stringbuffer;
+
+public class HashCode {
+
+ public static long getHashCodeString(String string) {
+ return string.hashCode();
+ }
+
+ public static long getHashCodeSBuffer(StringBuffer strBuff) {
+ return strBuff.hashCode();
+ }
+
+ public static void main(String[] args) {
+ String str = "Spring";
+ System.out.println("String HashCode pre concatenation :" + getHashCodeString(str));
+ str += "Framework";
+ System.out.println("String HashCode post concatenation :" + getHashCodeString(str));
+
+ StringBuffer sBuf = new StringBuffer("Spring");
+ System.out.println("StringBuffer HashCode pre concatenation :" + getHashCodeSBuffer(sBuf));
+ sBuf.append("Framework");
+ System.out.println("StringBuffer HashCode post concatenation :" + getHashCodeSBuffer(sBuf));
+ }
+}
diff --git a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringIterator/StringIteratorTest.java b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringIterator/StringIteratorTest.java
index 585d65d4be..aef7f81da2 100644
--- a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringIterator/StringIteratorTest.java
+++ b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringIterator/StringIteratorTest.java
@@ -17,7 +17,7 @@ public class StringIteratorTest {
public void whenUseJavaForLoop_thenIterate() {
String input = "Hello, Baeldung!";
String expectedOutput = "Hello, Baeldung!";
- String result = StringIterator.javaForLoop(input);
+ String result = StringIterator.javaforLoop(input);
assertEquals(expectedOutput, result);
}
@@ -25,7 +25,7 @@ public class StringIteratorTest {
public void whenUseForEachMethod_thenIterate() {
String input = "Hello, Baeldung!";
String expectedOutput = "Hello, Baeldung!";
- String result = StringIterator.java8ForEach(input);
+ String result = StringIterator.java8forEach(input);
assertEquals(expectedOutput, result);
}
diff --git a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/ComparePerformanceTest.java b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/ComparePerformanceTest.java
new file mode 100644
index 0000000000..696c4bae6b
--- /dev/null
+++ b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/ComparePerformanceTest.java
@@ -0,0 +1,32 @@
+package com.baeldung.stringbuffer;
+
+import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class ComparePerformanceTest {
+
+ ComparePerformance cp = new ComparePerformance();
+
+ @Test
+ public void whenStringConcatenated_thenResultAsExpected() {
+ assertThat(cp.benchmarkStringConcatenation()).isEqualTo("springframework");
+ }
+
+ @Test
+ public void whenStringBufferConcatenated_thenResultAsExpected() {
+ StringBuffer stringBuffer = new StringBuffer("springframework");
+ assertThat(cp.benchmarkStringBufferConcatenation()).isEqualToIgnoringCase(stringBuffer);
+ }
+
+ @Test
+ public void whenStringReplaced_thenResultAsExpected() {
+ assertThat(cp.benchmarkStringReplacement()).isEqualTo("java-framework");
+ }
+
+ @Test
+ public void whenStringBufferReplaced_thenResultAsExpected() {
+ StringBuffer stringBuffer = new StringBuffer("java-framework");
+ assertThat(cp.benchmarkStringBufferReplacement()).isEqualToIgnoringCase(stringBuffer);
+ }
+}
diff --git a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/HashCodeTest.java b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/HashCodeTest.java
new file mode 100644
index 0000000000..265c4e1e40
--- /dev/null
+++ b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/HashCodeTest.java
@@ -0,0 +1,24 @@
+package com.baeldung.stringbuffer;
+
+import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class HashCodeTest {
+
+ String str = "Spring";
+ StringBuffer sBuf = new StringBuffer("Spring");
+
+ @Test
+ public void whenStringConcat_thenHashCodeChanges() {
+ HashCode hc = new HashCode();
+
+ long initialStringHashCode = hc.getHashCodeString(str);
+ long initialSBufHashCode = hc.getHashCodeSBuffer(sBuf);
+
+ str += "Framework";
+ sBuf.append("Framework");
+
+ assertThat(initialStringHashCode).isNotEqualTo(hc.getHashCodeString(str));
+ assertThat(initialSBufHashCode).isEqualTo(hc.getHashCodeSBuffer(sBuf));
+ }
+}
From c67139e60ba57b3846e8d8505b93bdf5374443d6 Mon Sep 17 00:00:00 2001
From: panos-kakos
Date: Tue, 28 Nov 2023 06:38:53 +0200
Subject: [PATCH 19/23] [JAVA-26727] Upgraded maven-javadoc-plugin to 3.6.2
version
---
core-java-modules/core-java-console/pom.xml | 2 +-
core-java-modules/core-java-documentation/pom.xml | 2 +-
core-java-modules/core-java-io-2/pom.xml | 2 +-
core-java-modules/core-java-io/pom.xml | 2 +-
core-java-modules/core-java-jar/pom.xml | 2 +-
core-java-modules/core-java-serialization/pom.xml | 2 +-
core-java-modules/core-java-uuid/pom.xml | 2 +-
performance-tests/pom.xml | 2 +-
.../spring-openapi-generator-api-client/pom.xml | 2 +-
.../spring-swagger-codegen-api-client/pom.xml | 2 +-
10 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/core-java-modules/core-java-console/pom.xml b/core-java-modules/core-java-console/pom.xml
index 8677b672ea..a761b2749e 100644
--- a/core-java-modules/core-java-console/pom.xml
+++ b/core-java-modules/core-java-console/pom.xml
@@ -159,7 +159,7 @@
- 3.0.0-M1
+ 3.6.2
1.8
1.8
0.3.2
diff --git a/core-java-modules/core-java-documentation/pom.xml b/core-java-modules/core-java-documentation/pom.xml
index be18af1b10..23443dd5ea 100644
--- a/core-java-modules/core-java-documentation/pom.xml
+++ b/core-java-modules/core-java-documentation/pom.xml
@@ -33,7 +33,7 @@
- 3.0.0-M1
+ 3.6.2
1.8
1.8
diff --git a/core-java-modules/core-java-io-2/pom.xml b/core-java-modules/core-java-io-2/pom.xml
index 8632748baa..830b386fe2 100644
--- a/core-java-modules/core-java-io-2/pom.xml
+++ b/core-java-modules/core-java-io-2/pom.xml
@@ -61,7 +61,7 @@
- 3.0.0-M1
+ 3.6.2
3.3.1
diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml
index faeddafd81..93c9289fdd 100644
--- a/core-java-modules/core-java-io/pom.xml
+++ b/core-java-modules/core-java-io/pom.xml
@@ -134,7 +134,7 @@
- 3.5.0
+ 3.6.2
2.7.1
2.8.0
diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml
index a46299c669..138827781e 100644
--- a/core-java-modules/core-java-jar/pom.xml
+++ b/core-java-modules/core-java-jar/pom.xml
@@ -274,7 +274,7 @@
4.6.1
1.1
- 3.0.0-M1
+ 3.6.2
1.4.4
3.1.1
3.3.0
diff --git a/core-java-modules/core-java-serialization/pom.xml b/core-java-modules/core-java-serialization/pom.xml
index 63771d2da0..ad0a730514 100644
--- a/core-java-modules/core-java-serialization/pom.xml
+++ b/core-java-modules/core-java-serialization/pom.xml
@@ -177,7 +177,7 @@
0.4
1.8.7
1.1
- 3.0.0-M1
+ 3.6.2
4.3.20.RELEASE
diff --git a/core-java-modules/core-java-uuid/pom.xml b/core-java-modules/core-java-uuid/pom.xml
index d46fcd8a65..0a0835ca46 100644
--- a/core-java-modules/core-java-uuid/pom.xml
+++ b/core-java-modules/core-java-uuid/pom.xml
@@ -154,7 +154,7 @@
- 3.0.0-M1
+ 3.6.2
diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml
index d22a9cf3ac..7927c518f9 100644
--- a/performance-tests/pom.xml
+++ b/performance-tests/pom.xml
@@ -164,7 +164,7 @@
3.2.4
3.0.0-M1
3.2.0
- 3.2.0
+ 3.6.2
3.1.0
3.9.1
3.2.1
diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml b/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml
index ee2c86238a..1e3b93ae42 100644
--- a/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml
+++ b/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml
@@ -276,7 +276,7 @@
2.2
1.10
3.6.1
- 2.10.4
+ 3.6.2
2.2.1
1.5
diff --git a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml
index 35f4978411..af12f9cef0 100644
--- a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml
+++ b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml
@@ -196,7 +196,7 @@
2.2
1.5
2.2.1
- 2.10.4
+ 3.6.2
1.10
From 331fb9a477be4641a7e7900bcf7e8550e09ff701 Mon Sep 17 00:00:00 2001
From: panos-kakos <102670093+panos-kakos@users.noreply.github.com>
Date: Tue, 28 Nov 2023 12:21:36 +0200
Subject: [PATCH 20/23] [JAVA-27680] Upgraded spring-boot-groovy to jdk17 and
spring boot 3 (#15292)
---
.../spring-boot-groovy/pom.xml | 22 ++++++++++++-------
.../springwithgroovy/entity/Todo.groovy | 12 +++++-----
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/spring-boot-modules/spring-boot-groovy/pom.xml b/spring-boot-modules/spring-boot-groovy/pom.xml
index 151160bde5..677e07db2d 100644
--- a/spring-boot-modules/spring-boot-groovy/pom.xml
+++ b/spring-boot-modules/spring-boot-groovy/pom.xml
@@ -1,7 +1,7 @@
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.baeldung.app
spring-boot-groovy
@@ -10,9 +10,10 @@
Spring Boot Todo Application with Groovy
- com.baeldung.spring-boot-modules
- spring-boot-modules
- 1.0.0-SNAPSHOT
+ com.baeldung
+ parent-boot-3
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-3
@@ -25,7 +26,7 @@
spring-boot-starter-web
- org.codehaus.groovy
+ org.apache.groovy
groovy
${groovy.version}
@@ -39,6 +40,11 @@
h2
runtime
+
+ io.rest-assured
+ rest-assured
+ test
+
@@ -71,8 +77,8 @@
com.baeldung.springwithgroovy.SpringBootGroovyApplication
- 3.0.13
- 1.9.0
+ 4.0.11
+ 3.0.2
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-groovy/src/main/groovy/com/baeldung/springwithgroovy/entity/Todo.groovy b/spring-boot-modules/spring-boot-groovy/src/main/groovy/com/baeldung/springwithgroovy/entity/Todo.groovy
index 000d981701..31274e1f07 100644
--- a/spring-boot-modules/spring-boot-groovy/src/main/groovy/com/baeldung/springwithgroovy/entity/Todo.groovy
+++ b/spring-boot-modules/spring-boot-groovy/src/main/groovy/com/baeldung/springwithgroovy/entity/Todo.groovy
@@ -1,11 +1,11 @@
package com.baeldung.springwithgroovy.entity
-import javax.persistence.Column
-import javax.persistence.Entity
-import javax.persistence.GeneratedValue
-import javax.persistence.GenerationType
-import javax.persistence.Id
-import javax.persistence.Table
+import jakarta.persistence.Column
+import jakarta.persistence.Entity
+import jakarta.persistence.GeneratedValue
+import jakarta.persistence.GenerationType
+import jakarta.persistence.Id
+import jakarta.persistence.Table
@Entity
@Table(name = 'todo')
From 7b5225e8db05bd236cafa955223212c2db435bc2 Mon Sep 17 00:00:00 2001
From: Ulisses Lima
Date: Tue, 28 Nov 2023 12:14:50 -0300
Subject: [PATCH 21/23] BAEL-7022 Why wait must be called in a synchronized
block - Changing Boolean to primitive
Based on a comment.
---
.../com/baeldung/wait_synchronization/ConditionChecker.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core-java-modules/core-java-concurrency-advanced-5/src/main/java/com/baeldung/wait_synchronization/ConditionChecker.java b/core-java-modules/core-java-concurrency-advanced-5/src/main/java/com/baeldung/wait_synchronization/ConditionChecker.java
index dca36fe7cb..34e0a7522b 100644
--- a/core-java-modules/core-java-concurrency-advanced-5/src/main/java/com/baeldung/wait_synchronization/ConditionChecker.java
+++ b/core-java-modules/core-java-concurrency-advanced-5/src/main/java/com/baeldung/wait_synchronization/ConditionChecker.java
@@ -2,7 +2,7 @@ package com.baeldung.wait_synchronization;
public class ConditionChecker {
- private volatile Boolean jobIsDone;
+ private volatile boolean jobIsDone;
private final Object lock = new Object();
public void ensureCondition() {
@@ -21,4 +21,4 @@ public class ConditionChecker {
lock.notify();
}
}
-}
\ No newline at end of file
+}
From 6ecf4f2bd9d8013f83948f58715ee758842bb470 Mon Sep 17 00:00:00 2001
From: Bipin kumar
Date: Wed, 29 Nov 2023 17:54:00 +0530
Subject: [PATCH 22/23] JAVA-26778: Changes made for Upgrade jaxb2-maven-plugin
to latest version (#15220)
---
feign/pom.xml | 14 +++++++++++++-
pom.xml | 4 ++--
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/feign/pom.xml b/feign/pom.xml
index edb55e7da5..127f6c490c 100644
--- a/feign/pom.xml
+++ b/feign/pom.xml
@@ -74,6 +74,17 @@
${wire.mock.version}
test
+
+ jakarta.xml.bind
+ jakarta.xml.bind-api
+ 4.0.0
+
+
+ com.sun.xml.bind
+ jaxb-impl
+ 4.0.0
+ runtime
+
@@ -85,7 +96,7 @@
org.codehaus.mojo
jaxb2-maven-plugin
- 2.5.0
+ 3.1.0
xjc
@@ -131,6 +142,7 @@
3.8.0
3.1.2
2.33.2
+ 4.0.0
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f5aedd091e..32b8e8c8c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -726,7 +726,7 @@
dozer
drools
dubbo
-
+ feign
gcp-firebase
geotools
google-auto-project
@@ -970,7 +970,7 @@
dozer
drools
dubbo
-
+ feign
gcp-firebase
geotools
google-auto-project
From 5990aeee283a63ce0146baa756a4bc3843ebf84b Mon Sep 17 00:00:00 2001
From: panos-kakos <102670093+panos-kakos@users.noreply.github.com>
Date: Thu, 30 Nov 2023 13:05:22 +0200
Subject: [PATCH 23/23] [JAVA-27742] Replaced aspectj-maven-plugin with
dev.aspectj that supports java 17 (#15289)
---
spring-di-2/pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/spring-di-2/pom.xml b/spring-di-2/pom.xml
index 0bd6c41a8c..898dd182f1 100644
--- a/spring-di-2/pom.xml
+++ b/spring-di-2/pom.xml
@@ -55,9 +55,9 @@
- org.codehaus.mojo
+ dev.aspectj
aspectj-maven-plugin
- ${aspectj-plugin.version}
+ ${aspectj-maven-plugin.version}
${java.version}
@@ -80,7 +80,7 @@
3.1.2
- 1.14.0
+ 1.13.1
2.17.1