百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
J

jwt-spring-security-demo

> 后端框架
开源

使用JWT(Json Web Token)与Spring Security和Spring Boot 2的演示

3.1K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

使用JWT(Json Web Token)与Spring Security和Spring Boot 2的演示

JWT Spring Security 示例

关于

这是一个使用 JWT(JSON Web Token) 与 Spring Security 以及 Spring Boot 的示例项目。我完全重写了第一版。现在这个解决方案基于 JHipster 项目的代码库。我尝试提取了 JWT 认证所需的最小配置和类,并做了一些修改。

要求

此示例使用 Maven 3.6.x 和 Java 11 构建。

使用方法

只需使用 Spring Boot Maven 插件启动应用程序(mvn spring-boot:run)。应用程序运行在 http://localhost:8080。

您可以使用 H2-Console 在 http://localhost:8080/h2-console 下探索数据库:

后端

提供了三个用户账户,用于演示对 API 中端点的不同访问权限级别以及不同的授权异常:

Admin - admin:admin
User - user:password
Disabled - disabled:password (this user is deactivated)

有四个端点适合用于演示:

/api/authenticate - authentication endpoint with unrestricted access
/api/user - returns detail information for an authenticated user (a valid JWT token must be present in the request header)
/api/persons - an example endpoint that is restricted to authorized users with the authority 'ROLE_USER' (a valid JWT token must be present in the request header)
/api/hiddenmessage - an example endpoint that is restricted to authorized users with the authority 'ROLE_ADMIN' (a valid JWT token must be present in the request header)

前端

我编写了一个小型的 JavaScript 客户端,并在代码中添加了一些注释,希望能让这个演示易于理解。 您可以在 /src/main/resources/static/js/client.js 找到它。

为新用户生成密码哈希

我使用 bcrypt 来对密码进行加密。您可以使用这个简单的工具生成哈希值: Bcrypt Generator

Issues· 10 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaauthenticationdemojavajwt

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架