Skip to content

micro-java 安全与鉴权

认证授权集中在 xichen-common,由 auth-servicesystem-servicemonitor-service 通过 @Import(SecurityConfig.class) 引入,与 server-java 安全 语义对齐。

请求链路

text
HTTP(经 Gateway,Gateway 不校验 JWT)
  → JwtAuthenticationFilter
  → CustomUserDetailsService(xichen-common)
  → SecurityContext
  → @PreAuthorize("hasAuthority('...')")

SecurityConfig 白名单

无需登录:

路径说明
/api/v1/health健康检查
/api/v1/auth/login登录
/api/v1/auth/refresh刷新 Token
/api/v1/system/database/init数据库 init
/api/v1/system/files/download/**文件下载
/api-docs/**/swagger-ui/**Swagger

其余路径:authenticated()

Auth 接口(logoutmeprofilechange-password)仅需登录,无细粒度 permission。

JWT 跨服务

服务角色
auth-service签发 Token
system-service校验 Token
monitor-service校验 Token

所有业务服务 JWT_SECRET 必须相同app.jwt.secret)。

Token payload 含 userId;权限每次从 DB 加载,不落 Token。

权限码

与 server-java / 契约一致,例如:

前缀示例
system:user:*list / create / update / delete / export / import / resetPwd
system:role:*list / create / update / delete
system:menu:*
system:dept:*
system:dict:*
system:file:*
system:permission:*
monitor:*operlog / logininfor / job

完整列表见 server-java 安全 与 init 种子。

401 / 403

Handler场景
JsonAuthenticationEntryPoint未登录或 Token 无效
JsonAccessDeniedHandler@PreAuthorize 不满足

响应:{ code, message, data }

CORS

层级配置
GatewayGatewayCorsConfig + CORS_ORIGINS
业务服务app.cors.allowed-origins + SecurityConfig

Web 开发推荐 VITE_API_BASE_URL 留空走 Vite 代理;直连 :8080 时依赖 Gateway CORS。详见 Gateway — CORS

关键源码

模块
SecurityConfigxichen-common
JwtAuthenticationFilterxichen-common
CustomUserDetailsServicexichen-common
OperLogAspectxichen-common
AuthControllerauth-service
System*Controllersystem-service
Sys*Controllermonitor-service

相关文档

Xichen Full Stack 内部文档