Skip to content

Commit d710e94

Browse files
tienbkuramazansakin
authored and
ramazansakin
committed
get current changes & resolve conflicts
1 parent 519f3fa commit d710e94

File tree

3 files changed

+172
-132
lines changed

3 files changed

+172
-132
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: 64 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,77 @@
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+
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.7.3</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>
1717

18-
<properties>
19-
<java.version>1.8</java.version>
20-
</properties>
18+
<properties>
19+
<java.version>1.8</java.version>
20+
</properties>
2121

22-
<dependencies>
23-
<dependency>
24-
<groupId>org.springframework.boot</groupId>
25-
<artifactId>spring-boot-starter-data-jpa</artifactId>
26-
</dependency>
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-data-jpa</artifactId>
26+
</dependency>
2727

28-
<dependency>
29-
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-security</artifactId>
31-
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-security</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-validation</artifactId>
36+
</dependency>
3237

33-
<dependency>
34-
<groupId>org.springframework.boot</groupId>
35-
<artifactId>spring-boot-starter-validation</artifactId>
36-
</dependency>
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
</dependency>
3742

38-
<dependency>
39-
<groupId>org.springframework.boot</groupId>
40-
<artifactId>spring-boot-starter-web</artifactId>
41-
</dependency>
43+
<dependency>
44+
<groupId>mysql</groupId>
45+
<artifactId>mysql-connector-java</artifactId>
46+
<scope>runtime</scope>
47+
</dependency>
4248

43-
<dependency>
44-
<groupId>mysql</groupId>
45-
<artifactId>mysql-connector-java</artifactId>
46-
<scope>runtime</scope>
47-
</dependency>
49+
<dependency>
50+
<groupId>io.jsonwebtoken</groupId>
51+
<artifactId>jjwt</artifactId>
52+
<version>0.9.1</version>
53+
</dependency>
4854

49-
<dependency>
50-
<groupId>io.jsonwebtoken</groupId>
51-
<artifactId>jjwt</artifactId>
52-
<version>0.9.1</version>
53-
</dependency>
54-
<dependency>
55-
<groupId>org.projectlombok</groupId>
56-
<artifactId>lombok</artifactId>
57-
<version>1.18.24</version>
58-
</dependency>
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-starter-test</artifactId>
58+
<scope>test</scope>
59+
</dependency>
5960

60-
<dependency>
61-
<groupId>org.springframework.boot</groupId>
62-
<artifactId>spring-boot-starter-test</artifactId>
63-
<scope>test</scope>
64-
</dependency>
61+
<dependency>
62+
<groupId>org.springframework.security</groupId>
63+
<artifactId>spring-security-test</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
</dependencies>
6567

66-
<dependency>
67-
<groupId>org.springframework.security</groupId>
68-
<artifactId>spring-security-test</artifactId>
69-
<scope>test</scope>
70-
</dependency>
71-
</dependencies>
72-
73-
<build>
74-
<plugins>
75-
<plugin>
76-
<groupId>org.springframework.boot</groupId>
77-
<artifactId>spring-boot-maven-plugin</artifactId>
78-
<configuration>
79-
<excludes>
80-
<exclude>
81-
<groupId>org.projectlombok</groupId>
82-
<artifactId>lombok</artifactId>
83-
</exclude>
84-
</excludes>
85-
</configuration>
86-
</plugin>
87-
</plugins>
88-
</build>
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>org.springframework.boot</groupId>
72+
<artifactId>spring-boot-maven-plugin</artifactId>
73+
</plugin>
74+
</plugins>
75+
</build>
8976

9077
</project>
Lines changed: 77 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,99 @@
11
package com.bezkoder.springjwt.security;
22

3-
import com.bezkoder.springjwt.security.jwt.AuthEntryPointJwt;
4-
import com.bezkoder.springjwt.security.jwt.AuthTokenFilter;
5-
import com.bezkoder.springjwt.security.services.UserDetailsServiceImpl;
6-
import lombok.RequiredArgsConstructor;
3+
import org.springframework.beans.factory.annotation.Autowired;
74
import org.springframework.context.annotation.Bean;
85
import org.springframework.context.annotation.Configuration;
96
import org.springframework.security.authentication.AuthenticationManager;
10-
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;
1110
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
1211
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;
12+
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
13+
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
1514
import org.springframework.security.config.http.SessionCreationPolicy;
1615
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1716
import org.springframework.security.crypto.password.PasswordEncoder;
17+
import org.springframework.security.web.SecurityFilterChain;
1818
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
1919

20-
@RequiredArgsConstructor
20+
import com.bezkoder.springjwt.security.jwt.AuthEntryPointJwt;
21+
import com.bezkoder.springjwt.security.jwt.AuthTokenFilter;
22+
import com.bezkoder.springjwt.security.services.UserDetailsServiceImpl;
23+
2124
@Configuration
22-
@EnableWebSecurity
2325
@EnableGlobalMethodSecurity(
24-
// securedEnabled = true,
25-
// jsr250Enabled = true,
26-
prePostEnabled = true)
27-
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
28-
29-
private final UserDetailsServiceImpl userDetailsService;
26+
// securedEnabled = true,
27+
// jsr250Enabled = true,
28+
prePostEnabled = true)
29+
public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
30+
@Autowired
31+
UserDetailsServiceImpl userDetailsService;
3032

31-
private final AuthEntryPointJwt unauthorizedHandler;
33+
@Autowired
34+
private AuthEntryPointJwt unauthorizedHandler;
3235

33-
@Bean
34-
public AuthTokenFilter authenticationJwtTokenFilter() {
35-
return new AuthTokenFilter();
36-
}
36+
@Bean
37+
public AuthTokenFilter authenticationJwtTokenFilter() {
38+
return new AuthTokenFilter();
39+
}
3740

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

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

49-
@Bean
50-
public PasswordEncoder passwordEncoder() {
51-
return new BCryptPasswordEncoder();
52-
}
67+
@Bean
68+
public PasswordEncoder passwordEncoder() {
69+
return new BCryptPasswordEncoder();
70+
}
5371

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();
72+
// @Override
73+
// protected void configure(HttpSecurity http) throws Exception {
74+
// http.cors().and().csrf().disable()
75+
// .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
76+
// .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
77+
// .authorizeRequests().antMatchers("/api/auth/**").permitAll()
78+
// .antMatchers("/api/test/**").permitAll()
79+
// .anyRequest().authenticated();
80+
//
81+
// http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
82+
// }
83+
84+
@Bean
85+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
86+
http.cors().and().csrf().disable()
87+
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
88+
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
89+
.authorizeRequests().antMatchers("/api/auth/**").permitAll()
90+
.antMatchers("/api/test/**").permitAll()
91+
.anyRequest().authenticated();
92+
93+
http.authenticationProvider(authenticationProvider());
6294

63-
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
64-
}
95+
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
96+
97+
return http.build();
98+
}
6599
}

0 commit comments

Comments
 (0)