- Appropriate Flow for User Login and Registration with JWT and HttpOnly Cookie
- Spring Boot Rest Api Architecture with Spring Security
- How to configure Spring Security to work with JWT
- How to define Data Models and association for Authentication and Authorization
- Way to use Spring Data JPA to interact with H2 Database
You can have an overview of our Spring Boot Server with the diagram below:
For more detail, please visit:
– If you want to use PostgreSQL:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>– or MySQL:
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>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
# App Properties
bezkoder.app.jwtSecret= ======================BezKoder=Spring===========================
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.MySQLDialect
spring.jpa.hibernate.ddl-auto=update
# App Properties
bezkoder.app.jwtSecret= ======================BezKoder=Spring===========================
bezkoder.app.jwtExpirationMs= 86400000
mvn spring-boot:run
Let’s check H2 database with url: http://localhost:8084/h2-ui: And JDBC url:
jdbc:h2:file:./testdb
un: sa
Details :
https://www.bezkoder.com/spring-boot-security-login-jwt/
INSERT INTO roles(name) VALUES('ROLE_USER');
INSERT INTO roles(name) VALUES('ROLE_MODERATOR');
INSERT INTO roles(name) VALUES('ROLE_ADMIN');
##Sample user service consume:
usercreate: url :
http://localhost:8084/api/auth/signup
body:
{
"username": "arif",
"email": "arif@arif.com",
"password": "arif123",
"role": [
"mod",
"user",
"admin"
]
}
login user url :
http://localhost:8084/api/auth/signin
body:
{
"username": "arif",
"password": "arif123"
}
http://localhost:8084/swagger-ui/index.html
Spring Boot JWT Refresh Token example
Exception handling: @RestControllerAdvice example in Spring Boot
Validation: Spring Boot Validate Request Body
Documentation: Spring Boot and Swagger 3 example
Caching: Spring Boot Redis Cache example
Associations:
Deployment:
Run both Back-end & Front-end in one place:

