An open API service indexing awesome lists of open source software.

https://github.com/charlybutar21/spring-boot-security-jwt-authentication

Spring Boot application to implement rest API with JWT authentication
https://github.com/charlybutar21/spring-boot-security-jwt-authentication

api-integration junit jwt-authentication mysql rest-api solid-principles spring-boot spring-data-jpa spring-mvc spring-security-jwt spring-validation

Last synced: about 2 months ago
JSON representation

Spring Boot application to implement rest API with JWT authentication

Awesome Lists containing this project

README

          

# Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

## User Registration, User Login and Authorization process.
The diagram shows flow of how we implement User Registration, User Login and Authorization process.

![spring-boot-jwt-authentication-spring-security-flow](spring-boot-jwt-authentication-spring-security-flow.png)

## Configure Spring Datasource, JPA, App properties
Open `src/main/resources/application.properties`
- MySQL
```
spring.datasource.url=jdbc:mysql://localhost:3306/demo_db?useSSL=false
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=update

# App Properties
bezkoder.app.jwtSecret= ======================BezKoder=Spring===========================
bezkoder.app.jwtExpirationMs=86400000
```
## Run Spring Boot application
```
mvn spring-boot:run
```

## Run following SQL insert statements
Open `database.sql`
```
INSERT INTO roles(name) VALUES('ROLE_USER');
INSERT INTO roles(name) VALUES('ROLE_MODERATOR');
INSERT INTO roles(name) VALUES('ROLE_ADMIN');
```