Skip to content

Commit

Permalink
Upgrade to Spring Boot 3.2 and Wicket 10 and Java 17 #196
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcGiffing committed Mar 22, 2024
1 parent 22ea715 commit 77e0f18
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 72 deletions.
13 changes: 9 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter-parent</artifactId>
<version>4.0.0-M1</version>
<version>4.0.0</version>
<packaging>pom</packaging>

<name>Wicket Spring Boot Starter Parent</name>
Expand All @@ -22,7 +22,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.8</version>
<version>3.2.4</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -54,8 +54,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<apache-shiro.version>1.8.0</apache-shiro.version>
<wicket.version>10.0.0-M1</wicket.version>
<wicketstuff.version>10.0.0-M1</wicketstuff.version>
<wicket.version>10.0.0</wicket.version>
<wicketstuff.version>10.0.0</wicketstuff.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -203,6 +203,11 @@
<artifactId>wicket-source</artifactId>
<version>9.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-tester</artifactId>
<version>${wicket.version}</version>
</dependency>
<!-- Security - Apache Shiro -->
<dependency>
<groupId>org.wicketstuff</groupId>
Expand Down
2 changes: 1 addition & 1 deletion wicket-spring-boot-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter-parent</artifactId>
<version>4.0.0-M1</version>
<version>4.0.0</version>
</parent>

<artifactId>wicket-spring-boot-context</artifactId>
Expand Down
13 changes: 11 additions & 2 deletions wicket-spring-boot-starter-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter-parent</artifactId>
<version>4.0.0-M1</version>
<version>4.0.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down Expand Up @@ -73,6 +73,10 @@
<groupId>de.agilecoders.wicket.webjars</groupId>
<artifactId>wicket-webjars</artifactId>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicketstuff-serializer-fast2</artifactId>
Expand All @@ -85,7 +89,7 @@
<dependency>
<groupId>de.agilecoders.wicket</groupId>
<artifactId>jquery-selectors</artifactId>
<version>3.0.4</version>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
Expand All @@ -109,6 +113,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-tester</artifactId>
<scope>test</scope>
</dependency>
<!-- To provide the annotation processor in the IDE's classpath -->
<dependency>
<groupId>org.hibernate.orm</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -18,7 +17,7 @@ public class SpringSecurityWicketSessionResolver implements WicketSessionResolve
@Override
public List<String> resolve(Object identifier) {
Map<String, ? extends Session> findByPrincipalName = sessions.findByPrincipalName(identifier.toString());
return findByPrincipalName.keySet().stream().collect(Collectors.toList());
return new ArrayList<>(findByPrincipalName.keySet());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
* <p>
* 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();
//}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion wicket-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter-parent</artifactId>
<version>4.0.0-M1</version>
<version>4.0.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down

0 comments on commit 77e0f18

Please sign in to comment.