From de518acea534a84247ca545ba3762648a5ec696e Mon Sep 17 00:00:00 2001 From: Joshua Gort Date: Sun, 5 May 2024 18:24:45 +0200 Subject: [PATCH 01/19] Updated spring boot to version 3.0 - Changed spring boot from 2.7 to 3.0 - Removed javax.el-api dependency (https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#jakarta-ee) - Updaed thymeleaf to use spring6 and springsecurity6 --- build.gradle | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index c72e6dc5..970747f0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - springBootVersion = '2.7.18' + springBootVersion = '3.0.13' } repositories { mavenCentral() @@ -56,16 +56,11 @@ dependencies { //TEMP APPLICATION PROPERTIES HELPER runtimeOnly 'org.springframework.boot:spring-boot-properties-migrator' - - implementation 'javax.el:javax.el-api:2.2.5' implementation "be.woutschoovaerts:mollie:3.6.1" - - implementation 'org.thymeleaf:thymeleaf-spring5' - implementation 'org.thymeleaf:thymeleaf' - implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' - implementation 'org.thymeleaf.extras:thymeleaf-extras-java8time' - + implementation 'org.thymeleaf:thymeleaf-spring6' + implementation 'org.thymeleaf:thymeleaf' + implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' implementation 'com.google.guava:guava:32.0.0-jre' implementation 'org.hibernate.validator:hibernate-validator' From 5c2d1b1109bc10501cc96b89c1fbc727c1f47caa Mon Sep 17 00:00:00 2001 From: Joshua Gort Date: Sun, 5 May 2024 18:25:13 +0200 Subject: [PATCH 02/19] Changed port to 8080 in devcontainer config so that logging in works --- config/application-devcontainer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application-devcontainer.yml b/config/application-devcontainer.yml index a0dca394..a21987c8 100644 --- a/config/application-devcontainer.yml +++ b/config/application-devcontainer.yml @@ -76,7 +76,7 @@ logging.level.web: DEBUG # Serve connect server: - port: 80 + port: 8080 servlet.context-path: / # CH Connect Configuration From a346e24babdff00d80122b6de05ad2ae50f8f3c6 Mon Sep 17 00:00:00 2001 From: Joshua Gort Date: Sun, 5 May 2024 18:27:11 +0200 Subject: [PATCH 03/19] Moved javax imports to jakarta https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#jakarta-ee --- .../wisv/events/api/request/ProductDto.java | 2 +- .../events/core/model/customer/Customer.java | 10 ++++----- .../events/core/model/document/Document.java | 6 ++--- .../wisv/events/core/model/event/Event.java | 22 +++++++++---------- .../wisv/events/core/model/order/Order.java | 20 ++++++++--------- .../events/core/model/order/OrderProduct.java | 4 ++-- .../events/core/model/product/Product.java | 2 +- .../wisv/events/core/model/ticket/Ticket.java | 12 +++++----- .../events/core/model/webhook/Webhook.java | 8 +++---- .../core/model/webhook/WebhookTask.java | 10 ++++----- .../core/service/mail/MailServiceImpl.java | 9 ++++---- .../service/ticket/TicketServiceImpl.java | 2 +- .../controller/WebshopIndexController.java | 2 +- .../controller/WebshopTicketController.java | 2 +- .../webshop/service/PaymentsServiceImpl.java | 2 +- 15 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/main/java/ch/wisv/events/api/request/ProductDto.java b/src/main/java/ch/wisv/events/api/request/ProductDto.java index 480331d5..69f02910 100644 --- a/src/main/java/ch/wisv/events/api/request/ProductDto.java +++ b/src/main/java/ch/wisv/events/api/request/ProductDto.java @@ -1,6 +1,6 @@ package ch.wisv.events.api.request; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import ch.wisv.events.core.util.VatRate; import lombok.Getter; diff --git a/src/main/java/ch/wisv/events/core/model/customer/Customer.java b/src/main/java/ch/wisv/events/core/model/customer/Customer.java index 2521e0a0..427cf978 100644 --- a/src/main/java/ch/wisv/events/core/model/customer/Customer.java +++ b/src/main/java/ch/wisv/events/core/model/customer/Customer.java @@ -5,11 +5,11 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.Data; import lombok.Getter; diff --git a/src/main/java/ch/wisv/events/core/model/document/Document.java b/src/main/java/ch/wisv/events/core/model/document/Document.java index fa24a0aa..6baa8960 100644 --- a/src/main/java/ch/wisv/events/core/model/document/Document.java +++ b/src/main/java/ch/wisv/events/core/model/document/Document.java @@ -1,8 +1,8 @@ package ch.wisv.events.core.model.document; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; import lombok.Data; /** diff --git a/src/main/java/ch/wisv/events/core/model/event/Event.java b/src/main/java/ch/wisv/events/core/model/event/Event.java index b9df4761..41e6d7e7 100644 --- a/src/main/java/ch/wisv/events/core/model/event/Event.java +++ b/src/main/java/ch/wisv/events/core/model/event/Event.java @@ -6,22 +6,22 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; -import javax.validation.constraints.NotNull; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderBy; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.Setter; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat.ISO; diff --git a/src/main/java/ch/wisv/events/core/model/order/Order.java b/src/main/java/ch/wisv/events/core/model/order/Order.java index 2126284b..2efc76f7 100644 --- a/src/main/java/ch/wisv/events/core/model/order/Order.java +++ b/src/main/java/ch/wisv/events/core/model/order/Order.java @@ -6,16 +6,16 @@ import java.util.HashMap; import java.util.List; import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import javax.validation.constraints.NotNull; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + +import jakarta.validation.constraints.NotNull; import ch.wisv.events.core.util.VatRate; import lombok.AccessLevel; diff --git a/src/main/java/ch/wisv/events/core/model/order/OrderProduct.java b/src/main/java/ch/wisv/events/core/model/order/OrderProduct.java index 3eb6f30b..a88a84b3 100644 --- a/src/main/java/ch/wisv/events/core/model/order/OrderProduct.java +++ b/src/main/java/ch/wisv/events/core/model/order/OrderProduct.java @@ -2,8 +2,8 @@ import ch.wisv.events.core.model.product.Product; -import javax.persistence.*; -import javax.validation.constraints.NotNull; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import ch.wisv.events.core.util.VatRate; import lombok.AccessLevel; diff --git a/src/main/java/ch/wisv/events/core/model/product/Product.java b/src/main/java/ch/wisv/events/core/model/product/Product.java index dc95d8ee..65782ac9 100644 --- a/src/main/java/ch/wisv/events/core/model/product/Product.java +++ b/src/main/java/ch/wisv/events/core/model/product/Product.java @@ -6,7 +6,7 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import javax.persistence.*; +import jakarta.persistence.*; import ch.wisv.events.core.model.event.Event; import ch.wisv.events.core.util.VatRate; diff --git a/src/main/java/ch/wisv/events/core/model/ticket/Ticket.java b/src/main/java/ch/wisv/events/core/model/ticket/Ticket.java index e76f9fa5..69ce0643 100644 --- a/src/main/java/ch/wisv/events/core/model/ticket/Ticket.java +++ b/src/main/java/ch/wisv/events/core/model/ticket/Ticket.java @@ -8,11 +8,11 @@ import java.time.LocalDateTime; import java.util.UUID; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.validation.constraints.NotNull; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Data; @@ -39,7 +39,7 @@ public class Ticket { /** * Customer which owns the Ticket. */ - @ManyToOne(cascade = {javax.persistence.CascadeType.ALL}) + @ManyToOne(cascade = {jakarta.persistence.CascadeType.ALL}) public Order order; /** diff --git a/src/main/java/ch/wisv/events/core/model/webhook/Webhook.java b/src/main/java/ch/wisv/events/core/model/webhook/Webhook.java index 97d3897a..40278ac0 100644 --- a/src/main/java/ch/wisv/events/core/model/webhook/Webhook.java +++ b/src/main/java/ch/wisv/events/core/model/webhook/Webhook.java @@ -3,10 +3,10 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; import lombok.Data; @Entity diff --git a/src/main/java/ch/wisv/events/core/model/webhook/WebhookTask.java b/src/main/java/ch/wisv/events/core/model/webhook/WebhookTask.java index a22a5bd7..5fc89edb 100644 --- a/src/main/java/ch/wisv/events/core/model/webhook/WebhookTask.java +++ b/src/main/java/ch/wisv/events/core/model/webhook/WebhookTask.java @@ -1,11 +1,11 @@ package ch.wisv.events.core.model.webhook; import java.time.LocalDateTime; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToOne; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; import lombok.Data; import org.json.simple.JSONObject; diff --git a/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java b/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java index 65d20e39..68d79fea 100644 --- a/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java +++ b/src/main/java/ch/wisv/events/core/service/mail/MailServiceImpl.java @@ -11,9 +11,9 @@ import java.net.URL; import java.util.List; import java.util.Locale; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import javax.validation.constraints.NotNull; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import jakarta.validation.constraints.NotNull; import ch.wisv.events.core.service.ticket.TicketService; import ch.wisv.events.core.util.QrCode; @@ -29,8 +29,7 @@ import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; import org.thymeleaf.context.Context; -import org.thymeleaf.spring5.SpringTemplateEngine; - +import org.thymeleaf.spring6.SpringTemplateEngine; /** * MailService implementation. */ diff --git a/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java b/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java index 14bd68f8..4a50c351 100644 --- a/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java +++ b/src/main/java/ch/wisv/events/core/service/ticket/TicketServiceImpl.java @@ -24,7 +24,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; /** * TicketServiceImpl class. diff --git a/src/main/java/ch/wisv/events/webshop/controller/WebshopIndexController.java b/src/main/java/ch/wisv/events/webshop/controller/WebshopIndexController.java index e7702ddd..a6c94c3d 100644 --- a/src/main/java/ch/wisv/events/webshop/controller/WebshopIndexController.java +++ b/src/main/java/ch/wisv/events/webshop/controller/WebshopIndexController.java @@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; /** * WebshopIndexController class. diff --git a/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java b/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java index 39913a96..3e4d05cd 100644 --- a/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java +++ b/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java @@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.IOException; diff --git a/src/main/java/ch/wisv/events/webshop/service/PaymentsServiceImpl.java b/src/main/java/ch/wisv/events/webshop/service/PaymentsServiceImpl.java index 63bb17cf..8ab5e02d 100644 --- a/src/main/java/ch/wisv/events/webshop/service/PaymentsServiceImpl.java +++ b/src/main/java/ch/wisv/events/webshop/service/PaymentsServiceImpl.java @@ -15,7 +15,7 @@ import ch.wisv.events.core.service.mail.MailService; import ch.wisv.events.core.service.order.OrderService; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; From eaf08824fd2e7cbaa3a77480b49fe2fffbc1c5b4 Mon Sep 17 00:00:00 2001 From: Joshua Gort Date: Sun, 5 May 2024 18:29:27 +0200 Subject: [PATCH 04/19] Fix websecurityconfigureradapter Renamed authorizeRequests, antMatchers and ignoringMatchers to new versions - https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter - https://stackoverflow.com/questions/74609057/how-to-fix-spring-authorizerequests-is-deprecated --- .../ch/wisv/events/ChConnectConfiguration.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/wisv/events/ChConnectConfiguration.java b/src/main/java/ch/wisv/events/ChConnectConfiguration.java index eb146c0f..d48ca199 100644 --- a/src/main/java/ch/wisv/events/ChConnectConfiguration.java +++ b/src/main/java/ch/wisv/events/ChConnectConfiguration.java @@ -12,7 +12,7 @@ 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.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest; import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService; @@ -20,6 +20,7 @@ import org.springframework.security.oauth2.core.oidc.OidcIdToken; import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; import org.springframework.security.oauth2.core.oidc.user.OidcUser; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.csrf.CookieCsrfTokenRepository; import org.springframework.validation.annotation.Validated; import org.springframework.web.cors.CorsConfigurationSource; @@ -36,7 +37,7 @@ @ConfigurationProperties(prefix = "wisvch.connect") @Validated @Profile("!test") -public class ChConnectConfiguration extends WebSecurityConfigurerAdapter { +public class ChConnectConfiguration { /** * Groups that are admin in the system. @@ -64,14 +65,15 @@ public class ChConnectConfiguration extends WebSecurityConfigurerAdapter { * @param http * @throws Exception */ - public void configure(HttpSecurity http) throws Exception { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .cors() .and() .csrf() - .and().authorizeRequests() - .antMatchers("/administrator/**").hasRole("ADMIN") - .antMatchers("/", "/management/health").permitAll() + .and().authorizeHttpRequests() + .requestMatchers("/administrator/**").hasRole("ADMIN") + .requestMatchers("/", "/management/health").permitAll() .anyRequest().permitAll() .and() .logout() @@ -79,9 +81,10 @@ public void configure(HttpSecurity http) throws Exception { .and() .csrf() .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) - .ignoringAntMatchers("/api/v1/**") + .ignoringRequestMatchers("/api/v1/**") .and() .oauth2Login().userInfoEndpoint().oidcUserService(oidcUserService()); + return http.build(); } /** From ecaf4fc8e92547a5b51565a7e4300e5fc1707633 Mon Sep 17 00:00:00 2001 From: Joshua Gort Date: Sun, 5 May 2024 18:31:13 +0200 Subject: [PATCH 05/19] Remove Java8TimeDialect TODO: Check whether this breaks anything --- .../ch/wisv/events/EventsApplication.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/wisv/events/EventsApplication.java b/src/main/java/ch/wisv/events/EventsApplication.java index 58db039e..22ecff7c 100644 --- a/src/main/java/ch/wisv/events/EventsApplication.java +++ b/src/main/java/ch/wisv/events/EventsApplication.java @@ -6,7 +6,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters; import org.springframework.scheduling.annotation.EnableScheduling; -import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect; /** * EventsApplication class. @@ -26,14 +25,14 @@ public static void main(String[] args) { SpringApplication.run(EventsApplication.class, args); } - /** - * Enables Time formating in thymeleaf. - * - * @return Java8TimeDialect - */ - @Bean - public Java8TimeDialect java8TimeDialect() { - return new Java8TimeDialect(); - } + // /** + // * Enables Time formating in thymeleaf. + // * + // * @return Java8TimeDialect + // */ + // @Bean + // public Java8TimeDialect java8TimeDialect() { + // return new Java8TimeDialect(); + // } } From 7cebd7230d445419e3c559e6641b2b14df9c251e Mon Sep 17 00:00:00 2001 From: Joshua Gort Date: Sun, 5 May 2024 18:32:03 +0200 Subject: [PATCH 06/19] Temp fix validation errors becuse of NotNull constraint in Order TODO: Figure out how to keep this constraint? --- src/main/java/ch/wisv/events/core/model/order/Order.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/wisv/events/core/model/order/Order.java b/src/main/java/ch/wisv/events/core/model/order/Order.java index 2efc76f7..79873fb3 100644 --- a/src/main/java/ch/wisv/events/core/model/order/Order.java +++ b/src/main/java/ch/wisv/events/core/model/order/Order.java @@ -51,7 +51,7 @@ public class Order { * Field customer customer that order this. */ @ManyToOne - @NotNull + // @NotNull private Customer owner; /** @@ -75,7 +75,7 @@ public class Order { /** * Field createdBy the name of the person who created the order. */ - @NotNull + // @NotNull private String createdBy; /** From 2839847d3ee9181d8f8c9bb857c7b8837afff96b Mon Sep 17 00:00:00 2001 From: Joshua Gort Date: Mon, 6 May 2024 13:18:34 +0200 Subject: [PATCH 07/19] Fix trailing slashes and html errs due to deprecated #httpServletRequest --- .../java/ch/wisv/events/WebConfiguration.java | 15 ++++++++++++ .../resources/templates/admin/sidebar.html | 24 +++++++------------ .../templates/sales/stats/sidebar.html | 6 ++--- 3 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 src/main/java/ch/wisv/events/WebConfiguration.java diff --git a/src/main/java/ch/wisv/events/WebConfiguration.java b/src/main/java/ch/wisv/events/WebConfiguration.java new file mode 100644 index 00000000..2a3ea9af --- /dev/null +++ b/src/main/java/ch/wisv/events/WebConfiguration.java @@ -0,0 +1,15 @@ +package ch.wisv.events; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfiguration implements WebMvcConfigurer { + + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + configurer.setUseTrailingSlashMatch(true); + } + +} \ No newline at end of file diff --git a/src/main/resources/templates/admin/sidebar.html b/src/main/resources/templates/admin/sidebar.html index 28b7e251..a90860f4 100644 --- a/src/main/resources/templates/admin/sidebar.html +++ b/src/main/resources/templates/admin/sidebar.html @@ -6,56 +6,48 @@