Skip to content

Commit 27d1779

Browse files
authored
Merge pull request #39 from mirkoperillo/upgrade-spring-3
Upgrade to Spring Boot 3.4.1
2 parents 80c0d03 + f86d314 commit 27d1779

23 files changed

+509
-780
lines changed

pom.xml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<parent>
1616
<groupId>org.springframework.boot</groupId>
1717
<artifactId>spring-boot-starter-parent</artifactId>
18-
<version>2.7.7</version>
18+
<version>3.4.1</version>
1919
<relativePath /> <!-- lookup parent from repository -->
2020
</parent>
2121

@@ -30,12 +30,12 @@
3030
<groupId>org.springframework.boot</groupId>
3131
<artifactId>spring-boot-starter-web</artifactId>
3232
<exclusions>
33-
<exclusion>
33+
<exclusion>
3434
<!-- bloated dependency -->
35-
<artifactId>tomcat-embed-el</artifactId>
36-
<groupId>org.apache.tomcat.embed</groupId>
37-
</exclusion>
38-
</exclusions>
35+
<artifactId>tomcat-embed-el</artifactId>
36+
<groupId>org.apache.tomcat.embed</groupId>
37+
</exclusion>
38+
</exclusions>
3939
</dependency>
4040
<dependency>
4141
<groupId>org.springframework.boot</groupId>
@@ -47,25 +47,27 @@
4747
<exclusions>
4848
<exclusion>
4949
<!-- bloated dependency -->
50-
<artifactId>txw2</artifactId>
51-
<groupId>org.glassfish.jaxb</groupId>
50+
<artifactId>txw2</artifactId>
51+
<groupId>org.glassfish.jaxb</groupId>
5252
</exclusion>
53-
</exclusions>
53+
</exclusions>
5454
</dependency>
5555
<dependency>
56-
<groupId>org.springframework.mobile</groupId>
57-
<artifactId>spring-mobile-device</artifactId>
58-
<version>1.1.5.RELEASE</version>
56+
<groupId>io.jsonwebtoken</groupId>
57+
<artifactId>jjwt-api</artifactId>
58+
<version>0.12.6</version>
5959
</dependency>
60-
6160
<dependency>
6261
<groupId>io.jsonwebtoken</groupId>
63-
<artifactId>jjwt</artifactId>
64-
<version>0.6.0</version>
62+
<artifactId>jjwt-impl</artifactId>
63+
<version>0.12.6</version>
64+
<scope>runtime</scope>
6565
</dependency>
6666
<dependency>
67-
<groupId>javax.xml.bind</groupId>
68-
<artifactId>jaxb-api</artifactId>
67+
<groupId>io.jsonwebtoken</groupId>
68+
<artifactId>jjwt-jackson</artifactId>
69+
<version>0.12.6</version>
70+
<scope>runtime</scope>
6971
</dependency>
7072

7173
<dependency>
@@ -141,5 +143,4 @@
141143
</plugins>
142144
</build>
143145

144-
145146
</project>

src/main/java/com/bfwg/Application.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ public class Application {
99
public static void main(String[] args) {
1010
SpringApplication.run(Application.class, args);
1111
}
12-
}
13-
14-
12+
}

src/main/java/com/bfwg/common/DeviceProvider.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/main/java/com/bfwg/common/TimeProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
@Component
1212
public class TimeProvider implements Serializable {
1313

14-
private static final long serialVersionUID = -3301695478208950415L;
14+
private static final long serialVersionUID = -3301695478208950415L;
1515

16-
public Date now() {
17-
return new Date();
18-
}
16+
public Date now() {
17+
return new Date();
18+
}
1919
}

src/main/java/com/bfwg/config/WebConfig.java

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.bfwg.config;
22

3+
import static org.springframework.security.web.util.matcher.AntPathRequestMatcher.antMatcher;
4+
35
import org.springframework.beans.factory.annotation.Autowired;
46
import org.springframework.context.annotation.Bean;
57
import org.springframework.context.annotation.Configuration;
68
import org.springframework.http.HttpMethod;
79
import org.springframework.security.authentication.AuthenticationManager;
810
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
911
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
10-
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
12+
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
1113
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1214
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1315
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
@@ -27,7 +29,7 @@
2729

