feat(gateway): 新增网关服务及权限认证功能
- 新增网关服务模块 han-note-gateway,包含基础配置和启动类 - 实现全局过滤器 AddUserId2HeaderFilter,自动将用户ID添加到请求头(目前有问题) - 配置 Sa-Token 权限认证,支持 JWT 格式的 Token 解析和鉴权 - 新增全局异常处理器 GlobalExceptionHandler,统一处理未登录和权限不足异常 - 实现 StpInterfaceImpl 接口,从 Redis 获取用户角色和权限信息- 配置 RedisTemplate 支持 JSON 序列化,用于存储用户角色和权限数据 - 在 auth 服务中增加登出接口,支持用户退出登录(待完成) - 引入 Nacos 配置中心和注册中心依赖,支持配置动态刷新和服务发现 - 更新 Redis Key 构造方式,使用 userId 和 roleKey 替代 email 和 roleId - 新增告警模块,支持邮件和短信告警方式的配置与切换 -优化角色权限同步逻辑,使用角色 Key 替代角色 ID 存储权限信息 - 添加 bootstrap.yml 配置文件,支持从 Nacos 读取配置
This commit is contained in:
@@ -47,7 +47,9 @@ logging:
|
||||
############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: satoken
|
||||
token-name: Authorization
|
||||
# token前缀
|
||||
token-prefix: Bearer
|
||||
# token 有效期(单位:秒) 默认30天,-1 代表永久有效
|
||||
timeout: 2592000
|
||||
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||
@@ -57,6 +59,8 @@ sa-token:
|
||||
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
|
||||
is-share: true
|
||||
# token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||
token-style: simple-uuid
|
||||
token-style: random-128
|
||||
# 是否输出操作日志
|
||||
is-log: true
|
||||
alarm:
|
||||
type: mail # 告警类型
|
||||
|
||||
19
han-note-auth/src/main/resources/bootstrap.yml
Normal file
19
han-note-auth/src/main/resources/bootstrap.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev # 激活的环境
|
||||
application:
|
||||
name: han-note-auth # 必须在 bootstrap 阶段就设置应用名
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: http://127.0.0.1:8848 # 指定 Nacos 配置中心的服务器地址
|
||||
prefix: ${spring.application.name} # 配置 Data Id 前缀,这里使用应用名称作为前缀
|
||||
group: DEFAULT_GROUP # 所属组
|
||||
namespace: han-note # 命名空间
|
||||
file-extension: yaml # 配置文件格式
|
||||
refresh-enabled: true # 是否开启动态刷新
|
||||
discovery:
|
||||
enabled: true # 启用服务发现
|
||||
group: DEFAULT_GROUP # 所属组
|
||||
namespace: han-note # 命名空间
|
||||
server-addr: 127.0.0.1:8848 # 指定 Nacos 配置中心的服务器地址
|
||||
@@ -25,4 +25,13 @@
|
||||
where status = 0
|
||||
and is_deleted = 0;
|
||||
</select>
|
||||
|
||||
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from t_role
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
and is_deleted = 0
|
||||
and status = 0;
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user