From 77e0f1827ba1dadd9218b7f252b410983dbd83f2 Mon Sep 17 00:00:00 2001 From: Marc Giffing Date: Fri, 22 Mar 2024 19:58:24 +0100 Subject: [PATCH] Upgrade to Spring Boot 3.2 and Wicket 10 and Java 17 #196 --- pom.xml | 13 ++- wicket-spring-boot-context/pom.xml | 2 +- wicket-spring-boot-starter-example/pom.xml | 13 ++- .../SpringSecurityWicketSessionResolver.java | 11 +- .../WicketWebSecurityAdapterConfig.java | 109 +++++++++--------- .../boot/example/web/WicketBaseIntTest.java | 9 +- wicket-spring-boot-starter/pom.xml | 2 +- 7 files changed, 87 insertions(+), 72 deletions(-) diff --git a/pom.xml b/pom.xml index a324f331..59c3ca0d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.giffing.wicket.spring.boot.starter wicket-spring-boot-starter-parent - 4.0.0-M1 + 4.0.0 pom Wicket Spring Boot Starter Parent @@ -22,7 +22,7 @@ org.springframework.boot spring-boot-starter-parent - 3.0.8 + 3.2.4 @@ -54,8 +54,8 @@ UTF-8 17 1.8.0 - 10.0.0-M1 - 10.0.0-M1 + 10.0.0 + 10.0.0 @@ -203,6 +203,11 @@ wicket-source 9.0.0 + + org.apache.wicket + wicket-tester + ${wicket.version} + org.wicketstuff diff --git a/wicket-spring-boot-context/pom.xml b/wicket-spring-boot-context/pom.xml index af4ee98f..c575df0d 100644 --- a/wicket-spring-boot-context/pom.xml +++ b/wicket-spring-boot-context/pom.xml @@ -4,7 +4,7 @@ com.giffing.wicket.spring.boot.starter wicket-spring-boot-starter-parent - 4.0.0-M1 + 4.0.0 wicket-spring-boot-context diff --git a/wicket-spring-boot-starter-example/pom.xml b/wicket-spring-boot-starter-example/pom.xml index bc70a92e..10817e06 100644 --- a/wicket-spring-boot-starter-example/pom.xml +++ b/wicket-spring-boot-starter-example/pom.xml @@ -5,7 +5,7 @@ com.giffing.wicket.spring.boot.starter wicket-spring-boot-starter-parent - 4.0.0-M1 + 4.0.0 .. @@ -73,6 +73,10 @@ de.agilecoders.wicket.webjars wicket-webjars + + jakarta.xml.bind + jakarta.xml.bind-api + org.wicketstuff wicketstuff-serializer-fast2 @@ -85,7 +89,7 @@ de.agilecoders.wicket jquery-selectors - 3.0.4 + 4.0.2 org.liquibase @@ -109,6 +113,11 @@ spring-boot-starter-test test + + org.apache.wicket + wicket-tester + test + org.hibernate.orm diff --git a/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/web/security/SpringSecurityWicketSessionResolver.java b/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/web/security/SpringSecurityWicketSessionResolver.java index 0d7a0ef1..21338b7c 100644 --- a/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/web/security/SpringSecurityWicketSessionResolver.java +++ b/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/web/security/SpringSecurityWicketSessionResolver.java @@ -1,14 +1,13 @@ package com.giffing.wicket.spring.boot.example.web.security; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - +import com.giffing.wicket.spring.boot.starter.web.servlet.websocket.WicketSessionResolver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.session.FindByIndexNameSessionRepository; import org.springframework.session.Session; -import com.giffing.wicket.spring.boot.starter.web.servlet.websocket.WicketSessionResolver; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class SpringSecurityWicketSessionResolver implements WicketSessionResolver { @@ -18,7 +17,7 @@ public class SpringSecurityWicketSessionResolver implements WicketSessionResolve @Override public List resolve(Object identifier) { Map findByPrincipalName = sessions.findByPrincipalName(identifier.toString()); - return findByPrincipalName.keySet().stream().collect(Collectors.toList()); + return new ArrayList<>(findByPrincipalName.keySet()); } } diff --git a/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/web/security/WicketWebSecurityAdapterConfig.java b/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/web/security/WicketWebSecurityAdapterConfig.java index 278a2be1..97d49c45 100644 --- a/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/web/security/WicketWebSecurityAdapterConfig.java +++ b/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/web/security/WicketWebSecurityAdapterConfig.java @@ -7,6 +7,9 @@ import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; 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.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; +import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -19,67 +22,67 @@ /** * Default Spring Boot Wicket security getting started configuration. Its only * active if there is not other {@link SecurityFilterChain} bean is present. - * + *