2830
@Configuration
2931
@EnableWebSecurity
30-
@EnableGlobalMethodSecurity(prePostEnabled = true)
32+
@EnableMethodSecurity(prePostEnabled = true)
3133
public class WebSecurityConfig {
3234

3335
@Autowired
@@ -41,8 +43,7 @@ public class WebSecurityConfig {
4143

4244
@Autowired
4345
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
44-
auth.userDetailsService(jwtUserDetailsService)
45-
.passwordEncoder(passwordEncoder);
46+
auth.userDetailsService(jwtUserDetailsService).passwordEncoder(passwordEncoder);
4647
}
4748

4849
@Autowired
@@ -56,46 +57,32 @@ public AuthenticationManager authenticationManager(AuthenticationConfiguration a
5657

5758
@Bean
5859
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
59-
http
60-
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
61-
.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint).and()
62-
.authorizeRequests()
63-
.antMatchers(
64-
HttpMethod.GET,
65-
"/",
66-
"/auth/**",
67-
"/webjars/**",
68-
"/*.html",
69-
"/favicon.ico",
70-
"/**/*.html",
71-
"/**/*.css",
72-
"/**/*.js")
73-
.permitAll()
74-
.antMatchers("/auth/**").permitAll()
75-
.anyRequest().authenticated().and()
76-
.addFilterBefore(new TokenAuthenticationFilter(tokenHelper, jwtUserDetailsService),
77-
BasicAuthenticationFilter.class);
7860

79-
http.csrf().disable();
61+
http.addFilterBefore(new TokenAuthenticationFilter(tokenHelper, jwtUserDetailsService),
62+
BasicAuthenticationFilter.class)
63+
.authorizeHttpRequests(authorize -> authorize
64+
.requestMatchers(antMatcher(HttpMethod.GET, "/"), antMatcher(HttpMethod.GET, "/auth/**"),
65+
antMatcher(HttpMethod.GET, "/webjars/**"), antMatcher(HttpMethod.GET, "/*.html"),
66+
antMatcher(HttpMethod.GET, "/favicon.ico"), antMatcher(HttpMethod.GET, "/**/*.html"),
67+
antMatcher(HttpMethod.GET, "/**/*.css"), antMatcher(HttpMethod.GET, "/**/*.js"))
68+
.permitAll().requestMatchers("/auth/**").permitAll().anyRequest().authenticated())
69+
.sessionManagement(sec -> sec.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
70+
.exceptionHandling(
71+
exceptionHandler -> exceptionHandler.authenticationEntryPoint(restAuthenticationEntryPoint))
72+
.csrf(csrf -> csrf.disable());
73+
8074
return http.build();
8175
}
8276

8377
@Bean
8478
public WebSecurityCustomizer webSecurityCustomizer() {
8579
// TokenAuthenticationFilter will ignore the below paths
8680
return (web) -> {
87-
web.ignoring().antMatchers(
88-
HttpMethod.POST,
89-
"/auth/login");
90-
web.ignoring().antMatchers(
91-
HttpMethod.GET,
92-
"/",
93-
"/webjars/**",
94-
"/*.html",
95-
"/favicon.ico",
96-
"/**/*.html",
97-
"/**/*.css",
98-
"/**/*.js");
81+
web.ignoring().requestMatchers(HttpMethod.POST, "/auth/login").requestMatchers(
82+
antMatcher(HttpMethod.GET, "/"), antMatcher(HttpMethod.GET, "/webjars/**"),
83+
antMatcher(HttpMethod.GET, "/*.html"), antMatcher(HttpMethod.GET, "/favicon.ico"),
84+
antMatcher(HttpMethod.GET, "/**/*.html"), antMatcher(HttpMethod.GET, "/**path/*.css"),
85+
antMatcher(HttpMethod.GET, "/**path/*.js"));
9986
};
10087
}
10188
}
Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,56 @@
11
package com.bfwg.model;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnore;
43
import org.springframework.security.core.GrantedAuthority;
54

