记一次开源脚手架的登录认证流程

代码仓库

https://gitee.com/y_project/RuoYi-Cloud.git

时序图

登录和用户列表都只经过三个正在运行的服务:网关 ruoyi-gateway、认证 ruoyi-auth、系统 ruoyi-system。ruoyi-api-system 是认证服务里的 Feign 接口包,不是独立进程。

  1. 登录 POST /auth/login

网关白名单放行这条路径,所以 AuthFilter 不校验令牌。验证码在网关里核对,用户和权限在系统服务查库,令牌由认证服务写入 Redis。
MySQL 系统 ruoyi-system Nacos 认证 ruoyi-auth Redis 网关 ruoyi-gateway 前端 MySQL 系统 ruoyi-system Nacos 认证 ruoyi-auth Redis 网关 ruoyi-gateway 前端 #mermaid-svg-s5Qw4b0OrfKhqHTH{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-s5Qw4b0OrfKhqHTH .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-s5Qw4b0OrfKhqHTH .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-s5Qw4b0OrfKhqHTH .error-icon{fill:#552222;}#mermaid-svg-s5Qw4b0OrfKhqHTH .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-s5Qw4b0OrfKhqHTH .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-s5Qw4b0OrfKhqHTH .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-s5Qw4b0OrfKhqHTH .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-s5Qw4b0OrfKhqHTH .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-s5Qw4b0OrfKhqHTH .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-s5Qw4b0OrfKhqHTH .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-s5Qw4b0OrfKhqHTH .marker{fill:#333333;stroke:#333333;}#mermaid-svg-s5Qw4b0OrfKhqHTH .marker.cross{stroke:#333333;}#mermaid-svg-s5Qw4b0OrfKhqHTH svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-s5Qw4b0OrfKhqHTH p{margin:0;}#mermaid-svg-s5Qw4b0OrfKhqHTH .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-s5Qw4b0OrfKhqHTH text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-s5Qw4b0OrfKhqHTH .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-s5Qw4b0OrfKhqHTH .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-s5Qw4b0OrfKhqHTH .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-s5Qw4b0OrfKhqHTH .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-s5Qw4b0OrfKhqHTH #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-s5Qw4b0OrfKhqHTH .sequenceNumber{fill:white;}#mermaid-svg-s5Qw4b0OrfKhqHTH #sequencenumber{fill:#333;}#mermaid-svg-s5Qw4b0OrfKhqHTH #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-s5Qw4b0OrfKhqHTH .messageText{fill:#333;stroke:none;}#mermaid-svg-s5Qw4b0OrfKhqHTH .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-s5Qw4b0OrfKhqHTH .labelText,#mermaid-svg-s5Qw4b0OrfKhqHTH .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-s5Qw4b0OrfKhqHTH .loopText,#mermaid-svg-s5Qw4b0OrfKhqHTH .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-s5Qw4b0OrfKhqHTH .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-s5Qw4b0OrfKhqHTH .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-s5Qw4b0OrfKhqHTH .noteText,#mermaid-svg-s5Qw4b0OrfKhqHTH .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-s5Qw4b0OrfKhqHTH .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-s5Qw4b0OrfKhqHTH .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-s5Qw4b0OrfKhqHTH .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-s5Qw4b0OrfKhqHTH .actorPopupMenu{position:absolute;}#mermaid-svg-s5Qw4b0OrfKhqHTH .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-s5Qw4b0OrfKhqHTH .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-s5Qw4b0OrfKhqHTH .actor-man circle,#mermaid-svg-s5Qw4b0OrfKhqHTH line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-s5Qw4b0OrfKhqHTH :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} ValidateCodeFilterruoyi-gateway TokenController、SysLoginService模块 ruoyi-auth Feign RemoteUserService模块 ruoyi-api-system InnerAuth 校验内部调用SysUserController.info BCrypt 校验密码模块 ruoyi-common-security TokenService.refreshToken POST /auth/login读取 captcha_codes:{uuid}验证码答案POST /login查找 ruoyi-systemGET /user/info/{username}查询用户、角色、菜单权限用户与 permissionsR LoginUser写入 login_tokens:{uuid}access_tokenaccess_token

  1. 用户列表 GET /system/user/list

