2020-02-18 06:56:01 +07:00
|
|
|
|
# Spring Boot JWT Authentication example with Spring Security & Spring Data JPA
|
2019-10-15 23:08:57 +07:00
|
|
|
|
|
2020-11-29 15:12:56 +07:00
|
|
|
|
## User Registration, User Login and Authorization process.
|
|
|
|
|
|
The diagram shows flow of how we implement User Registration, User Login and Authorization process.
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
## Spring Boot Server Architecture with Spring Security
|
|
|
|
|
|
You can have an overview of our Spring Boot Server with the diagram below:
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
2019-10-15 23:08:57 +07:00
|
|
|
|
For more detail, please visit:
|
|
|
|
|
|
> [Secure Spring Boot App with Spring Security & JWT Authentication](https://bezkoder.com/spring-boot-jwt-authentication/)
|
|
|
|
|
|
|
2020-02-24 08:58:05 +07:00
|
|
|
|
> [For MongoDB](https://bezkoder.com/spring-boot-jwt-auth-mongodb/)
|
|
|
|
|
|
|
2020-11-29 15:12:56 +07:00
|
|
|
|
## Fullstack Authentication
|
2020-01-18 10:05:24 +07:00
|
|
|
|
|
|
|
|
|
|
> [Spring Boot + Vue.js JWT Authentication](https://bezkoder.com/spring-boot-vue-js-authentication-jwt-spring-security/)
|
|
|
|
|
|
|
|
|
|
|
|
> [Spring Boot + Angular 8 JWT Authentication](https://bezkoder.com/angular-spring-boot-jwt-auth/)
|
|
|
|
|
|
|
2020-11-16 10:29:56 +07:00
|
|
|
|
> [Spring Boot + Angular 10 JWT Authentication](https://bezkoder.com/angular-10-spring-boot-jwt-auth/)
|
|
|
|
|
|
|
2020-04-01 17:03:27 +07:00
|
|
|
|
> [Spring Boot + React JWT Authentication](https://bezkoder.com/spring-boot-react-jwt-auth/)
|
|
|
|
|
|
|
2020-11-29 15:12:56 +07:00
|
|
|
|
## Fullstack CRUD App
|
|
|
|
|
|
|
|
|
|
|
|
> [Vue.js + Spring Boot + MySQL/PostgreSQL example](https://bezkoder.com/spring-boot-vue-js-crud-example/)
|
|
|
|
|
|
|
|
|
|
|
|
> [Angular + Spring Boot + MySQL example](https://bezkoder.com/angular-10-spring-boot-crud/)
|
|
|
|
|
|
|
|
|
|
|
|
> [Angular + Spring Boot + PostgreSQL example](https://bezkoder.com/angular-10-spring-boot-postgresql/)
|
|
|
|
|
|
|
|
|
|
|
|
> [React + Spring Boot + MySQL example](https://bezkoder.com/react-spring-boot-crud/)
|
|
|
|
|
|
|
|
|
|
|
|
> [React + Spring Boot + PostgreSQL example](https://bezkoder.com/spring-boot-react-postgresql/)
|
|
|
|
|
|
|
2020-11-16 10:29:56 +07:00
|
|
|
|
Run both Back-end & Front-end in one place:
|
|
|
|
|
|
> [Integrate Angular with Spring Boot Rest API](https://bezkoder.com/integrate-angular-spring-boot/)
|
|
|
|
|
|
|
|
|
|
|
|
> [Integrate React.js with Spring Boot Rest API](https://bezkoder.com/integrate-reactjs-spring-boot/)
|
|
|
|
|
|
|
2020-02-18 06:56:01 +07:00
|
|
|
|
## Dependency
|
|
|
|
|
|
– If you want to use PostgreSQL:
|
|
|
|
|
|
```xml
|
|
|
|
|
|
<dependency>
|
|
|
|
|
|
<groupId>org.postgresql</groupId>
|
|
|
|
|
|
<artifactId>postgresql</artifactId>
|
|
|
|
|
|
<scope>runtime</scope>
|
|
|
|
|
|
</dependency>
|
|
|
|
|
|
```
|
|
|
|
|
|
– or MySQL:
|
|
|
|
|
|
```xml
|
|
|
|
|
|
<dependency>
|
|
|
|
|
|
<groupId>mysql</groupId>
|
|
|
|
|
|
<artifactId>mysql-connector-java</artifactId>
|
|
|
|
|
|
<scope>runtime</scope>
|
|
|
|
|
|
</dependency>
|
|
|
|
|
|
```
|
|
|
|
|
|
## Configure Spring Datasource, JPA, App properties
|
|
|
|
|
|
Open `src/main/resources/application.properties`
|
|
|
|
|
|
- For PostgreSQL:
|
|
|
|
|
|
```
|
|
|
|
|
|
spring.datasource.url= jdbc:postgresql://localhost:5432/testdb
|
|
|
|
|
|
spring.datasource.username= postgres
|
|
|
|
|
|
spring.datasource.password= 123
|
|
|
|
|
|
|
|
|
|
|
|
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation= true
|
|
|
|
|
|
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect
|
|
|
|
|
|
|
|
|
|
|
|
# Hibernate ddl auto (create, create-drop, validate, update)
|
|
|
|
|
|
spring.jpa.hibernate.ddl-auto= update
|
2020-01-18 10:05:24 +07:00
|
|
|
|
|
2020-02-18 06:56:01 +07:00
|
|
|
|
# App Properties
|
|
|
|
|
|
bezkoder.app.jwtSecret= bezKoderSecretKey
|
|
|
|
|
|
bezkoder.app.jwtExpirationMs= 86400000
|
|
|
|
|
|
```
|
|
|
|
|
|
- For MySQL
|
|
|
|
|
|
```
|
|
|
|
|
|
spring.datasource.url= jdbc:mysql://localhost:3306/testdb?useSSL=false
|
|
|
|
|
|
spring.datasource.username= root
|
|
|
|
|
|
spring.datasource.password= 123456
|
|
|
|
|
|
|
|
|
|
|
|
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
|
|
|
|
|
|
spring.jpa.hibernate.ddl-auto= update
|
|
|
|
|
|
|
|
|
|
|
|
# App Properties
|
|
|
|
|
|
bezkoder.app.jwtSecret= bezKoderSecretKey
|
|
|
|
|
|
bezkoder.app.jwtExpirationMs= 86400000
|
|
|
|
|
|
```
|
2019-10-15 23:08:57 +07:00
|
|
|
|
## Run Spring Boot application
|
|
|
|
|
|
```
|
|
|
|
|
|
mvn spring-boot:run
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Run following SQL insert statements
|
|
|
|
|
|
```
|
|
|
|
|
|
INSERT INTO roles(name) VALUES('ROLE_USER');
|
|
|
|
|
|
INSERT INTO roles(name) VALUES('ROLE_MODERATOR');
|
|
|
|
|
|
INSERT INTO roles(name) VALUES('ROLE_ADMIN');
|
2020-01-18 10:05:24 +07:00
|
|
|
|
```
|