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 e26754e

Browse files
committed
update for new Spring Boot version
1 parent 8b3b772 commit e26754e

File tree

3 files changed

+81
-24
lines changed

3 files changed

+81
-24
lines changed

‎README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ More Practice:
3232
3333
> [Spring Boot + GraphQL + MongoDB example](https://www.bezkoder.com/spring-boot-graphql-mongodb-example-graphql-java/)
3434
35+
Fullstack:
36+
> [Vue.js + Spring Boot + MongoDB example](https://www.bezkoder.com/spring-boot-vue-mongodb/)
37+
38+
> [Angular 8 + Spring Boot + MongoDB example](https://www.bezkoder.com/angular-spring-boot-mongodb/)
39+
40+
> [Angular 10 + Spring Boot + MongoDB example](https://www.bezkoder.com/angular-10-spring-boot-mongodb/)
41+
42+
> [Angular 11 + Spring Boot + MongoDB example](https://www.bezkoder.com/angular-11-spring-boot-mongodb/)
43+
44+
> [Angular 12 + Spring Boot + MongoDB example](https://www.bezkoder.com/angular-12-spring-boot-mongodb/)
45+
46+
> [Angular 13 + Spring Boot + MongoDB example](https://www.bezkoder.com/angular-13-spring-boot-mongodb/)
47+
48+
> [Angular 14 + Spring Boot + MongoDB example](https://www.bezkoder.com/spring-boot-angular-14-mongodb/)
49+
50+
> [React + Spring Boot + MongoDB example](https://www.bezkoder.com/react-spring-boot-mongodb/)
51+
52+
3553
Run both Back-end & Front-end in one place:
3654
> [Integrate Angular with Spring Boot Rest API](https://www.bezkoder.com/integrate-angular-spring-boot/)
3755

‎pom.xml

Lines changed: 6 additions & 1 deletion
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.2.4.RELEASE</version>
9+
<version>2.7.3</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>com.bezkoder</groupId>
@@ -30,6 +30,11 @@
3030
<groupId>org.springframework.boot</groupId>
3131
<artifactId>spring-boot-starter-security</artifactId>
3232
</dependency>
33+
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-validation</artifactId>
37+
</dependency>
3338

3439
<dependency>
3540
<groupId>org.springframework.boot</groupId>

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

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@
44
import org.springframework.context.annotation.Bean;
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.security.authentication.AuthenticationManager;
7-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7+
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
8+
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
9+
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
810
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
911
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
10-
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
11-
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
12+
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
13+
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
1214
import org.springframework.security.config.http.SessionCreationPolicy;
1315
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1416
import org.springframework.security.crypto.password.PasswordEncoder;
17+
import org.springframework.security.web.SecurityFilterChain;
1518
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
1619

1720
import com.bezkoder.spring.jwt.mongodb.security.jwt.AuthEntryPointJwt;
1821
import com.bezkoder.spring.jwt.mongodb.security.jwt.AuthTokenFilter;
1922
import com.bezkoder.spring.jwt.mongodb.security.services.UserDetailsServiceImpl;
2023

2124
@Configuration
22-
@EnableWebSecurity
25+
//@EnableWebSecurity
2326
@EnableGlobalMethodSecurity(
2427
// securedEnabled = true,
2528
// jsr250Enabled = true,
2629
prePostEnabled = true)
27-
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
30+
public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
2831
@Autowired
2932
UserDetailsServiceImpl userDetailsService;
3033

@@ -36,31 +39,62 @@ public AuthTokenFilter authenticationJwtTokenFilter() {
3639
return new AuthTokenFilter();
3740
}
3841

39-
@Override
40-
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
41-
authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
42-
}
42+
// @Override
43+
// public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
44+
// authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
45+
// }
46+
47+
@Bean
48+
public DaoAuthenticationProvider authenticationProvider() {
49+
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
50+
51+
authProvider.setUserDetailsService(userDetailsService);
52+
authProvider.setPasswordEncoder(passwordEncoder());
53+
54+
return authProvider;
55+
}
4356

57+
// @Bean
58+
// @Override
59+
// public AuthenticationManager authenticationManagerBean() throws Exception {
60+
// return super.authenticationManagerBean();
61+
// }
62+
4463
@Bean
45-
@Override
46-
public AuthenticationManager authenticationManagerBean() throws Exception {
47-
return super.authenticationManagerBean();
48-
}
64+
public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {
65+
return authConfig.getAuthenticationManager();
66+
}
4967

5068
@Bean
5169
public PasswordEncoder passwordEncoder() {
5270
return new BCryptPasswordEncoder();
5371
}
5472

55-
@Override
56-
protected void configure(HttpSecurity http) throws Exception {
57-
http.cors().and().csrf().disable()
58-
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
59-
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
60-
.authorizeRequests().antMatchers("/api/auth/**").permitAll()
61-
.antMatchers("/api/test/**").permitAll()
62-
.anyRequest().authenticated();
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();
81+
//
82+
// http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
83+
// }
84+
85+
@Bean
86+
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+
94+
http.authenticationProvider(authenticationProvider());
6395

64-
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
65-
}
96+
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
97+
98+
return http.build();
99+
}
66100
}

0 commit comments

Comments
(0)

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