feat(停用账号): 停用/删除即强制下线并点名成因——写入口、X-Auth-Reason 头、三面接线
- Java:AdminUserUpdateRequest 加 disabled 开关(不能停自己、归属门沿用既有闸), AccountExpiryService/AdminAuthSupport 抛停用/删除子类型,GlobalExceptionHandler 打 X-Auth-Reason: disabled|deleted 响应头;业务码保持 401 不变,不惊动三个既有消费者 - 后台管理:用户页停用/解除停用按钮 + 已停用徽章;拦截器把成因随 &auth= 带给登录页, 登录页分停用/删除两种文案;源码钉子棘轮基线按正路重生成 - 用户端:kick-handler 按 X-Auth-Reason 分支亮停用/删除标记(互斥清理), 登录页两段专属文案且各自关自动登录;跳转目标仍是 /login?expired=1 - 反假绿:摘掉成因头注入实测 2/4 红(变异自证),还原等值后复跑回绿
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
package com.nanri.aiimage.common.exception;
|
||||
|
||||
/**
|
||||
* 账号已被删除(硬删后 selectById 落空)。会话闸专用;
|
||||
* {@code GlobalExceptionHandler} 据此打 X-Auth-Reason: deleted,前端点名删除成因。
|
||||
*/
|
||||
public class AccountDeletedException extends BusinessException {
|
||||
|
||||
public static final String REASON = "deleted";
|
||||
|
||||
public AccountDeletedException(int code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.nanri.aiimage.common.exception;
|
||||
|
||||
/**
|
||||
* 账号已被管理员停用。登录闸(403)与会话闸(401)共用;
|
||||
* 会话路径上 {@code GlobalExceptionHandler} 据此打 X-Auth-Reason: disabled,
|
||||
* 前端据此在登录页点名停用成因。业务码仍沿用 401——改成新码会打断
|
||||
* 两面前端与桌面端既有的一切「code==401 才收口」的判定。
|
||||
*/
|
||||
public class AccountDisabledException extends BusinessException {
|
||||
|
||||
public static final String REASON = "disabled";
|
||||
|
||||
public AccountDisabledException(int code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
}
|
||||
+12
-1
@@ -24,6 +24,9 @@ import java.io.IOException;
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
/** 会话失效成因标记头:disabled=账号已停用、deleted=账号已删除;其余 401 不打此头。 */
|
||||
public static final String AUTH_REASON_HEADER = "X-Auth-Reason";
|
||||
|
||||
private final TaskOwnerForwardService taskOwnerForwardService;
|
||||
|
||||
@ExceptionHandler(TaskOwnerMismatchException.class)
|
||||
@@ -72,7 +75,15 @@ public class GlobalExceptionHandler {
|
||||
}
|
||||
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public ApiResponse<Void> handleBusinessException(BusinessException ex, HttpServletRequest request) {
|
||||
public ApiResponse<Void> handleBusinessException(BusinessException ex, HttpServletRequest request,
|
||||
jakarta.servlet.http.HttpServletResponse response) {
|
||||
// 停用/删除的成因走响应头而非新业务码:code 必须保持 401,改成新码会同时打断
|
||||
// 两面前端拦截器与桌面端 app_client/main.py 里按 'code': 401 识别鉴权失败的判定
|
||||
if (ex instanceof AccountDisabledException) {
|
||||
response.setHeader(AUTH_REASON_HEADER, AccountDisabledException.REASON);
|
||||
} else if (ex instanceof AccountDeletedException) {
|
||||
response.setHeader(AUTH_REASON_HEADER, AccountDeletedException.REASON);
|
||||
}
|
||||
// 业务异常此前完全不记日志:2026-09-16 线上「保存权限/创建用户」双双失败时,
|
||||
// 服务端只留 RequestTraceFilter 的 200 一行,根因只能靠反推响应体字节数才定位到。
|
||||
// 401/4011(未登录、被顶下线)属于轮询类接口的常态噪声,降为 debug 以免淹没真实业务错。
|
||||
|
||||
+3
-1
@@ -1,5 +1,6 @@
|
||||
package com.nanri.aiimage.common.security;
|
||||
|
||||
import com.nanri.aiimage.common.exception.AccountDisabledException;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.common.mapper.ShopManageGroupMapper;
|
||||
@@ -87,7 +88,8 @@ public class AccountExpiryService {
|
||||
*/
|
||||
private static void assertNotDisabled(java.time.LocalDateTime disabledAt, int code) {
|
||||
if (disabledAt != null) {
|
||||
throw new BusinessException(code, "账号已停用,请联系管理员");
|
||||
// 子类型只为了让 GlobalExceptionHandler 打 X-Auth-Reason: disabled;码与文案不变
|
||||
throw new AccountDisabledException(code, "账号已停用,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.nanri.aiimage.common.security;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import com.nanri.aiimage.common.exception.AccountDeletedException;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.JwtService;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
@@ -66,7 +67,7 @@ public class AdminAuthSupport {
|
||||
AdminUserEntity user = adminUserMapper.selectById(userId);
|
||||
if (user == null) {
|
||||
// 硬删账号会留下孤儿在跑行:认人必须排在容忍之前,否则已删账号被自己的孤儿行继续供着
|
||||
throw new BusinessException(401, "用户不存在");
|
||||
throw new AccountDeletedException(401, "用户不存在");
|
||||
}
|
||||
// 吊销先于单设备比对:那条路径第一行就是 if (exempt) return;(超管豁免),
|
||||
// 把吊销挂在它下面等于超管永不见吊销
|
||||
|
||||
Reference in New Issue
Block a user