优化代码语法,token采用jwt加强
This commit is contained in:
@@ -234,19 +234,19 @@ flowchart TB
|
|||||||
|
|
||||||
### 2.3 模块职责
|
### 2.3 模块职责
|
||||||
|
|
||||||
| 层级 | 模块 | 职责说明 |
|
| 层级 | 模块 | 职责说明 |
|
||||||
|------------------|-----------------------------------------|-------------------------------------------------|
|
|-------------------|-------------------------------------------|-------------------------------------------------------------------------|
|
||||||
| **Controller层** | SysUserController、SysLoginController等 | 接收HTTP请求、参数验证(@Valid)、调用Service层、返回统一响应(Result) |
|
| **Controller层** | SysUserController、SysLoginController等 | 接收HTTP请求、参数验证(@Valid)、调用Service层、返回统一响应(Result) |
|
||||||
| **Service层** | SysUserServiceImpl、SysLoginServiceImpl等 | 实现业务逻辑、事务控制(@Transactional)、调用Mapper层、缓存操作 |
|
| **Service层** | SysUserServiceImpl、SysLoginServiceImpl等 | 实现业务逻辑、事务控制(@Transactional)、调用Mapper层、缓存操作 |
|
||||||
| **BaseService层** | SysUserBaseService等 | 继承MyBatis-Plus ServiceImpl,提供基础CRUD操作 |
|
| **BaseService层** | SysUserBaseService等 | 继承MyBatis-Plus ServiceImpl,提供基础CRUD操作 |
|
||||||
| **Mapper层** | SysUserMapper、SysRoleMapper等 | 继承MyBatis-Plus BaseMapper,数据库访问、SQL执行 |
|
| **Mapper层** | SysUserMapper、SysRoleMapper等 | 继承MyBatis-Plus BaseMapper,数据库访问、SQL执行 |
|
||||||
| **Entity层** | SysUser、SysRole、SysMenu等 | 数据库实体映射 |
|
| **Entity层** | SysUser、SysRole、SysMenu等 | 数据库实体映射 |
|
||||||
| **DTO层** | Req(请求)、Resp(响应)、Excel | 数据传输对象 |
|
| **DTO层** | Req(请求)、Resp(响应)、Excel | 数据传输对象 |
|
||||||
| **Convert层** | SysUserConvert、SysRoleConvert等 | MapStruct对象转换 |
|
| **Convert层** | SysUserConvert、SysRoleConvert等 | MapStruct对象转换 |
|
||||||
| **Config层** | SysConfig、ApiConfig等 | 配置类 |
|
| **Config层** | SysConfig、ApiConfig等 | 配置类 |
|
||||||
| **MQ层** | SysLogMq、SysTaskMq等 | 消息队列消费者 |
|
| **MQ层** | SysLogMq、SysTaskMq等 | 消息队列消费者 |
|
||||||
| **Job层** | BaseJob、SysLogJob等 | 定时任务、异步任务 |
|
| **Job层** | BaseJob、SysLogJob等 | 定时任务、异步任务 |
|
||||||
| **Utils层** | PasswdUtils、AuthUtils等 | 工具类 |
|
| **Utils层** | PasswdUtils、AuthUtils等 | 工具类 |
|
||||||
|
|
||||||
### 2.4 包结构设计
|
### 2.4 包结构设计
|
||||||
|
|
||||||
@@ -276,12 +276,12 @@ xtools.app.{module}
|
|||||||
|
|
||||||
项目支持两种部署模式:
|
项目支持两种部署模式:
|
||||||
|
|
||||||
| 模块 | 说明 |
|
| 模块 | 说明 |
|
||||||
|-----------------------------|-----------------------------------------------------|
|
|-----------------------------|---------------------------------------------------------------------------|
|
||||||
| **xtools-app-standalone** | 单体部署模式,包含所有模块,通过 spring-boot-maven-plugin 打包为可执行JAR |
|
| **xtools-app-standalone** | 单体部署模式,包含所有模块,通过 spring-boot-maven-plugin 打包为可执行JAR |
|
||||||
| **xtools-app-sys-boot** | 微服务模式 - 系统管理服务 |
|
| **xtools-app-sys-boot** | 微服务模式 - 系统管理服务 |
|
||||||
| **xtools-app-gen-boot** | 微服务模式 - 代码生成服务 |
|
| **xtools-app-gen-boot** | 微服务模式 - 代码生成服务 |
|
||||||
| **xtools-app-monitor-boot** | 微服务模式 - 监控服务 |
|
| **xtools-app-monitor-boot** | 微服务模式 - 监控服务 |
|
||||||
|
|
||||||
## 三、项目功能设计
|
## 三、项目功能设计
|
||||||
|
|
||||||
@@ -380,12 +380,12 @@ flowchart LR
|
|||||||
|
|
||||||
#### 日志类型
|
#### 日志类型
|
||||||
|
|
||||||
| 类型 | 说明 | 处理方式 |
|
| 类型 | 说明 | 处理方式 |
|
||||||
|------|----------|---------------------------------|
|
|----------|------------------|-----------------------------------|
|
||||||
| 操作日志 | 用户操作行为记录 | LogFilter采集 -> MQ -> ES |
|
| 操作日志 | 用户操作行为记录 | LogFilter采集 -> MQ -> ES |
|
||||||
| 系统日志 | 系统运行日志 | LogBus记录 -> MQ -> ES |
|
| 系统日志 | 系统运行日志 | LogBus记录 -> MQ -> ES |
|
||||||
| 任务日志 | 定时任务执行日志 | BaseJob记录 -> LogBus -> MQ -> ES |
|
| 任务日志 | 定时任务执行日志 | BaseJob记录 -> LogBus -> MQ -> ES |
|
||||||
| 错误日志 | 异常和错误信息 | 异常捕获 -> LogBus -> MQ -> ES |
|
| 错误日志 | 异常和错误信息 | 异常捕获 -> LogBus -> MQ -> ES |
|
||||||
|
|
||||||
#### 日志配置
|
#### 日志配置
|
||||||
|
|
||||||
@@ -428,15 +428,15 @@ flowchart TD
|
|||||||
|
|
||||||
#### 代码生成特性
|
#### 代码生成特性
|
||||||
|
|
||||||
| 特性 | 说明 |
|
| 特性 | 说明 |
|
||||||
|--------|---------------------------|
|
|--------------|------------------------------------------|
|
||||||
| 多数据源 | 支持 MySQL 等多种数据库类型 |
|
| 多数据源 | 支持 MySQL 等多种数据库类型 |
|
||||||
| 表结构同步 | 自动读取表和字段元数据 |
|
| 表结构同步 | 自动读取表和字段元数据 |
|
||||||
| 智能类型映射 | 自动将数据库类型映射为 Java 类型 |
|
| 智能类型映射 | 自动将数据库类型映射为 Java 类型 |
|
||||||
| 表单类型推断 | 根据字段类型自动推断表单组件 |
|
| 表单类型推断 | 根据字段类型自动推断表单组件 |
|
||||||
| 查询方式推断 | String类型默认LIKE,时间类型默认范围查询 |
|
| 查询方式推断 | String类型默认LIKE,时间类型默认范围查询 |
|
||||||
| 模板配置 | 可配置后端和前端项目名称、模块路径等 |
|
| 模板配置 | 可配置后端和前端项目名称、模块路径等 |
|
||||||
| ZIP下载 | 生成的代码打包为ZIP文件下载 |
|
| ZIP下载 | 生成的代码打包为ZIP文件下载 |
|
||||||
|
|
||||||
### 3.4 任务调度设计
|
### 3.4 任务调度设计
|
||||||
|
|
||||||
@@ -459,11 +459,11 @@ flowchart TD
|
|||||||
|
|
||||||
#### 任务类型
|
#### 任务类型
|
||||||
|
|
||||||
| 类型 | 实现方式 | 说明 |
|
| 类型 | 实现方式 | 说明 |
|
||||||
|----------|-------------------------------|--------------------|
|
|------------|-------------------------------|----------------------------|
|
||||||
| 异步任务 | `BaseJob implements Runnable` | 支持分布式锁,防止重复执行 |
|
| 异步任务 | `BaseJob implements Runnable` | 支持分布式锁,防止重复执行 |
|
||||||
| XXL-JOB | `xtools-boot-job-xxl`(可选) | 分布式任务调度平台 |
|
| XXL-JOB | `xtools-boot-job-xxl`(可选) | 分布式任务调度平台 |
|
||||||
| 定时任务 | `SysScheduled` | Spring Task 定时任务管理 |
|
| 定时任务 | `SysScheduled` | Spring Task 定时任务管理 |
|
||||||
| Spring任务 | `JobInterface.execute()` | Spring 原生任务执行接口 |
|
| Spring任务 | `JobInterface.execute()` | Spring 原生任务执行接口 |
|
||||||
|
|
||||||
#### 任务调度特性
|
#### 任务调度特性
|
||||||
@@ -477,20 +477,20 @@ flowchart TD
|
|||||||
|
|
||||||
#### 缓存策略
|
#### 缓存策略
|
||||||
|
|
||||||
| 缓存Key | 说明 | 过期时间 |
|
| 缓存Key | 说明 | 过期时间 |
|
||||||
|------------------------------------|----------|------|
|
|------------------------------------|----------------|----------|
|
||||||
| `xtools-app:uid:{uid}:sm2` | SM2公钥缓存 | 5分钟 |
|
| `xtools-app:uid:{uid}:sm2` | SM2公钥缓存 | 5分钟 |
|
||||||
| `xtools-app:uid:{uid}:captcha` | 验证码缓存 | 60秒 |
|
| `xtools-app:uid:{uid}:captcha` | 验证码缓存 | 60秒 |
|
||||||
| `xtools-app:auth:sys:user:{token}` | 用户认证信息 | 1小时 |
|
| `xtools-app:auth:sys:user:{token}` | 用户认证信息 | 1小时 |
|
||||||
| `xtools-app:auth:sys:uri` | 权限URI缓存 | 永不过期 |
|
| `xtools-app:auth:sys:uri` | 权限URI缓存 | 永不过期 |
|
||||||
| `xtools-app:auth:cloud:token` | 微服务Token | 60秒 |
|
| `xtools-app:auth:cloud:token` | 微服务Token | 60秒 |
|
||||||
| `xtools-app:mq:msg:err:{id}` | MQ消息错误次数 | 60秒 |
|
| `xtools-app:mq:msg:err:{id}` | MQ消息错误次数 | 60秒 |
|
||||||
| `xtools-app:lock:job:{className}` | 任务分布式锁 | 5分钟 |
|
| `xtools-app:lock:job:{className}` | 任务分布式锁 | 5分钟 |
|
||||||
| `xtools-app:risk:ip:{ip}` | 风控IP | 永不过期 |
|
| `xtools-app:risk:ip:{ip}` | 风控IP | 永不过期 |
|
||||||
| `xtools-app:risk:uri:{uri}` | 风控URI | 永不过期 |
|
| `xtools-app:risk:uri:{uri}` | 风控URI | 永不过期 |
|
||||||
| `xtools-app:sys:cache:param:{key}` | 系统参数缓存 | 永不过期 |
|
| `xtools-app:sys:cache:param:{key}` | 系统参数缓存 | 永不过期 |
|
||||||
| `xtools-app:sys:cache:jar:{name}` | JAR包缓存 | 永不过期 |
|
| `xtools-app:sys:cache:jar:{name}` | JAR包缓存 | 永不过期 |
|
||||||
| `xtools-app:sys:cache:addr:{key}` | 地址缓存 | 1小时 |
|
| `xtools-app:sys:cache:addr:{key}` | 地址缓存 | 1小时 |
|
||||||
|
|
||||||
#### 缓存架构
|
#### 缓存架构
|
||||||
|
|
||||||
@@ -518,9 +518,9 @@ graph TD
|
|||||||
|
|
||||||
项目支持多种文件存储方式(通过 `xtools-app-standalone` 可选配置):
|
项目支持多种文件存储方式(通过 `xtools-app-standalone` 可选配置):
|
||||||
|
|
||||||
| 存储方式 | 模块 | 说明 |
|
| 存储方式 | 模块 | 说明 |
|
||||||
|------|----------------------------|--------------|
|
|----------|----------------------------|--------------------------|
|
||||||
| S3存储 | `xtools-boot-storage-s3` | 兼容S3协议的对象存储 |
|
| S3存储 | `xtools-boot-storage-s3` | 兼容S3协议的对象存储 |
|
||||||
| 本地文件 | `xtools-boot-storage-file` | 本地文件系统存储(可选) |
|
| 本地文件 | `xtools-boot-storage-file` | 本地文件系统存储(可选) |
|
||||||
|
|
||||||
## 四、编码规范设计
|
## 四、编码规范设计
|
||||||
@@ -529,31 +529,31 @@ graph TD
|
|||||||
|
|
||||||
#### 类命名
|
#### 类命名
|
||||||
|
|
||||||
| 类型 | 命名规范 | 示例 |
|
| 类型 | 命名规范 | 示例 |
|
||||||
|--------------|-------------------------------|----------------------------------|
|
|--------------|-----------------------------------|-----------------------------------|
|
||||||
| 实体类 | `Sys` + 模块名 | `SysUser`、`SysRole`、`SysMenu` |
|
| 实体类 | `Sys` + 模块名 | `SysUser`、`SysRole`、`SysMenu` |
|
||||||
| 请求DTO | 模块名 + `Req` | `SysUserAddReq`、`SysUserPageReq` |
|
| 请求DTO | 模块名 + `Req` | `SysUserAddReq`、`SysUserPageReq` |
|
||||||
| 响应DTO | 模块名 + `Resp` | `GenTableInfoResp` |
|
| 响应DTO | 模块名 + `Resp` | `GenTableInfoResp` |
|
||||||
| Excel DTO | 模块名 + `Excel` | `SysDictExcel` |
|
| Excel DTO | 模块名 + `Excel` | `SysDictExcel` |
|
||||||
| Service接口 | 模块名 + `Service` | `SysUserService` |
|
| Service接口 | 模块名 + `Service` | `SysUserService` |
|
||||||
| Service实现 | 模块名 + `ServiceImpl` | `SysUserServiceImpl` |
|
| Service实现 | 模块名 + `ServiceImpl` | `SysUserServiceImpl` |
|
||||||
| Base Service | 模块名 + `BaseService` | `SysUserBaseService` |
|
| Base Service | 模块名 + `BaseService` | `SysUserBaseService` |
|
||||||
| Controller | 模块名 + `Controller` | `SysUserController` |
|
| Controller | 模块名 + `Controller` | `SysUserController` |
|
||||||
| Mapper | 模块名 + `Mapper` | `SysUserMapper` |
|
| Mapper | 模块名 + `Mapper` | `SysUserMapper` |
|
||||||
| 转换器 | 模块名 + `Convert` | `SysUserConvert` |
|
| 转换器 | 模块名 + `Convert` | `SysUserConvert` |
|
||||||
| 工具类 | 功能名 + `Utils` | `PasswdUtils`、`AuthUtils` |
|
| 工具类 | 功能名 + `Utils` | `PasswdUtils`、`AuthUtils` |
|
||||||
| 配置类 | 功能名 + `Config` 或 `Properties` | `SysConfig`、`GenProperties` |
|
| 配置类 | 功能名 + `Config` 或 `Properties` | `SysConfig`、`GenProperties` |
|
||||||
|
|
||||||
#### 方法命名
|
#### 方法命名
|
||||||
|
|
||||||
| 操作 | 命名规范 | 示例 |
|
| 操作 | 命名规范 | 示例 |
|
||||||
|------|-------------------------|------------------|
|
|----------|-------------------------|------------------|
|
||||||
| 查询单个 | `getXxx` | `getUserInfo()` |
|
| 查询单个 | `getXxx` | `getUserInfo()` |
|
||||||
| 分页查询 | `pageXxx` | `pageSysUser()` |
|
| 分页查询 | `pageXxx` | `pageSysUser()` |
|
||||||
| 新增 | `addXxx` / `saveXxx` | `addSysUser()` |
|
| 新增 | `addXxx` / `saveXxx` | `addSysUser()` |
|
||||||
| 修改 | `updateXxx` / `editXxx` | `editUserInfo()` |
|
| 修改 | `updateXxx` / `editXxx` | `editUserInfo()` |
|
||||||
| 删除 | `delXxx` / `deleteXxx` | `delSysUser()` |
|
| 删除 | `delXxx` / `deleteXxx` | `delSysUser()` |
|
||||||
| 统计 | `countXxx` | — |
|
| 统计 | `countXxx` | — |
|
||||||
|
|
||||||
### 4.2 注释规范
|
### 4.2 注释规范
|
||||||
|
|
||||||
@@ -602,7 +602,7 @@ private static final String CLOUD_FLAG = String.valueOf(Boolean.TRUE);
|
|||||||
- **统一返回**:使用 `Result<T>` 统一响应格式
|
- **统一返回**:使用 `Result<T>` 统一响应格式
|
||||||
- **统一异常**:使用 `BizError`(业务错误)和 `BizWarning`(业务警告)异常类
|
- **统一异常**:使用 `BizError`(业务错误)和 `BizWarning`(业务警告)异常类
|
||||||
- **JDK特性**:使用 `ScopedValue`、`switch表达式`、`record` 等JDK 25特性
|
- **JDK特性**:使用 `ScopedValue`、`switch表达式`、`record` 等JDK 25特性
|
||||||
- **常量管理**:通过 `BaseParams` 接口提供通用常量(`CP_NUM0`、`CP_NUM1` 等)
|
- **常量管理**:通过 `Constants` 接口提供通用常量(`CP_NUM0`、`CP_NUM1` 等)
|
||||||
|
|
||||||
### 4.4 设计规范
|
### 4.4 设计规范
|
||||||
|
|
||||||
@@ -623,125 +623,125 @@ private static final String CLOUD_FLAG = String.valueOf(Boolean.TRUE);
|
|||||||
|
|
||||||
### 5.1 核心框架依赖
|
### 5.1 核心框架依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|-----------------------------|------------|-----------|
|
|-----------------------------|------------|------------------|
|
||||||
| Spring Boot | 4.0.5 | 应用框架 |
|
| Spring Boot | 4.0.5 | 应用框架 |
|
||||||
| Spring Framework | 7.0.6 | 核心框架 |
|
| Spring Framework | 7.0.6 | 核心框架 |
|
||||||
| Spring Cloud | 2025.1.1 | 微服务框架 |
|
| Spring Cloud | 2025.1.1 | 微服务框架 |
|
||||||
| Spring Cloud Alibaba | 2025.1.0.0 | 微服务组件 |
|
| Spring Cloud Alibaba | 2025.1.0.0 | 微服务组件 |
|
||||||
| Spring Data BOM | 2025.1.4 | 数据访问版本管理 |
|
| Spring Data BOM | 2025.1.4 | 数据访问版本管理 |
|
||||||
| MyBatis-Plus | 3.5.16 | ORM增强工具 |
|
| MyBatis-Plus | 3.5.16 | ORM增强工具 |
|
||||||
| MyBatis Spring Boot Starter | 4.0.1 | MyBatis集成 |
|
| MyBatis Spring Boot Starter | 4.0.1 | MyBatis集成 |
|
||||||
|
|
||||||
### 5.2 数据存储依赖
|
### 5.2 数据存储依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|----------------------|-----------------|-------------|
|
|----------------------|---------------------|------------------|
|
||||||
| Druid | 1.2.28 | 数据库连接池 |
|
| Druid | 1.2.28 | 数据库连接池 |
|
||||||
| MySQL Connector/J | 9.6.0 | MySQL数据库驱动 |
|
| MySQL Connector/J | 9.6.0 | MySQL数据库驱动 |
|
||||||
| Elasticsearch Client | 9.2.6 | ES搜索引擎客户端 |
|
| Elasticsearch Client | 9.2.6 | ES搜索引擎客户端 |
|
||||||
| Spring Data Redis | (Spring Boot管理) | Redis集成 |
|
| Spring Data Redis | (Spring Boot管理) | Redis集成 |
|
||||||
| Lettuce | 6.8.2 | Redis客户端 |
|
| Lettuce | 6.8.2 | Redis客户端 |
|
||||||
| Spring AMQP | 4.0.2 | RabbitMQ集成 |
|
| Spring AMQP | 4.0.2 | RabbitMQ集成 |
|
||||||
| RabbitMQ Client | 5.27.1 | RabbitMQ客户端 |
|
| RabbitMQ Client | 5.27.1 | RabbitMQ客户端 |
|
||||||
|
|
||||||
### 5.3 微服务相关依赖
|
### 5.3 微服务相关依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|--------------|-------|-----------|
|
|--------------|-------|--------------------|
|
||||||
| Nacos Client | 3.1.1 | 服务注册与配置中心 |
|
| Nacos Client | 3.1.1 | 服务注册与配置中心 |
|
||||||
| Sentinel | 1.8.9 | 流量控制与熔断降级 |
|
| Sentinel | 1.8.9 | 流量控制与熔断降级 |
|
||||||
| Seata | 2.5.0 | 分布式事务(可用) |
|
| Seata | 2.5.0 | 分布式事务(可用) |
|
||||||
| RocketMQ | 5.3.1 | 消息队列(可用) |
|
| RocketMQ | 5.3.1 | 消息队列(可用) |
|
||||||
|
|
||||||
### 5.4 工具库依赖
|
### 5.4 工具库依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|---------------|---------|------------|
|
|---------------|---------|----------------------|
|
||||||
| Lombok | 1.18.44 | 代码简化 |
|
| Lombok | 1.18.44 | 代码简化 |
|
||||||
| MapStruct | 1.6.3 | 对象映射 |
|
| MapStruct | 1.6.3 | 对象映射 |
|
||||||
| FastJSON2 | 2.0.60 | JSON处理 |
|
| FastJSON2 | 2.0.60 | JSON处理 |
|
||||||
| Velocity | 2.4.1 | 模板引擎(代码生成) |
|
| Velocity | 2.4.1 | 模板引擎(代码生成) |
|
||||||
| Jackson | 2.21.2 | JSON序列化 |
|
| Jackson | 2.21.2 | JSON序列化 |
|
||||||
| Commons Lang3 | 3.20.0 | 通用工具 |
|
| Commons Lang3 | 3.20.0 | 通用工具 |
|
||||||
| Commons IO | 2.21.0 | IO工具 |
|
| Commons IO | 2.21.0 | IO工具 |
|
||||||
| Commons Text | 1.15.0 | 文本处理 |
|
| Commons Text | 1.15.0 | 文本处理 |
|
||||||
| Caffeine | 3.2.3 | 本地缓存 |
|
| Caffeine | 3.2.3 | 本地缓存 |
|
||||||
|
|
||||||
### 5.5 安全相关依赖
|
### 5.5 安全相关依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|-------------------------------|-------|---------------|
|
|-------------------------------|-------|---------------------|
|
||||||
| BouncyCastle (bcprov-jdk18on) | 1.84 | 国密算法(SM2/SM3) |
|
| BouncyCastle (bcprov-jdk18on) | 1.84 | 国密算法(SM2/SM3) |
|
||||||
| Easy Captcha | 1.6.2 | 验证码生成 |
|
| Easy Captcha | 1.6.2 | 验证码生成 |
|
||||||
| java-jwt | 4.5.1 | JWT令牌 |
|
| java-jwt | 4.5.1 | JWT令牌 |
|
||||||
|
|
||||||
### 5.6 文档相关依赖
|
### 5.6 文档相关依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|---------------------|--------|-----------|
|
|---------------------|--------|-------------|
|
||||||
| Knife4j | 4.5.0 | API文档增强 |
|
| Knife4j | 4.5.0 | API文档增强 |
|
||||||
| SpringDoc OpenAPI | 3.0.3 | OpenAPI文档 |
|
| SpringDoc OpenAPI | 3.0.3 | OpenAPI文档 |
|
||||||
| Swagger Annotations | 2.2.48 | API注解 |
|
| Swagger Annotations | 2.2.48 | API注解 |
|
||||||
|
|
||||||
### 5.7 系统监控依赖
|
### 5.7 系统监控依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|-------------------|--------|--------|
|
|-------------------|--------|--------------|
|
||||||
| Spring Boot Admin | 4.0.3 | 应用监控 |
|
| Spring Boot Admin | 4.0.3 | 应用监控 |
|
||||||
| OSHI Core | 6.11.1 | 系统信息采集 |
|
| OSHI Core | 6.11.1 | 系统信息采集 |
|
||||||
| Micrometer | 1.16.4 | 指标采集 |
|
| Micrometer | 1.16.4 | 指标采集 |
|
||||||
|
|
||||||
### 5.8 文件处理依赖
|
### 5.8 文件处理依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|---------------|------------------|-----------|
|
|---------------|------------------|------------------|
|
||||||
| Fesod Sheet | 2.0.1-incubating | Excel处理 |
|
| Fesod Sheet | 2.0.1-incubating | Excel处理 |
|
||||||
| PDFBox | 3.0.7 | PDF处理 |
|
| PDFBox | 3.0.7 | PDF处理 |
|
||||||
| Thumbnailator | 0.4.21 | 图片压缩 |
|
| Thumbnailator | 0.4.21 | 图片压缩 |
|
||||||
| S3 SDK | 2.42.34 | S3对象存储客户端 |
|
| S3 SDK | 2.42.34 | S3对象存储客户端 |
|
||||||
|
|
||||||
### 5.9 其他工具依赖
|
### 5.9 其他工具依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|----------------|--------|---------|
|
|----------------|--------|----------------|
|
||||||
| XXL-Job Core | 3.4.0 | 分布式任务调度 |
|
| XXL-Job Core | 3.4.0 | 分布式任务调度 |
|
||||||
| IP2Region | 3.3.7 | IP归属地查询 |
|
| IP2Region | 3.3.7 | IP归属地查询 |
|
||||||
| UserAgentUtils | 1.21 | 浏览器标识解析 |
|
| UserAgentUtils | 1.21 | 浏览器标识解析 |
|
||||||
| Pinyin4j | 2.5.1 | 拼音转换 |
|
| Pinyin4j | 2.5.1 | 拼音转换 |
|
||||||
| ZXing | 3.5.4 | 二维码/条形码 |
|
| ZXing | 3.5.4 | 二维码/条形码 |
|
||||||
| JSoup | 1.22.1 | HTML解析 |
|
| JSoup | 1.22.1 | HTML解析 |
|
||||||
| MMSEG4J | 1.10.0 | 中文分词 |
|
| MMSEG4J | 1.10.0 | 中文分词 |
|
||||||
|
|
||||||
### 5.10 xtools 内部框架依赖
|
### 5.10 xtools 内部框架依赖
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|-------------------------------|-------|-----------------------|
|
|-------------------------------|-------|------------------------------|
|
||||||
| xtools-core | 5.0.0 | 核心工具库 |
|
| xtools-core | 5.0.0 | 核心工具库 |
|
||||||
| xtools-web | 5.0.0 | Web工具库 |
|
| xtools-web | 5.0.0 | Web工具库 |
|
||||||
| xtools-extend | 5.0.0 | 扩展工具库 |
|
| xtools-extend | 5.0.0 | 扩展工具库 |
|
||||||
| xtools-api | 5.0.0 | API基础库 |
|
| xtools-api | 5.0.0 | API基础库 |
|
||||||
| xtools-boot-api | 5.0.0 | Boot API基础(Result、异常) |
|
| xtools-boot-api | 5.0.0 | Boot API基础(Result、异常) |
|
||||||
| xtools-boot-core | 5.0.0 | Boot核心(Holder、工具) |
|
| xtools-boot-core | 5.0.0 | Boot核心(Holder、工具) |
|
||||||
| xtools-boot-cache-redis | 5.0.0 | Redis缓存封装 |
|
| xtools-boot-cache-redis | 5.0.0 | Redis缓存封装 |
|
||||||
| xtools-boot-db-mybatis-plus | 5.0.0 | MyBatis-Plus封装 |
|
| xtools-boot-db-mybatis-plus | 5.0.0 | MyBatis-Plus封装 |
|
||||||
| xtools-boot-elasticsearch | 5.0.0 | Elasticsearch封装 |
|
| xtools-boot-elasticsearch | 5.0.0 | Elasticsearch封装 |
|
||||||
| xtools-boot-ip | 5.0.0 | IP工具封装 |
|
| xtools-boot-ip | 5.0.0 | IP工具封装 |
|
||||||
| xtools-boot-knife4j | 5.0.0 | Knife4j封装 |
|
| xtools-boot-knife4j | 5.0.0 | Knife4j封装 |
|
||||||
| xtools-boot-log | 5.0.0 | 日志封装 |
|
| xtools-boot-log | 5.0.0 | 日志封装 |
|
||||||
| xtools-boot-mask | 5.0.0 | 数据脱敏封装 |
|
| xtools-boot-mask | 5.0.0 | 数据脱敏封装 |
|
||||||
| xtools-boot-mq-base | 5.0.0 | 消息队列基础 |
|
| xtools-boot-mq-base | 5.0.0 | 消息队列基础 |
|
||||||
| xtools-boot-mq-rabbit | 5.0.0 | RabbitMQ封装 |
|
| xtools-boot-mq-rabbit | 5.0.0 | RabbitMQ封装 |
|
||||||
| xtools-boot-storage-base | 5.0.0 | 存储基础 |
|
| xtools-boot-storage-base | 5.0.0 | 存储基础 |
|
||||||
| xtools-boot-storage-file | 5.0.0 | 本地文件存储 |
|
| xtools-boot-storage-file | 5.0.0 | 本地文件存储 |
|
||||||
| xtools-boot-storage-s3 | 5.0.0 | S3对象存储 |
|
| xtools-boot-storage-s3 | 5.0.0 | S3对象存储 |
|
||||||
| xtools-boot-task | 5.0.0 | 异步任务封装 |
|
| xtools-boot-task | 5.0.0 | 异步任务封装 |
|
||||||
| xtools-boot-thread | 5.0.0 | 线程池封装 |
|
| xtools-boot-thread | 5.0.0 | 线程池封装 |
|
||||||
| xtools-boot-web-base | 5.0.0 | Web基础 |
|
| xtools-boot-web-base | 5.0.0 | Web基础 |
|
||||||
| xtools-boot-web-filter | 5.0.0 | Web过滤器基础 |
|
| xtools-boot-web-filter | 5.0.0 | Web过滤器基础 |
|
||||||
| xtools-boot-job-xxl | 5.0.0 | XXL-Job集成 |
|
| xtools-boot-job-xxl | 5.0.0 | XXL-Job集成 |
|
||||||
| xtools-cloud-alibaba-nacos | 5.0.0 | Nacos集成 |
|
| xtools-cloud-alibaba-nacos | 5.0.0 | Nacos集成 |
|
||||||
| xtools-cloud-alibaba-sentinel | 5.0.0 | Sentinel集成 |
|
| xtools-cloud-alibaba-sentinel | 5.0.0 | Sentinel集成 |
|
||||||
| xtools-cloud-call | 5.0.0 | 微服务远程调用 |
|
| xtools-cloud-call | 5.0.0 | 微服务远程调用 |
|
||||||
|
|
||||||
## 六、技术选型说明
|
## 六、技术选型说明
|
||||||
@@ -825,31 +825,27 @@ private static final String CLOUD_FLAG = String.valueOf(Boolean.TRUE);
|
|||||||
|
|
||||||
### 6.9 其他重要依赖版本
|
### 6.9 其他重要依赖版本
|
||||||
|
|
||||||
| 依赖 | 版本 | 用途 |
|
| 依赖 | 版本 | 用途 |
|
||||||
|----------------------|------------------|-----------|
|
|----------------------|------------------|--------------------|
|
||||||
| Spring Cloud Alibaba | 2025.1.0.0 | 微服务框架 |
|
| Spring Cloud Alibaba | 2025.1.0.0 | 微服务框架 |
|
||||||
| Nacos | 3.1.1 | 服务注册与配置中心 |
|
| Nacos | 3.1.1 | 服务注册与配置中心 |
|
||||||
| Sentinel | 1.8.9 | 流量控制与熔断 |
|
| Sentinel | 1.8.9 | 流量控制与熔断 |
|
||||||
| FastJSON2 | 2.0.60 | JSON序列化 |
|
| FastJSON2 | 2.0.60 | JSON序列化 |
|
||||||
| Lombok | 1.18.44 | 代码简化 |
|
| Lombok | 1.18.44 | 代码简化 |
|
||||||
| MapStruct | 1.6.3 | 对象映射 |
|
| MapStruct | 1.6.3 | 对象映射 |
|
||||||
| Velocity | 2.4.1 | 模板引擎 |
|
| Velocity | 2.4.1 | 模板引擎 |
|
||||||
| Knife4j | 4.5.0 | API文档增强 |
|
| Knife4j | 4.5.0 | API文档增强 |
|
||||||
| BouncyCastle | 1.84 | 加密库 |
|
| BouncyCastle | 1.84 | 加密库 |
|
||||||
| OSHI | 6.11.1 | 系统监控 |
|
| OSHI | 6.11.1 | 系统监控 |
|
||||||
| Easy Captcha | 1.6.2 | 验证码生成 |
|
| Easy Captcha | 1.6.2 | 验证码生成 |
|
||||||
| Fesod Sheet | 2.0.1-incubating | Excel处理 |
|
| Fesod Sheet | 2.0.1-incubating | Excel处理 |
|
||||||
| Jackson | 2.21.2 | JSON处理 |
|
| Jackson | 2.21.2 | JSON处理 |
|
||||||
| Druid | 1.2.28 | 数据库连接池 |
|
| Druid | 1.2.28 | 数据库连接池 |
|
||||||
| Spring Boot Admin | 4.0.3 | 应用监控 |
|
| Spring Boot Admin | 4.0.3 | 应用监控 |
|
||||||
| java-jwt | 4.5.1 | JWT令牌 |
|
| java-jwt | 4.5.1 | JWT令牌 |
|
||||||
| XXL-Job | 3.4.0 | 分布式任务调度 |
|
| XXL-Job | 3.4.0 | 分布式任务调度 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**文档版本**:v1.0
|
**文档版本**:v1.0 **编写日期**:2026-04-16 **项目版本**:1.0.0 **父POM版本**:xtools-parent-cloud:5.0.0 **JDK版本**:25
|
||||||
**编写日期**:2026-04-16
|
|
||||||
**项目版本**:1.0.0
|
|
||||||
**父POM版本**:xtools-parent-cloud:5.0.0
|
|
||||||
**JDK版本**:25
|
|
||||||
**维护团队**:xujun.org
|
**维护团队**:xujun.org
|
||||||
|
|||||||
Vendored
+1
-1
@@ -72,7 +72,7 @@ public enum AppCache implements BaseCacheEnum {
|
|||||||
private final String key;
|
private final String key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 超时时间
|
* 超时时间(秒)
|
||||||
*/
|
*/
|
||||||
private final Long expireTime;
|
private final Long expireTime;
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -126,9 +126,7 @@ public abstract class BaseJob implements Runnable, JobInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 运行作业
|
* 运行作业
|
||||||
*
|
|
||||||
* @throws Exception 运行异常
|
|
||||||
*/
|
*/
|
||||||
public abstract void runJob() throws Exception;
|
public abstract void runJob();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,17 @@
|
|||||||
<!-- 依赖 -->
|
<!-- 依赖 -->
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- xtools begin -->
|
<!-- xtools begin -->
|
||||||
|
<!-- xtools-extend begin -->
|
||||||
|
<!-- JSON WEB令牌 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.auth0</groupId>
|
||||||
|
<artifactId>java-jwt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.xujun</groupId>
|
||||||
|
<artifactId>xtools-extend</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- xtools-extend end -->
|
||||||
<!-- xtools-web 模块 -->
|
<!-- xtools-web 模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.xujun</groupId>
|
<groupId>org.xujun</groupId>
|
||||||
|
|||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package xtools.app.sys.auth.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Title : AuthConfig</p>
|
||||||
|
* <p>Description : AuthConfig</p>
|
||||||
|
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||||
|
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||||
|
* <p>Company : org.xujun</p>
|
||||||
|
*
|
||||||
|
* @author : XuJun
|
||||||
|
* @version : 1.0.0
|
||||||
|
* @date : 2026/2/16 11:01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "auth")
|
||||||
|
public class AuthConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密钥
|
||||||
|
*/
|
||||||
|
private String secret = "xtools-app";
|
||||||
|
}
|
||||||
+8
-1
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import xtools.app.common.cache.enums.AppCache;
|
import xtools.app.common.cache.enums.AppCache;
|
||||||
import xtools.app.sys.auth.model.dto.LoginUserDto;
|
import xtools.app.sys.auth.model.dto.LoginUserDto;
|
||||||
import xtools.app.sys.auth.model.dto.OptLogDto;
|
import xtools.app.sys.auth.model.dto.OptLogDto;
|
||||||
|
import xtools.app.sys.auth.utils.AuthJwtUtils;
|
||||||
import xtools.app.sys.auth.utils.AuthUtils;
|
import xtools.app.sys.auth.utils.AuthUtils;
|
||||||
import xtools.app.sys.auth.utils.PremUtils;
|
import xtools.app.sys.auth.utils.PremUtils;
|
||||||
import xtools.app.sys.auth.whitelist.AuthWhitelist;
|
import xtools.app.sys.auth.whitelist.AuthWhitelist;
|
||||||
@@ -189,12 +190,18 @@ public class AuthFilter extends BaseFilter implements Ordered, BootCommonConstan
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 校验登录权限
|
// 校验登录权限
|
||||||
String accessToken = AuthUtils.getAccessToken(request);
|
String jwt = AuthUtils.getAccessToken(request);
|
||||||
|
JSONObject jwtToken = AuthJwtUtils.verifyToken(jwt);
|
||||||
|
String accessToken = jwtToken.getString(AuthUtils.JWT_TOKEN);
|
||||||
LoginUserDto loginUser = AuthUtils.get(accessToken);
|
LoginUserDto loginUser = AuthUtils.get(accessToken);
|
||||||
if (Objects.isNull(loginUser)) {
|
if (Objects.isNull(loginUser)) {
|
||||||
HttpServletUtils.respWriter(response, JSONObject.from(new Result<>(ResultType.UNAUTHORIZED, null)));
|
HttpServletUtils.respWriter(response, JSONObject.from(new Result<>(ResultType.UNAUTHORIZED, null)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!AuthUtils.checkJwtToken(jwtToken, uid, loginUser.getId())) {
|
||||||
|
HttpServletUtils.respWriter(response, JSONObject.from(new Result<>(ResultType.UNAUTHORIZED, null)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
log.setAccountId(loginUser.getId());
|
log.setAccountId(loginUser.getId());
|
||||||
log.setAccount(loginUser.getAccount());
|
log.setAccount(loginUser.getAccount());
|
||||||
|
|
||||||
|
|||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
package xtools.app.sys.auth.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.auth0.jwt.algorithms.Algorithm;
|
||||||
|
import com.auth0.jwt.interfaces.JWTVerifier;
|
||||||
|
import xtools.app.sys.auth.config.AuthConfig;
|
||||||
|
import xtools.boot.core.utils.SpringContextUtils;
|
||||||
|
import xtools.extend.JwtUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Title : AuthJwtUtils</p>
|
||||||
|
* <p>Description : AuthJwtUtils</p>
|
||||||
|
* <p>DevelopTools : Idea_x64_v2026.2.0.1</p>
|
||||||
|
* <p>DevelopSystem : macOS Tahoe 26.6</p>
|
||||||
|
* <p>Company : org.xujun</p>
|
||||||
|
*
|
||||||
|
* @author : XuJun
|
||||||
|
* @version : 1.0.0
|
||||||
|
* @date : 2026/8/6 15:42
|
||||||
|
*/
|
||||||
|
public class AuthJwtUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签名算法
|
||||||
|
*/
|
||||||
|
private static volatile Algorithm algorithm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
private static volatile JWTVerifier verifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 Token
|
||||||
|
*
|
||||||
|
* @param data 数据
|
||||||
|
* @param expireTime 过期时间
|
||||||
|
* @return Token
|
||||||
|
*/
|
||||||
|
public static String getToken(JSONObject data, long expireTime) {
|
||||||
|
if (algorithm == null) {
|
||||||
|
AuthConfig config = SpringContextUtils.getBean(AuthConfig.class);
|
||||||
|
synchronized (AuthJwtUtils.class) {
|
||||||
|
if (algorithm == null) {
|
||||||
|
algorithm = JwtUtils.getAlgorithm(config.getSecret());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return JwtUtils.getToken(algorithm, data, expireTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证 Token
|
||||||
|
*
|
||||||
|
* @param token Token
|
||||||
|
* @return 数据
|
||||||
|
*/
|
||||||
|
public static JSONObject verifyToken(String token) {
|
||||||
|
if (verifier == null) {
|
||||||
|
AuthConfig config = SpringContextUtils.getBean(AuthConfig.class);
|
||||||
|
synchronized (AuthJwtUtils.class) {
|
||||||
|
if (verifier == null) {
|
||||||
|
verifier = JwtUtils.getVerifier(config.getSecret());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return JwtUtils.verifyToken(verifier, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+66
-10
@@ -6,7 +6,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import xtools.app.common.cache.enums.AppCache;
|
import xtools.app.common.cache.enums.AppCache;
|
||||||
import xtools.app.sys.auth.model.dto.LoginUserDto;
|
import xtools.app.sys.auth.model.dto.LoginUserDto;
|
||||||
import xtools.app.sys.auth.model.dto.TokenDto;
|
import xtools.app.sys.auth.model.dto.TokenDto;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.constant.BootCommonConstant;
|
import xtools.boot.api.constant.BootCommonConstant;
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
import xtools.boot.api.exection.UnauthorizedError;
|
import xtools.boot.api.exection.UnauthorizedError;
|
||||||
@@ -25,6 +24,9 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import static xtools.base.config.Constants.CP_COLON;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : AuthUtils</p>
|
* <p>Title : AuthUtils</p>
|
||||||
* <p>Description : AuthUtils</p>
|
* <p>Description : AuthUtils</p>
|
||||||
@@ -38,6 +40,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class AuthUtils {
|
public class AuthUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jwtToken
|
||||||
|
*/
|
||||||
|
public static final String JWT_TOKEN = "token";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存参数
|
* 缓存参数
|
||||||
*/
|
*/
|
||||||
@@ -63,6 +70,11 @@ public class AuthUtils {
|
|||||||
*/
|
*/
|
||||||
private static final String USER = "id";
|
private static final String USER = "id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uid
|
||||||
|
*/
|
||||||
|
private static final String UID = "uid";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mask
|
* mask
|
||||||
*/
|
*/
|
||||||
@@ -112,13 +124,48 @@ public class AuthUtils {
|
|||||||
return HeaderUtils.getRequestParam(request, BootCommonConstant.UID);
|
return HeaderUtils.getRequestParam(request, BootCommonConstant.UID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从Jwt 中获取 token
|
||||||
|
*
|
||||||
|
* @param jwt Jwt信息
|
||||||
|
* @param uid Uid
|
||||||
|
* @param id Id
|
||||||
|
* @return token
|
||||||
|
*/
|
||||||
|
public static String getTokenByJwt(String jwt, String uid, Long id) {
|
||||||
|
JSONObject jwtToken = AuthJwtUtils.verifyToken(jwt);
|
||||||
|
if (checkJwtToken(jwtToken, uid, id)) {
|
||||||
|
return jwtToken.getString(JWT_TOKEN);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证 JwtToken
|
||||||
|
*
|
||||||
|
* @param jwtToken jwtToken
|
||||||
|
* @param uid Uid
|
||||||
|
* @param id Id
|
||||||
|
* @return 是否通过验证
|
||||||
|
*/
|
||||||
|
public static boolean checkJwtToken(JSONObject jwtToken, String uid, Long id) {
|
||||||
|
if (!Objects.equals(jwtToken.getString(UID), uid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Objects.equals(jwtToken.getLong(USER), id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建 Token
|
* 创建 Token
|
||||||
*
|
*
|
||||||
* @param loginUser 登录用户信息
|
* @param loginUser 登录用户信息
|
||||||
|
* @param uid Uid
|
||||||
* @return Token 信息
|
* @return Token 信息
|
||||||
*/
|
*/
|
||||||
public static TokenDto createToken(LoginUserDto loginUser) {
|
public static TokenDto createToken(LoginUserDto loginUser, String uid) {
|
||||||
Long userId = loginUser.getId();
|
Long userId = loginUser.getId();
|
||||||
remove(userId);
|
remove(userId);
|
||||||
|
|
||||||
@@ -131,18 +178,16 @@ public class AuthUtils {
|
|||||||
|
|
||||||
RedisService redis = RedisUtils.get();
|
RedisService redis = RedisUtils.get();
|
||||||
// 保存 accessToken信息
|
// 保存 accessToken信息
|
||||||
redis.set(getCacheKey(ACCESS_TOKEN, accessToken),
|
redis.set(getCacheKey(ACCESS_TOKEN, accessToken), JSONObject.of("expiryTime", userExpiryTime, "loginUser", loginUser), refreshTokenExpiryTime);
|
||||||
JSONObject.of("expiryTime", userExpiryTime, "loginUser", loginUser), refreshTokenExpiryTime);
|
|
||||||
// 保存 refreshToken信息
|
// 保存 refreshToken信息
|
||||||
redis.set(getCacheKey(REFRESH_TOKEN, refreshToken), accessToken, refreshTokenExpiryTime);
|
redis.set(getCacheKey(REFRESH_TOKEN, refreshToken), accessToken, refreshTokenExpiryTime);
|
||||||
// 保存用户 Token 信息
|
// 保存用户 Token 信息
|
||||||
redis.set(getCacheKey(USER, userId),
|
redis.set(getCacheKey(USER, userId), JSONObject.of(ACCESS_TOKEN, accessToken, REFRESH_TOKEN, refreshToken), refreshTokenExpiryTime);
|
||||||
JSONObject.of(ACCESS_TOKEN, accessToken, REFRESH_TOKEN, refreshToken), refreshTokenExpiryTime);
|
|
||||||
|
|
||||||
// 构建 Token 信息
|
// 构建 Token 信息
|
||||||
TokenDto token = new TokenDto();
|
TokenDto token = new TokenDto();
|
||||||
token.setAccessToken(accessToken);
|
token.setAccessToken(AuthJwtUtils.getToken(JSONObject.of(JWT_TOKEN, accessToken, UID, uid, USER, userId), accessTokenExpiryTime));
|
||||||
token.setRefreshToken(refreshToken);
|
token.setRefreshToken(AuthJwtUtils.getToken(JSONObject.of(JWT_TOKEN, refreshToken, UID, uid, USER, userId), refreshTokenExpiryTime));
|
||||||
token.setExpiryTime(userExpiryTime);
|
token.setExpiryTime(userExpiryTime);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
@@ -244,9 +289,15 @@ public class AuthUtils {
|
|||||||
* 刷新 Token
|
* 刷新 Token
|
||||||
*
|
*
|
||||||
* @param refreshToken RefreshToken
|
* @param refreshToken RefreshToken
|
||||||
|
* @param uid Uid
|
||||||
* @return Token
|
* @return Token
|
||||||
*/
|
*/
|
||||||
public static TokenDto refreshToken(String refreshToken) {
|
public static TokenDto refreshToken(String refreshToken, String uid) {
|
||||||
|
if (StringUtils.isBlank(uid)) {
|
||||||
|
throw new BizError("uid 不能为空");
|
||||||
|
}
|
||||||
|
JSONObject jwtToken = AuthJwtUtils.verifyToken(refreshToken);
|
||||||
|
refreshToken = jwtToken.getString(AuthUtils.JWT_TOKEN);
|
||||||
if (StringUtils.isBlank(refreshToken)) {
|
if (StringUtils.isBlank(refreshToken)) {
|
||||||
throw new BizError("refreshToken 不能为空");
|
throw new BizError("refreshToken 不能为空");
|
||||||
}
|
}
|
||||||
@@ -259,9 +310,14 @@ public class AuthUtils {
|
|||||||
if (loginUser == null) {
|
if (loginUser == null) {
|
||||||
throw new BizError("token已过期,请重新登录");
|
throw new BizError("token已过期,请重新登录");
|
||||||
}
|
}
|
||||||
return createToken(loginUser);
|
if (!checkJwtToken(jwtToken, uid, loginUser.getId())) {
|
||||||
|
remove(loginUser.getId());
|
||||||
|
throw new BizError("token异常,请重新登录");
|
||||||
|
}
|
||||||
|
return createToken(loginUser, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取是否忽略脱敏
|
* 获取是否忽略脱敏
|
||||||
*
|
*
|
||||||
|
|||||||
+8
-1
@@ -5,7 +5,6 @@ import org.springframework.util.AntPathMatcher;
|
|||||||
import org.springframework.util.PathMatcher;
|
import org.springframework.util.PathMatcher;
|
||||||
import xtools.app.common.cache.enums.AppCache;
|
import xtools.app.common.cache.enums.AppCache;
|
||||||
import xtools.app.sys.auth.model.dto.InterfacePermDto;
|
import xtools.app.sys.auth.model.dto.InterfacePermDto;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.cache.redis.base.RedisService;
|
import xtools.boot.cache.redis.base.RedisService;
|
||||||
import xtools.boot.cache.redis.utils.RedisUtils;
|
import xtools.boot.cache.redis.utils.RedisUtils;
|
||||||
import xtools.core.CollectionUtils;
|
import xtools.core.CollectionUtils;
|
||||||
@@ -15,6 +14,14 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static xtools.base.config.Constants.CP_COLON;
|
||||||
|
import static xtools.base.config.Constants.CP_EMPTY;
|
||||||
|
import static xtools.base.config.Constants.CP_LINE;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM1;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM2;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM7;
|
||||||
|
import static xtools.base.config.Constants.CP_SLASH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : PremUtils</p>
|
* <p>Title : PremUtils</p>
|
||||||
* <p>Description : PremUtils</p>
|
* <p>Description : PremUtils</p>
|
||||||
|
|||||||
+3
-2
@@ -62,9 +62,10 @@ public class SysLoginController {
|
|||||||
public Result<TokenDto> refresh(
|
public Result<TokenDto> refresh(
|
||||||
@Schema(description = "刷新令牌", example = "refreshToken")
|
@Schema(description = "刷新令牌", example = "refreshToken")
|
||||||
@NotNull(message = "不能为空")
|
@NotNull(message = "不能为空")
|
||||||
@PathVariable String refreshToken
|
@PathVariable String refreshToken,
|
||||||
|
HttpServletRequest request
|
||||||
) {
|
) {
|
||||||
return Result.ok(AuthUtils.refreshToken(refreshToken));
|
return Result.ok(AuthUtils.refreshToken(refreshToken, AuthUtils.getUid(request)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -5,7 +5,8 @@ import com.baomidou.mybatisplus.spring.service.impl.ServiceImpl;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import xtools.app.sys.mapper.SysDictMapper;
|
import xtools.app.sys.mapper.SysDictMapper;
|
||||||
import xtools.app.sys.model.entity.SysDict;
|
import xtools.app.sys.model.entity.SysDict;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
|
import static xtools.base.config.Constants.CP_NUM1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : SysDictBaseService</p>
|
* <p>Title : SysDictBaseService</p>
|
||||||
|
|||||||
-1
@@ -14,7 +14,6 @@ import xtools.app.sys.model.dto.resp.SysAddressResp;
|
|||||||
import xtools.app.sys.model.entity.SysAddress;
|
import xtools.app.sys.model.entity.SysAddress;
|
||||||
import xtools.app.sys.service.SysAddressService;
|
import xtools.app.sys.service.SysAddressService;
|
||||||
import xtools.app.sys.service.base.SysAddressBaseService;
|
import xtools.app.sys.service.base.SysAddressBaseService;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.model.dto.Result;
|
import xtools.boot.api.model.dto.Result;
|
||||||
import xtools.boot.cache.redis.base.RedisService;
|
import xtools.boot.cache.redis.base.RedisService;
|
||||||
import xtools.core.StringUtils;
|
import xtools.core.StringUtils;
|
||||||
|
|||||||
+4
-1
@@ -26,7 +26,6 @@ import xtools.app.sys.service.SysUserPasswdRuleService;
|
|||||||
import xtools.app.sys.service.SysUserService;
|
import xtools.app.sys.service.SysUserService;
|
||||||
import xtools.app.sys.service.base.SysUserBaseService;
|
import xtools.app.sys.service.base.SysUserBaseService;
|
||||||
import xtools.app.sys.utils.PasswdUtils;
|
import xtools.app.sys.utils.PasswdUtils;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
import xtools.boot.api.exection.BizWarning;
|
import xtools.boot.api.exection.BizWarning;
|
||||||
import xtools.boot.api.model.dto.Result;
|
import xtools.boot.api.model.dto.Result;
|
||||||
@@ -42,6 +41,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static xtools.base.config.Constants.CP_NUM0;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM1;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : SysBaseServiceImpl</p>
|
* <p>Title : SysBaseServiceImpl</p>
|
||||||
* <p>Description : SysBaseServiceImpl</p>
|
* <p>Description : SysBaseServiceImpl</p>
|
||||||
|
|||||||
+4
-1
@@ -15,7 +15,6 @@ import xtools.app.sys.model.dto.resp.SysDeptTreeResp;
|
|||||||
import xtools.app.sys.model.entity.SysDept;
|
import xtools.app.sys.model.entity.SysDept;
|
||||||
import xtools.app.sys.service.SysDeptService;
|
import xtools.app.sys.service.SysDeptService;
|
||||||
import xtools.app.sys.service.base.SysDeptBaseService;
|
import xtools.app.sys.service.base.SysDeptBaseService;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
import xtools.boot.api.exection.BizWarning;
|
import xtools.boot.api.exection.BizWarning;
|
||||||
import xtools.boot.api.model.dto.Result;
|
import xtools.boot.api.model.dto.Result;
|
||||||
@@ -38,6 +37,10 @@ import java.util.Set;
|
|||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static xtools.base.config.Constants.CP_COMMA;
|
||||||
|
import static xtools.base.config.Constants.CP_EMPTY_JSON;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : SysDeptServiceImpl</p>
|
* <p>Title : SysDeptServiceImpl</p>
|
||||||
* <p>Description : 部门管理表 ServiceImpl</p>
|
* <p>Description : 部门管理表 ServiceImpl</p>
|
||||||
|
|||||||
-1
@@ -16,7 +16,6 @@ import xtools.app.sys.model.entity.SysDict;
|
|||||||
import xtools.app.sys.service.SysDictItemService;
|
import xtools.app.sys.service.SysDictItemService;
|
||||||
import xtools.app.sys.service.SysDictService;
|
import xtools.app.sys.service.SysDictService;
|
||||||
import xtools.app.sys.service.base.SysDictBaseService;
|
import xtools.app.sys.service.base.SysDictBaseService;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.enums.StatusEnum;
|
import xtools.boot.api.enums.StatusEnum;
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
import xtools.boot.api.exection.BizWarning;
|
import xtools.boot.api.exection.BizWarning;
|
||||||
|
|||||||
+2
-2
@@ -145,7 +145,7 @@ public class SysLoginServiceImpl implements SysLoginService {
|
|||||||
redisService.set(cacheParam.key(uid), arithmeticDto.getResult(), cacheParam.expireTime());
|
redisService.set(cacheParam.key(uid), arithmeticDto.getResult(), cacheParam.expireTime());
|
||||||
|
|
||||||
// 转换为base64的验证码
|
// 转换为base64的验证码
|
||||||
return "data:image/png;base64," + new String(Base64Utils.encode(imgCode));
|
return "data:image/png;base64," + new String(Base64Utils.encode(imgCode) == null ? new byte[0] : imgCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,7 +208,7 @@ public class SysLoginServiceImpl implements SysLoginService {
|
|||||||
LoginUserDto loginUserDto = sysLoginConvert.entityToCacheDto(user);
|
LoginUserDto loginUserDto = sysLoginConvert.entityToCacheDto(user);
|
||||||
loginUserDto.setRoleIds(sysUserRoleBaseService.getUserRole(user.getId()));
|
loginUserDto.setRoleIds(sysUserRoleBaseService.getUserRole(user.getId()));
|
||||||
redisService.del(captchaKey);
|
redisService.del(captchaKey);
|
||||||
return Result.ok(AuthUtils.createToken(loginUserDto));
|
return Result.ok(AuthUtils.createToken(loginUserDto, uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -23,7 +23,6 @@ import xtools.app.sys.service.SysUserNoticeService;
|
|||||||
import xtools.app.sys.service.base.SysNoticeBaseService;
|
import xtools.app.sys.service.base.SysNoticeBaseService;
|
||||||
import xtools.app.sys.service.base.SysUserBaseService;
|
import xtools.app.sys.service.base.SysUserBaseService;
|
||||||
import xtools.app.sys.service.base.SysUserNoticeBaseService;
|
import xtools.app.sys.service.base.SysUserNoticeBaseService;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
import xtools.boot.api.exection.BizWarning;
|
import xtools.boot.api.exection.BizWarning;
|
||||||
import xtools.boot.api.model.dto.Result;
|
import xtools.boot.api.model.dto.Result;
|
||||||
@@ -41,6 +40,9 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static xtools.base.config.Constants.CP_NUM1;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : SysNoticeServiceImpl</p>
|
* <p>Title : SysNoticeServiceImpl</p>
|
||||||
* <p>Description : 系统通知公告表 ServiceImpl</p>
|
* <p>Description : 系统通知公告表 ServiceImpl</p>
|
||||||
|
|||||||
+4
-1
@@ -6,7 +6,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import xtools.app.sys.model.entity.SysUserPasswdRule;
|
import xtools.app.sys.model.entity.SysUserPasswdRule;
|
||||||
import xtools.app.sys.service.SysPasswdService;
|
import xtools.app.sys.service.SysPasswdService;
|
||||||
import xtools.app.sys.service.SysUserPasswdRuleService;
|
import xtools.app.sys.service.SysUserPasswdRuleService;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
import xtools.boot.api.exection.BizWarning;
|
import xtools.boot.api.exection.BizWarning;
|
||||||
import xtools.core.StringUtils;
|
import xtools.core.StringUtils;
|
||||||
@@ -16,6 +15,10 @@ import java.util.Set;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static xtools.base.config.Constants.CP_EMPTY;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM0;
|
||||||
|
import static xtools.base.config.Constants.CP_NUM3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : SysPasswdServiceImpl</p>
|
* <p>Title : SysPasswdServiceImpl</p>
|
||||||
* <p>Description : SysPasswdServiceImpl</p>
|
* <p>Description : SysPasswdServiceImpl</p>
|
||||||
|
|||||||
+2
-1
@@ -17,7 +17,6 @@ import xtools.app.sys.service.SysUserNoticeInfoService;
|
|||||||
import xtools.app.sys.service.base.SysNoticeBaseService;
|
import xtools.app.sys.service.base.SysNoticeBaseService;
|
||||||
import xtools.app.sys.service.base.SysUserNoticeBaseService;
|
import xtools.app.sys.service.base.SysUserNoticeBaseService;
|
||||||
import xtools.app.sys.service.base.SysUserNoticeInfoBaseService;
|
import xtools.app.sys.service.base.SysUserNoticeInfoBaseService;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.enums.DeleteEnum;
|
import xtools.boot.api.enums.DeleteEnum;
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
import xtools.boot.api.model.dto.Result;
|
import xtools.boot.api.model.dto.Result;
|
||||||
@@ -31,6 +30,8 @@ import java.time.Instant;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static xtools.base.config.Constants.CP_NUM1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : SysUserNoticeInfoServiceImpl</p>
|
* <p>Title : SysUserNoticeInfoServiceImpl</p>
|
||||||
* <p>Description : 系统用户通知公告信息表 ServiceImpl</p>
|
* <p>Description : 系统用户通知公告信息表 ServiceImpl</p>
|
||||||
|
|||||||
+2
-1
@@ -23,7 +23,6 @@ import xtools.app.sys.service.base.SysDeptBaseService;
|
|||||||
import xtools.app.sys.service.base.SysUserBaseService;
|
import xtools.app.sys.service.base.SysUserBaseService;
|
||||||
import xtools.app.sys.service.base.SysUserRoleBaseService;
|
import xtools.app.sys.service.base.SysUserRoleBaseService;
|
||||||
import xtools.app.sys.utils.PasswdUtils;
|
import xtools.app.sys.utils.PasswdUtils;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.boot.api.exection.BizError;
|
import xtools.boot.api.exection.BizError;
|
||||||
import xtools.boot.api.exection.BizWarning;
|
import xtools.boot.api.exection.BizWarning;
|
||||||
import xtools.boot.api.model.dto.Result;
|
import xtools.boot.api.model.dto.Result;
|
||||||
@@ -46,6 +45,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static xtools.base.config.Constants.CP_NUM0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Title : SysUserServiceImpl</p>
|
* <p>Title : SysUserServiceImpl</p>
|
||||||
* <p>Description : 系统用户表 ServiceImpl</p>
|
* <p>Description : 系统用户表 ServiceImpl</p>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import xtools.app.sys.enums.SysRiskType;
|
|||||||
import xtools.app.sys.model.dto.resp.SysRiskResp;
|
import xtools.app.sys.model.dto.resp.SysRiskResp;
|
||||||
import xtools.app.sys.risk.utils.RiskCaffeineUtils;
|
import xtools.app.sys.risk.utils.RiskCaffeineUtils;
|
||||||
import xtools.app.sys.risk.utils.UriRiskUtils;
|
import xtools.app.sys.risk.utils.UriRiskUtils;
|
||||||
import static xtools.base.config.Constants.*;
|
|
||||||
import xtools.core.CollectionUtils;
|
import xtools.core.CollectionUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
Reference in New Issue
Block a user