这次不再进入认证服务。网关只确认 Redis 里的登录状态还在,系统服务再从 Redis 取出 LoginUser,用其中的权限集合比对 system:user:list。
MySQL 系统 ruoyi-system Redis 网关 ruoyi-gateway 前端 MySQL 系统 ruoyi-system Redis 网关 ruoyi-gateway 前端 #mermaid-svg-hMlEy58MEm5swYG1{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-hMlEy58MEm5swYG1 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-hMlEy58MEm5swYG1 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-hMlEy58MEm5swYG1 .error-icon{fill:#552222;}#mermaid-svg-hMlEy58MEm5swYG1 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-hMlEy58MEm5swYG1 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-hMlEy58MEm5swYG1 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-hMlEy58MEm5swYG1 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-hMlEy58MEm5swYG1 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-hMlEy58MEm5swYG1 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-hMlEy58MEm5swYG1 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-hMlEy58MEm5swYG1 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-hMlEy58MEm5swYG1 .marker.cross{stroke:#333333;}#mermaid-svg-hMlEy58MEm5swYG1 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-hMlEy58MEm5swYG1 p{margin:0;}#mermaid-svg-hMlEy58MEm5swYG1 .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-hMlEy58MEm5swYG1 text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-hMlEy58MEm5swYG1 .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-hMlEy58MEm5swYG1 .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-hMlEy58MEm5swYG1 .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-hMlEy58MEm5swYG1 .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-hMlEy58MEm5swYG1 #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-hMlEy58MEm5swYG1 .sequenceNumber{fill:white;}#mermaid-svg-hMlEy58MEm5swYG1 #sequencenumber{fill:#333;}#mermaid-svg-hMlEy58MEm5swYG1 #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-hMlEy58MEm5swYG1 .messageText{fill:#333;stroke:none;}#mermaid-svg-hMlEy58MEm5swYG1 .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-hMlEy58MEm5swYG1 .labelText,#mermaid-svg-hMlEy58MEm5swYG1 .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-hMlEy58MEm5swYG1 .loopText,#mermaid-svg-hMlEy58MEm5swYG1 .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-hMlEy58MEm5swYG1 .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-hMlEy58MEm5swYG1 .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-hMlEy58MEm5swYG1 .noteText,#mermaid-svg-hMlEy58MEm5swYG1 .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-hMlEy58MEm5swYG1 .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-hMlEy58MEm5swYG1 .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-hMlEy58MEm5swYG1 .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-hMlEy58MEm5swYG1 .actorPopupMenu{position:absolute;}#mermaid-svg-hMlEy58MEm5swYG1 .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-hMlEy58MEm5swYG1 .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-hMlEy58MEm5swYG1 .actor-man circle,#mermaid-svg-hMlEy58MEm5swYG1 line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-hMlEy58MEm5swYG1 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} AuthFilter模块 ruoyi-gateway 附带用户标识请求头去掉 /system 前缀 HeaderInterceptor PreAuthorizeAspect模块 ruoyi-common-security比对 system:user:list SysUserController.list模块 ruoyi-system GET /system/user/list检查 login_tokens:{uuid} 是否存在已登录GET /user/list读取整个 LoginUserpermissions查询用户列表用户数据AjaxResultAjaxResult

相关推荐
十方空烬1 天前
命中不等于支持:一个离线证据检索器只保证引文位置
开源
miofly1 天前
百度开源ERNIE 5.5 Flash Base,总参数280B仅激活14B
开源·github
unconditional1 天前
我拆了 sdkm 的回滚设计:每个写操作,都提前写好了翻车预案
rust·开源
熟的生菜1 天前
从零造一个腱绳驱动灵巧手——仿真器篇4:Qt 界面实战——属性面板、树控件与姿势系统
开源
用户117910488331 天前
鸿蒙签名失败不是玄学:5 个证据点把 hapsigntool 一次排通 GitHub:swsgbl/hmharness
开源·ai编程·harmonyos
用户2991422196801 天前
GitHub 热榜项目:日榜(2026-11-07)
人工智能·开源·github
Flynt1 天前
内存省16倍的Lightpanda实测:数字是真的,但并发代码要重写
性能优化·开源·agent
分布式存储与RustFS1 天前
Hudi 表想摆脱 HDFS 绑定?用 Spark + Hudi 直接写进 RustFS
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
miofly1 天前
GitHub 日榜趋势速报 | 2026-11-07
开源·github
冬奇Lab2 天前
一天一个开源项目(第255篇):Mika —— 装在安卓手机里的 AI 代理,在后台虚拟屏上替你操作 App 和网页
人工智能·开源·资讯