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:
Hanserwei
2025-10-02 21:46:05 +08:00
parent eb9f887ac3
commit 4c6a08438a
27 changed files with 668 additions and 26 deletions

View File

@@ -8,10 +8,7 @@ import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/user")
@@ -27,4 +24,13 @@ public class UserController {
public Response<String> loginAndRegister(@Validated @RequestBody UserLoginReqVO userLoginReqVO) {
return userService.loginAndRegister(userLoginReqVO);
}
@PostMapping("/logout")
@ApiOperationLog(description = "账号登出")
public Response<?> logout(@RequestHeader("userId") String userId) {
log.info("==> 网关透传过来的用户 ID: {}", userId);
// todo 账号退出登录逻辑待实现
return Response.success();
}
}