Files
zhengwr 2f1f00a74a F2-6: JWT 瘦身——roles 不入 claims,RoleResolver 服务端缓存解析
- JwtService.issue() 移除 CLAIM_ROLES,token 仅携带 userId/account/name/depart/org
- JwtService.parse() roles 固定返回空列表(由 RoleResolver 填充)
- 新增 RoleResolver:Caffeine 缓存 userId→roles,TTL 5 分钟,容量 5000
  SQL 与 SysUserService 同源(sys_usergrouprole⋈sys_usergroupuser)
  DB 不可达时降级为空列表,不阻断请求
- JwtAuthFilter:parse 后调 RoleResolver 填充 roles,AuthPrincipal 对下游零改动
- SecurityConfig:注入 RoleResolver 传给 JwtAuthFilter
- platform-auth/pom.xml 加 Caffeine 依赖
- 单测覆盖:RoleResolverTest(命中/evict/evictAll/TTL降级)、JwtServiceTest 更新
  (roles不入token断言 + token<1KB断言)、EngineContextIsolationTest/SecurityProfileTest 适配

实测:admin token 316B,ceshi token 344B(原6413/16924字符)
2026-06-12 03:09:22 +08:00

31 lines
2.3 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.eip4</groupId>
<artifactId>eip4-platform</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>platform-auth</artifactId>
<name>platform-auth</name>
<description>P2:组织/权限/数据权限真实现(当前为 PoC 桩 + C2 数据权限最小真实现)</description>
<dependencies>
<dependency><groupId>com.eip4</groupId><artifactId>platform-legacy-core</artifactId></dependency>
<!-- 认证四层:Spring Security 过滤链 + Web(登录端点/JWT 过滤器) -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
<!-- 校验客户库 SYS_USER:只读 SELECT(JdbcTemplate),不引 ORM(与架构选型表一致) -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency>
<!-- 无状态 JWT 签发/校验 -->
<dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-api</artifactId></dependency>
<dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-impl</artifactId><scope>runtime</scope></dependency>
<dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-jackson</artifactId><scope>runtime</scope></dependency>
<!-- F2-6 JWT 瘦身:RoleResolver 服务端解析角色,Caffeine 缓存 userId→roles(TTL 5 分钟) -->
<dependency><groupId>com.github.ben-manes.caffeine</groupId><artifactId>caffeine</artifactId></dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
<dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-test</artifactId><scope>test</scope></dependency>
</dependencies>
</project>