Go to file
YuCheng Hu c15c58ee02 JwtUtils 修改为静态方法 2022-10-03 00:19:45 -04:00
.idea 删除不需要的文件,并且重新格式化项目 2022-10-03 00:07:01 -04:00
src JwtUtils 修改为静态方法 2022-10-03 00:19:45 -04:00
.gitignore 删除不需要的文件,并且重新格式化项目 2022-10-03 00:06:54 -04:00
LICENSE 更新许可证信息 2022-10-02 08:12:39 -04:00
README.md 更新自述文件 2022-10-03 00:09:50 -04:00
pom.xml 根据内容:https://www.ossez.com/t/spring-lombok/14129 修改实体类死循环问题 2022-10-02 17:26:46 -04:00
spring-boot-jwt-authentication-spring-security-architecture.png add references 2020-11-29 16:49:45 +07:00
spring-boot-jwt-authentication-spring-security-flow.png add references 2020-11-29 16:49:45 +07:00
spring-boot-refresh-token-jwt-example-flow.png add references 2021-04-21 07:32:13 +07:00

README.md

Spring Boot JWT 认证示例项目

本示例项目中使用了 Spring Security 和 Spring Data JPA 框架。


提供 CWIKI.US 项目中使用的代码

所有的 Java 代码使用的是 JDK 11。

你可以通过单击下面连接后访问我们网站,并且访问我们提供的最新有关 Java 的开发资料。

联系方式

请使用下面的联系方式和我们联系:

联系方式名称 联系方式
电子邮件 service@ossez.com
QQ 或微信 103899765
QQ 交流群 15186112
社区论坛 https://www.ossez.com/c/open-source/java/15

公众平台

我们建议您通过社区论坛来和我们进行沟通,请关注我们公众平台上的账号

微信公众号

头条号

我们也在头条号上创建了我们的公众号,请扫描下面的 QR 关注我们的头条号。

知乎

请关注我们的知乎:https://www.zhihu.com/people/huyuchengus

快速导航

在下面的表格中,我们列出了一些比较有用的 CWIKIUS 相关软件开发使用教程的导航,欢迎访问下面的链接获得更多的内容和参与讨论

网站名称 URL NOTE
OSSEZ 社区 www.ossez.com 开放社区,欢迎注册参与讨论
WIKI 维基 www.cwiki.us 使用 Confluence 部署的 WIKI 知识库
DOCS.OSSEZ.COM https://docs.ossez.com/#/ 本手册的编译版本将会部署在这个链接上
CN 博客 http://www.cwikius.cn/ CWIKIUS.CN 一个有独立思考和温度的清新站

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 Server Architecture with Spring Security

You can have an overview of our Spring Boot Server with the diagram below:

spring-boot-jwt-authentication-spring-security-architecture

For more detail, please visit:

Secure Spring Boot App with Spring Security & JWT Authentication

For MongoDB

Refresh Token

spring-boot-refresh-token-jwt-example-flow

For instruction: Spring Boot Refresh Token with JWT example

More Practice:

Spring Boot File upload example with Multipart File

Exception handling: @RestControllerAdvice example in Spring Boot

Spring Boot Repository Unit Test with @DataJpaTest

Spring Boot Pagination & Sorting example

Associations:

Spring Boot One To Many example with Spring JPA, Hibernate

Spring Boot Many To Many example with Spring JPA, Hibernate

JPA One To One example with Spring Boot

Deployment:

Deploy Spring Boot App on AWS Elastic Beanstalk

Docker Compose Spring Boot and MySQL example

Fullstack Authentication

Spring Boot + Vue.js JWT Authentication

Spring Boot + Angular 8 JWT Authentication

Spring Boot + Angular 10 JWT Authentication

Spring Boot + Angular 11 JWT Authentication

Spring Boot + Angular 12 JWT Authentication

Spring Boot + Angular 13 JWT Authentication

Spring Boot + Angular 14 JWT Authentication

Spring Boot + React JWT Authentication

Fullstack CRUD App

Vue.js + Spring Boot + H2 Embedded database example

Vue.js + Spring Boot + MySQL example

Vue.js + Spring Boot + PostgreSQL example

Angular 8 + Spring Boot + Embedded database example

Angular 8 + Spring Boot + MySQL example

Angular 8 + Spring Boot + PostgreSQL example

Angular 10 + Spring Boot + MySQL example

Angular 10 + Spring Boot + PostgreSQL example

Angular 11 + Spring Boot + MySQL example

Angular 11 + Spring Boot + PostgreSQL example

Angular 12 + Spring Boot + Embedded database example

Angular 12 + Spring Boot + MySQL example

Angular 12 + Spring Boot + PostgreSQL example

Angular 13 + Spring Boot + H2 Embedded Database example

Angular 13 + Spring Boot + MySQL example

Angular 13 + Spring Boot + PostgreSQL example

Angular 14 + Spring Boot + H2 Embedded Database example

Angular 14 + Spring Boot + MySQL example

Angular 14 + Spring Boot + PostgreSQL example

React + Spring Boot + MySQL example

React + Spring Boot + PostgreSQL example

React + Spring Boot + MongoDB example

Run both Back-end & Front-end in one place:

Integrate Angular with Spring Boot Rest API

Integrate React.js with Spring Boot Rest API

Integrate Vue.js with Spring Boot Rest API

Dependency

If you want to use PostgreSQL:

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <scope>runtime</scope>
</dependency>

or MySQL:

<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

# 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

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');