Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 33def00

Browse files
committed
update to Spring Boot 3
1 parent e26754e commit 33def00

File tree

11 files changed

+160
-123
lines changed

11 files changed

+160
-123
lines changed

‎README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ You can have an overview of our Spring Boot Server with the diagram below:
1818
For more detail, please visit:
1919
> [Spring Boot, MongoDB: JWT Authentication with Spring Security](https://bezkoder.com/spring-boot-jwt-auth-mongodb/)
2020
21+
> [Using HttpOnly Cookie](https://www.bezkoder.com/spring-boot-mongodb-login-example/)
22+
2123
Working with Front-end:
2224
> [Vue](https://www.bezkoder.com/jwt-vue-vuex-authentication/)
2325
@@ -32,6 +34,16 @@ More Practice:
3234
3335
> [Spring Boot + GraphQL + MongoDB example](https://www.bezkoder.com/spring-boot-graphql-mongodb-example-graphql-java/)
3436
37+
> [Spring Boot Repository Unit Test with @DataJpaTest](https://bezkoder.com/spring-boot-unit-test-jpa-repo-datajpatest/)
38+
39+
> [Spring Boot Rest Controller Unit Test with @WebMvcTest](https://www.bezkoder.com/spring-boot-webmvctest/)
40+
41+
> Validation: [Spring Boot Validate Request Body](https://www.bezkoder.com/spring-boot-validate-request-body/)
42+
43+
> Documentation: [Spring Boot and Swagger 3 example](https://www.bezkoder.com/spring-boot-swagger-3/)
44+
45+
> Caching: [Spring Boot Redis Cache example](https://www.bezkoder.com/spring-boot-redis-cache-example/)
46+
3547
Fullstack:
3648
> [Vue.js + Spring Boot + MongoDB example](https://www.bezkoder.com/spring-boot-vue-mongodb/)
3749
@@ -47,6 +59,10 @@ Fullstack:
4759
4860
> [Angular 14 + Spring Boot + MongoDB example](https://www.bezkoder.com/spring-boot-angular-14-mongodb/)
4961
62+
> [Angular 15 + Spring Boot + MongoDB example](https://www.bezkoder.com/spring-boot-angular-15-mongodb/)
63+
64+
> [Angular 16 + Spring Boot + MongoDB example](https://www.bezkoder.com/spring-boot-angular-16-mongodb/)
65+
5066
> [React + Spring Boot + MongoDB example](https://www.bezkoder.com/react-spring-boot-mongodb/)
5167
5268

‎pom.xml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>2.7.3</version>
9+
<version>3.1.0</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>com.bezkoder</groupId>
@@ -17,7 +17,7 @@
1717
JWT, MongoDB</description>
1818

1919
<properties>
20-
<java.version>1.8</java.version>
20+
<java.version>17</java.version>
2121
</properties>
2222

2323
<dependencies>
@@ -41,11 +41,25 @@
4141
<artifactId>spring-boot-starter-web</artifactId>
4242
</dependency>
4343

44-
<dependency>
45-
<groupId>io.jsonwebtoken</groupId>
46-
<artifactId>jjwt</artifactId>
47-
<version>0.9.1</version>
48-
</dependency>
44+
<dependency>
45+
<groupId>io.jsonwebtoken</groupId>
46+
<artifactId>jjwt-api</artifactId>
47+
<version>0.11.5</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>io.jsonwebtoken</groupId>
52+
<artifactId>jjwt-impl</artifactId>
53+
<version>0.11.5</version>
54+
<scope>runtime</scope>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>io.jsonwebtoken</groupId>
59+
<artifactId>jjwt-jackson</artifactId>
60+
<version>0.11.5</version>
61+
<scope>runtime</scope>
62+
</dependency>
4963

5064
<dependency>
5165
<groupId>org.springframework.boot</groupId>

‎src/main/java/com/bezkoder/spring/jwt/mongodb/controllers/AuthController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.Set;
66
import java.util.stream.Collectors;
77

8-
import javax.validation.Valid;
8+
import jakarta.validation.Valid;
99

1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.http.ResponseEntity;

‎src/main/java/com/bezkoder/spring/jwt/mongodb/models/User.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import java.util.HashSet;
44
import java.util.Set;
55

6-
import javax.validation.constraints.Email;
7-
import javax.validation.constraints.NotBlank;
8-
import javax.validation.constraints.Size;
6+
import jakarta.validation.constraints.Email;
7+
import jakarta.validation.constraints.NotBlank;
8+
import jakarta.validation.constraints.Size;
99

1010
import org.springframework.data.annotation.Id;
1111
import org.springframework.data.mongodb.core.mapping.DBRef;

‎src/main/java/com/bezkoder/spring/jwt/mongodb/payload/request/LoginRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.bezkoder.spring.jwt.mongodb.payload.request;
22

3-
import javax.validation.constraints.NotBlank;
3+
import jakarta.validation.constraints.NotBlank;
44

55
public class LoginRequest {
66
@NotBlank

‎src/main/java/com/bezkoder/spring/jwt/mongodb/payload/request/SignupRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.Set;
44

5-
import javax.validation.constraints.*;
5+
import jakarta.validation.constraints.*;
66

77
public class SignupRequest {
88
@NotBlank

‎src/main/java/com/bezkoder/spring/jwt/mongodb/security/WebSecurityConfig.java

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
88
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
99
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
10-
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
10+
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
1111
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1212
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1313
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@@ -23,78 +23,77 @@
2323

2424
@Configuration
2525
//@EnableWebSecurity
26-
@EnableGlobalMethodSecurity(
27-
// securedEnabled = true,
28-
// jsr250Enabled = true,
29-
prePostEnabled = true)
26+
@EnableMethodSecurity
27+
//(securedEnabled = true,
28+
//jsr250Enabled = true,
29+
//prePostEnabled = true) // by default
3030
public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
31-
@Autowired
32-
UserDetailsServiceImpl userDetailsService;
33-
34-
@Autowired
35-
private AuthEntryPointJwt unauthorizedHandler;
36-
37-
@Bean
38-
public AuthTokenFilter authenticationJwtTokenFilter() {
39-
return new AuthTokenFilter();
40-
}
41-
42-
//@Override
43-
//public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
44-
//authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
45-
//}
46-
47-
@Bean
31+
@Autowired
32+
UserDetailsServiceImpl userDetailsService;
33+
34+
@Autowired
35+
private AuthEntryPointJwt unauthorizedHandler;
36+
37+
@Bean
38+
public AuthTokenFilter authenticationJwtTokenFilter() {
39+
return new AuthTokenFilter();
40+
}
41+
42+
//@Override
43+
//public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
44+
//authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
45+
//}
46+
47+
@Bean
4848
public DaoAuthenticationProvider authenticationProvider() {
49-
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
50-
51-
authProvider.setUserDetailsService(userDetailsService);
52-
authProvider.setPasswordEncoder(passwordEncoder());
53-
54-
return authProvider;
49+
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
50+
51+
authProvider.setUserDetailsService(userDetailsService);
52+
authProvider.setPasswordEncoder(passwordEncoder());
53+
54+
return authProvider;
5555
}
5656

57-
//@Bean
58-
//@Override
59-
//public AuthenticationManager authenticationManagerBean() throws Exception {
60-
//return super.authenticationManagerBean();
61-
//}
62-
63-
@Bean
57+
//@Bean
58+
//@Override
59+
//public AuthenticationManager authenticationManagerBean() throws Exception {
60+
//return super.authenticationManagerBean();
61+
//}
62+
63+
@Bean
6464
public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {
6565
return authConfig.getAuthenticationManager();
6666
}
6767

68-
@Bean
69-
public PasswordEncoder passwordEncoder() {
70-
return new BCryptPasswordEncoder();
71-
}
72-
73-
//@Override
74-
//protected void configure(HttpSecurity http) throws Exception {
75-
//http.cors().and().csrf().disable()
76-
//.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
77-
//.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
78-
//.authorizeRequests().antMatchers("/api/auth/**").permitAll()
79-
//.antMatchers("/api/test/**").permitAll()
80-
//.anyRequest().authenticated();
68+
@Bean
69+
public PasswordEncoder passwordEncoder() {
70+
return new BCryptPasswordEncoder();
71+
}
72+
73+
//@Override
74+
//protected void configure(HttpSecurity http) throws Exception {
75+
//http.cors().and().csrf().disable()
76+
//.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
77+
//.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
78+
//.authorizeRequests().antMatchers("/api/auth/**").permitAll()
79+
//.antMatchers("/api/test/**").permitAll()
80+
//.anyRequest().authenticated();
8181
//
82-
//http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
83-
//}
84-
85-
@Bean
82+
//http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
83+
//}
84+
85+
@Bean
8686
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
87-
http.cors().and().csrf().disable()
88-
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
89-
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
90-
.authorizeRequests().antMatchers("/api/auth/**").permitAll()
91-
.antMatchers("/api/test/**").permitAll()
92-
.anyRequest().authenticated();
93-
87+
http.csrf(csrf -> csrf.disable())
88+
.exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedHandler))
89+
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
90+
.authorizeHttpRequests(auth -> auth.requestMatchers("/api/auth/**").permitAll().requestMatchers("/api/test/**")
91+
.permitAll().anyRequest().authenticated());
92+
9493
http.authenticationProvider(authenticationProvider());
9594

9695
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
97-
96+
9897
return http.build();
9998
}
10099
}

‎src/main/java/com/bezkoder/spring/jwt/mongodb/security/jwt/AuthEntryPointJwt.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import java.io.IOException;
44

5-
import javax.servlet.ServletException;
6-
import javax.servlet.http.HttpServletRequest;
7-
import javax.servlet.http.HttpServletResponse;
5+
import jakarta.servlet.ServletException;
6+
import jakarta.servlet.http.HttpServletRequest;
7+
import jakarta.servlet.http.HttpServletResponse;
88

99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;

‎src/main/java/com/bezkoder/spring/jwt/mongodb/security/jwt/AuthTokenFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import java.io.IOException;
44

5-
import javax.servlet.FilterChain;
6-
import javax.servlet.ServletException;
7-
import javax.servlet.http.HttpServletRequest;
8-
import javax.servlet.http.HttpServletResponse;
5+
import jakarta.servlet.FilterChain;
6+
import jakarta.servlet.ServletException;
7+
import jakarta.servlet.http.HttpServletRequest;
8+
import jakarta.servlet.http.HttpServletResponse;
99

1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /