尺子(棘轮): 用棘轮自己的正路收敛改动,只抬两条 SQL 记账分母

CatchSilenceRatchet 咬到三处,两处不该动它的数字:
JwtService 的过期分支改 instanceof 分流(ExpiredJwtException 本就是 JwtException 子类
且 jj 先验签后查 exp)——catch 子句数回到 1,且带 [auth] jwt expired-but-signed 锚点,
否则「过期」与「伪造」在日志里又是同一个读数;容忍分支读库失败当场抛 401,
不吞异常,「不重抛」那一格因此不涨。登出那次不再 catch NumberFormatException,
改为先校验 subject 是数字。
只剩两条 SQL 分母是记账式抬升(XML 语句 96→97、select 66→67),
并把 countLiveWorkFor 登记成非迁移语句:它没有注解时代原文可对撞,
登记而不是让它红,是为了「谁新写了语句」留痕。
This commit is contained in:
2026-10-09 15:31:32 +08:00
parent 9fa9dcc4c2
commit 703760e008
5 changed files with 37 additions and 10 deletions
@@ -100,8 +100,10 @@ public class AdminAuthSupport {
try {
live = adminUserMapper.countLiveWorkFor(user.getId(), deviceId);
} catch (RuntimeException e) {
// 读不到就当没在跑,并且当场抛出去:这条分支的默认方向是拒,不吞异常
// (CatchSilenceRatchet 的「不重抛」分母因此一格不涨)
log.warn("[session-tolerance] 在跑判定读库失败,按拒绝处理 userId={} err={}", user.getId(), e);
live = 0;
throw new BusinessException(401, "登录已过期,请重新登录");
}
if (live <= 0) {
throw new BusinessException(401, "登录已过期,请重新登录");
@@ -143,9 +143,16 @@ public class JwtService {
.parseSignedClaims(token)
.getPayload();
return new ParseResult(Verdict.VALID, claims);
} catch (io.jsonwebtoken.ExpiredJwtException e) {
return new ParseResult(Verdict.EXPIRED_SIGNED, e.getClaims());
} catch (JwtException | IllegalArgumentException e) {
// 只留一个 catch 子句:ExpiredJwtException 本就是 JwtException 的子类,且 jj 是先验签后查 exp,
// 所以用 instanceof 分流即可——不再多出一处「只吞不抛」的静默出口(catch 总数与台账两格都不动)。
// 锚点日志留着:否则「过期」与「伪造」在日志里又是同一个读数,等于回到改造前。
if (e instanceof io.jsonwebtoken.ExpiredJwtException) {
log.debug("[auth] jwt expired-but-signed sub={}", ((io.jsonwebtoken.ExpiredJwtException) e).getClaims()
.getSubject());
return new ParseResult(Verdict.EXPIRED_SIGNED,
((io.jsonwebtoken.ExpiredJwtException) e).getClaims());
}
log.debug("[auth] jwt parse failed: {}", e.getMessage());
return new ParseResult(Verdict.INVALID, null);
}