6-
import javax.persistence.*;
5+
import com.fasterxml.jackson.annotation.JsonIgnore;
6+
7+
import jakarta.persistence.Column;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.EnumType;
10+
import jakarta.persistence.Enumerated;
11+
import jakarta.persistence.GeneratedValue;
12+
import jakarta.persistence.GenerationType;
13+
import jakarta.persistence.Id;
14+
import jakarta.persistence.Table;
715

816
/**
917
* Created by fan.jin on 2016-11-03.
1018
*/
1119

1220
@Entity
13-
@Table(name="AUTHORITY")
21+
@Table(name = "AUTHORITY")
1422
public class Authority implements GrantedAuthority {
1523

16-
@Id
17-
@Column(name="id")
18-
@GeneratedValue(strategy = GenerationType.IDENTITY)
19-
Long id;
20-
21-
@Enumerated( EnumType.STRING)
22-
@Column(name="name")
23-
UserRoleName name;
24-
25-
@Override
26-
public String getAuthority() {
27-
return name.name();
28-
}
29-
30-
public void setName(UserRoleName name) {
31-
this.name = name;
32-
}
33-
34-
@JsonIgnore
35-
public UserRoleName getName() {
36-
return name;
37-
}
38-
39-
@JsonIgnore
40-
public Long getId() {
41-
return id;
42-
}
43-
44-
public void setId(Long id) {
45-
this.id = id;
46-
}
24+
@Id
25+
@Column(name = "id")
26+
@GeneratedValue(strategy = GenerationType.IDENTITY)
27+
Long id;
28+
29+
@Enumerated(EnumType.STRING)
30+
@Column(name = "name")
31+
UserRoleName name;
32+
33+
@Override
34+
public String getAuthority() {
35+
return name.name();
36+
}
37+
38+
public void setName(UserRoleName name) {
39+
this.name = name;
40+
}
41+
42+
@JsonIgnore
43+
public UserRoleName getName() {
44+
return name;
45+
}
46+
47+
@JsonIgnore
48+
public Long getId() {
49+
return id;
50+
}
51+
52+
public void setId(Long id) {
53+
this.id = id;
54+
}
4755

4856
}

src/main/java/com/bfwg/model/User.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
import java.util.Collection;
55
import java.util.List;
66

7-
import javax.persistence.CascadeType;
8-
import javax.persistence.Column;
9-
import javax.persistence.Entity;
10-
import javax.persistence.FetchType;
11-
import javax.persistence.GeneratedValue;
12-
import javax.persistence.GenerationType;
13-
import javax.persistence.Id;
14-
import javax.persistence.JoinColumn;
15-
import javax.persistence.JoinTable;
16-
import javax.persistence.ManyToMany;
17-
import javax.persistence.Table;
18-
197
import org.springframework.security.core.GrantedAuthority;
208
import org.springframework.security.core.userdetails.UserDetails;
219

2210
import com.fasterxml.jackson.annotation.JsonIgnore;
2311

12+
import jakarta.persistence.CascadeType;
13+
import jakarta.persistence.Column;
14+
import jakarta.persistence.Entity;
15+
import jakarta.persistence.FetchType;
16+
import jakarta.persistence.GeneratedValue;
17+
import jakarta.persistence.GenerationType;
18+
import jakarta.persistence.Id;
19+
import jakarta.persistence.JoinColumn;
20+
import jakarta.persistence.JoinTable;
21+
import jakarta.persistence.ManyToMany;
22+
import jakarta.persistence.Table;
23+
2424
/**
2525
* Created by fan.jin on 2016-10-15.
2626
*/
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.bfwg.model;
22

33
public enum UserRoleName {
4-
ROLE_USER,
5-
ROLE_ADMIN
4+
ROLE_USER, ROLE_ADMIN
65
}

0 commit comments

Comments
 (0)