* Holds hard coded users which should only be used to get started - * - * @author Marc Giffing * + * @author Marc Giffing */ @Configuration @EnableWebSecurity public class WicketWebSecurityAdapterConfig { - @ConditionalOnMissingBean - @Bean - public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { - return authenticationConfiguration.getAuthenticationManager(); - } - - @ConditionalOnMissingBean - @Bean - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http - .securityContext(ctx -> ctx.requireExplicitSave(false)) - .csrf().disable() - .authorizeHttpRequests().requestMatchers("/**").permitAll() - .and().logout().permitAll(); - http.headers().frameOptions().disable(); - return http.build(); - } - - @Bean - public static BCryptPasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } + @ConditionalOnMissingBean + @Bean + public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { + return authenticationConfiguration.getAuthenticationManager(); + } + + @ConditionalOnMissingBean + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + return http + .securityContext(ctx -> ctx.requireExplicitSave(false)) + .csrf(AbstractHttpConfigurer::disable) + .authorizeHttpRequests(authorizeHttpRequests -> + authorizeHttpRequests.requestMatchers("/**").permitAll()) + .logout(LogoutConfigurer::permitAll) + .headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) + .build(); + } + + @Bean + public static BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Bean + //TODO Add Wicket Issue - problem with semicolon in wicket websocket url. Allow semicolon. + public HttpFirewall allowUrlEncodedSlashHttpFirewall() { + StrictHttpFirewall fw = new StrictHttpFirewall(); + fw.setAllowSemicolon(true); + return fw; + } - @Bean - //TODO Add Wicket Issue - problem with semicolon in wicket websocket url. Allow semicolon. - public HttpFirewall allowUrlEncodedSlashHttpFirewall() { - StrictHttpFirewall fw = new StrictHttpFirewall(); - fw.setAllowSemicolon(true); - return fw; - } + @ConditionalOnMissingBean + @Bean + public UserDetailsService userDetailsService(final PasswordEncoder passwordEncoder) { + InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); + manager.createUser( + User.withUsername("admin") + .password(passwordEncoder.encode("admin")) + .authorities("USER", "ADMIN") + .build()); + manager.createUser( + User.withUsername("customer") + .password(passwordEncoder.encode("customer")) + .authorities("USER", "ADMIN") + .build()); + return manager; + } - @ConditionalOnMissingBean - @Bean - public UserDetailsService userDetailsService(final PasswordEncoder passwordEncoder) { - InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser( - User.withUsername("admin") - .password(passwordEncoder.encode("admin")) - .authorities("USER", "ADMIN") - .build()); - manager.createUser( - User.withUsername("customer") - .password(passwordEncoder.encode("customer")) - .authorities("USER", "ADMIN") - .build()); - return manager; - } - - //@Bean - //public WicketSessionResolver springSecurityWicketSessionResolver() { - // return new SpringSecurityWicketSessionResolver(); - //} + //@Bean + //public WicketSessionResolver springSecurityWicketSessionResolver() { + // return new SpringSecurityWicketSessionResolver(); + //} } diff --git a/wicket-spring-boot-starter-example/src/test/java/com/giffing/wicket/spring/boot/example/web/WicketBaseIntTest.java b/wicket-spring-boot-starter-example/src/test/java/com/giffing/wicket/spring/boot/example/web/WicketBaseIntTest.java index 934da472..c7af303c 100644 --- a/wicket-spring-boot-starter-example/src/test/java/com/giffing/wicket/spring/boot/example/web/WicketBaseIntTest.java +++ b/wicket-spring-boot-starter-example/src/test/java/com/giffing/wicket/spring/boot/example/web/WicketBaseIntTest.java @@ -1,5 +1,9 @@ package com.giffing.wicket.spring.boot.example.web; +import com.giffing.wicket.spring.boot.example.WicketApplication; +import com.giffing.wicket.spring.boot.example.web.pages.login.LoginPage; +import com.giffing.wicket.spring.boot.starter.configuration.extensions.external.spring.security.SecureWebSession; +import com.giffing.wicket.spring.boot.starter.web.servlet.websocket.WebSocketMessageBroadcaster; import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTester; @@ -11,11 +15,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -import com.giffing.wicket.spring.boot.example.WicketApplication; -import com.giffing.wicket.spring.boot.example.web.pages.login.LoginPage; -import com.giffing.wicket.spring.boot.starter.configuration.extensions.external.spring.security.SecureWebSession; -import com.giffing.wicket.spring.boot.starter.web.servlet.websocket.WebSocketMessageBroadcaster; - /** * Test class for initialize Wicket & Spring Boot only in the web package. All * external spring beans have to be mocked. diff --git a/wicket-spring-boot-starter/pom.xml b/wicket-spring-boot-starter/pom.xml index f441c029..80ffb650 100644 --- a/wicket-spring-boot-starter/pom.xml +++ b/wicket-spring-boot-starter/pom.xml @@ -4,7 +4,7 @@ com.giffing.wicket.spring.boot.starter wicket-spring-boot-starter-parent - 4.0.0-M1 + 4.0.0 ..