Skip to content

Commit 3e64506

Browse files
authored
Merge branch 'master' into master
2 parents 519f3fa + edaf308 commit 3e64506

File tree

3 files changed

+109
-53
lines changed

3 files changed

+109
-53
lines changed

README.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ For more detail, please visit:
2121

2222
For instruction: [Spring Boot Refresh Token with JWT example](https://bezkoder.com/spring-boot-refresh-token-jwt/)
2323

24+
## More Practice:
25+
> [Spring Boot File upload example with Multipart File](https://bezkoder.com/spring-boot-file-upload/)
26+
27+
> [Exception handling: @RestControllerAdvice example in Spring Boot](https://bezkoder.com/spring-boot-restcontrolleradvice/)
28+
29+
> [Spring Boot Repository Unit Test with @DataJpaTest](https://bezkoder.com/spring-boot-unit-test-jpa-repo-datajpatest/)
30+
31+
> [Spring Boot Pagination & Sorting example](https://www.bezkoder.com/spring-boot-pagination-sorting-example/)
32+
33+
Associations:
34+
> [Spring Boot One To Many example with Spring JPA, Hibernate](https://www.bezkoder.com/jpa-one-to-many/)
35+
36+
> [Spring Boot Many To Many example with Spring JPA, Hibernate](https://www.bezkoder.com/jpa-many-to-many/)
37+
38+
> [JPA One To One example with Spring Boot](https://www.bezkoder.com/jpa-one-to-one/)
39+
40+
Deployment:
41+
> [Deploy Spring Boot App on AWS – Elastic Beanstalk](https://www.bezkoder.com/deploy-spring-boot-aws-eb/)
42+
43+
> [Docker Compose Spring Boot and MySQL example](https://www.bezkoder.com/docker-compose-spring-boot-mysql/)
44+
2445
## Fullstack Authentication
2546

2647
> [Spring Boot + Vue.js JWT Authentication](https://bezkoder.com/spring-boot-vue-js-authentication-jwt-spring-security/)
@@ -33,6 +54,10 @@ For instruction: [Spring Boot Refresh Token with JWT example](https://bezkoder.c
3354
3455
> [Spring Boot + Angular 12 JWT Authentication](https://www.bezkoder.com/angular-12-spring-boot-jwt-auth/)
3556
57+
> [Spring Boot + Angular 13 JWT Authentication](https://www.bezkoder.com/angular-13-spring-boot-jwt-auth/)
58+
59+
> [Spring Boot + Angular 14 JWT Authentication](https://www.bezkoder.com/angular-14-spring-boot-jwt-auth/)
60+
3661
> [Spring Boot + React JWT Authentication](https://bezkoder.com/spring-boot-react-jwt-auth/)
3762
3863
## Fullstack CRUD App
@@ -69,6 +94,12 @@ For instruction: [Spring Boot Refresh Token with JWT example](https://bezkoder.c
6994
7095
> [Angular 13 + Spring Boot + PostgreSQL example](https://www.bezkoder.com/spring-boot-angular-13-postgresql/)
7196
97+
> [Angular 14 + Spring Boot + H2 Embedded Database example](https://www.bezkoder.com/spring-boot-angular-14-crud/)
98+
99+
> [Angular 14 + Spring Boot + MySQL example](https://www.bezkoder.com/spring-boot-angular-14-mysql/)
100+
101+
> [Angular 14 + Spring Boot + PostgreSQL example](https://www.bezkoder.com/spring-boot-angular-14-postgresql/)
102+
72103
> [React + Spring Boot + MySQL example](https://bezkoder.com/react-spring-boot-crud/)
73104
74105
> [React + Spring Boot + PostgreSQL example](https://bezkoder.com/spring-boot-react-postgresql/)
@@ -82,18 +113,6 @@ Run both Back-end & Front-end in one place:
82113
83114
> [Integrate Vue.js with Spring Boot Rest API](https://bezkoder.com/integrate-vue-spring-boot/)
84115
85-
More Practice:
86-
> [Spring Boot File upload example with Multipart File](https://bezkoder.com/spring-boot-file-upload/)
87-
88-
> [Exception handling: @RestControllerAdvice example in Spring Boot](https://bezkoder.com/spring-boot-restcontrolleradvice/)
89-
90-
> [Spring Boot Repository Unit Test with @DataJpaTest](https://bezkoder.com/spring-boot-unit-test-jpa-repo-datajpatest/)
91-
92-
Deployment:
93-
> [Deploy Spring Boot App on AWS – Elastic Beanstalk](https://www.bezkoder.com/deploy-spring-boot-aws-eb/)
94-
95-
> [Docker Compose Spring Boot and MySQL example](https://www.bezkoder.com/docker-compose-spring-boot-mysql/)
96-
97116
## Dependency
98117
– If you want to use PostgreSQL:
99118
```xml

pom.xml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
6-
<parent>
7-
<groupId>org.springframework.boot</groupId>
8-
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>2.6.1</version>
10-
<relativePath/> <!-- lookup parent from repository -->
11-
</parent>
12-
<groupId>com.bezkoder</groupId>
13-
<artifactId>spring-boot-security-jwt</artifactId>
14-
<version>0.0.1-SNAPSHOT</version>
15-
<name>spring-boot-security-jwt</name>
16-
<description>Demo project for Spring Boot Security - JWT</description>
3+
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<groupId>org.springframework.boot</groupId>
9+
<artifactId>spring-boot-starter-parent</artifactId>
10+
<version>2.7.3</version>
11+
<relativePath /> <!-- lookup parent from repository -->
12+
</parent>
13+
<groupId>com.bezkoder</groupId>
14+
<artifactId>spring-boot-security-jwt</artifactId>
15+
<version>0.0.1-SNAPSHOT</version>
16+
<name>spring-boot-security-jwt</name>
17+
<description>Demo project for Spring Boot Security - JWT</description>
1718

1819
<properties>
1920
<java.version>1.8</java.version>

src/main/java/com/bezkoder/springjwt/security/WebSecurityConfig.java

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,28 @@
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.context.annotation.Configuration;
99
import org.springframework.security.authentication.AuthenticationManager;
10-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
10+
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
11+
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
12+
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
1113
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
1214
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
13-
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
14-
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
15+
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
16+
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
1517
import org.springframework.security.config.http.SessionCreationPolicy;
1618
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1719
import org.springframework.security.crypto.password.PasswordEncoder;
20+
import org.springframework.security.web.SecurityFilterChain;
1821
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
1922

2023
@RequiredArgsConstructor
2124
@Configuration
22-
@EnableWebSecurity
2325
@EnableGlobalMethodSecurity(
24-
// securedEnabled = true,
25-
// jsr250Enabled = true,
26-
prePostEnabled = true)
27-
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
26+
// securedEnabled = true,
27+
// jsr250Enabled = true,
28+
prePostEnabled = true)
29+
public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
30+
@Autowired
31+
UserDetailsServiceImpl userDetailsService;
2832

2933
private final UserDetailsServiceImpl userDetailsService;
3034

@@ -35,31 +39,63 @@ public AuthTokenFilter authenticationJwtTokenFilter() {
3539
return new AuthTokenFilter();
3640
}
3741

38-
@Override
39-
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
40-
authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
41-
}
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+
}
4256

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

4968
@Bean
5069
public PasswordEncoder passwordEncoder() {
5170
return new BCryptPasswordEncoder();
5271
}
5372

54-
@Override
55-
protected void configure(HttpSecurity http) throws Exception {
56-
http.cors().and().csrf().disable()
57-
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
58-
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
59-
.authorizeRequests().antMatchers("/api/auth/**").permitAll()
60-
.antMatchers("/api/test/**").permitAll()
61-
.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());
95+
96+
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
97+
98+
return http.build();
99+
}
62100

63-
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
64-
}
65101
}

0 commit comments

Comments
 (0)