Spring Boot, Spring Security, PostgreSQL: JWT Authentication & Authorization & Cucumber testing example
https://www.bezkoder.com/spring-boot-jwt-authentication/
The diagram shows flow of how we implement User Registration, User Login and Authorization process.
You can have an overview of our Spring Boot Server with the diagram below:
For more detail, please visit:
Spring Boot, Spring Security, PostgreSQL: JWT Authentication & Authorization example
For instruction: Spring Boot Refresh Token with JWT example
Run both Back-end & Front-end in one place:
More Practice:
Exception handling: @RestControllerAdvice example in Spring Boot
Secure Spring Boot App with Spring Security & JWT Authentication
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
Open src/main/resources/application.properties
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
# App Properties
bezkoder.app.jwtSecret= bezKoderSecretKey
bezkoder.app.jwtExpirationMs= 86400000
mvn spring-boot:run
INSERT INTO roles(name) VALUES('ROLE_STUDENT');
INSERT INTO roles(name) VALUES('ROLE_TEACHER');
INSERT INTO roles(name) VALUES('ROLE_ADMIN');