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:
2026-10-09 16:35:35 +08:00
parent 3c2fd54e3e
commit 24a94428e8
25 changed files with 704 additions and 31 deletions
@@ -16,4 +16,10 @@ public class AdminUserUpdateRequest {
* yyyy-MM-dd[ HH:mm[:ss]],允许过去时间(立即到期 = 手工停用)。
*/
private String expiresAt;
/**
* 停用开关(V155):null=不动;true=停用(写 disabled_at,该账号已发令牌立刻 401、
* 无法重新登录);false=解除停用(清 disabled_at,原 expires_at 不受影响)。
* 普通账号也可被停用——停用是安全动作,不走「到期只设管理员」那条角色限制。
*/
private Boolean disabled;
}
@@ -25,6 +25,9 @@ public class AdminUserItemVo {
/** 到期时间(yyyy-MM-dd HH:mm);空串=永不过期,前端按此渲染。 */
@JsonProperty("expires_at")
private String expiresAt;
/** 管理员停用时刻(V155,yyyy-MM-dd HH:mm);null=未停用。 */
@JsonProperty("disabled_at")
private String disabledAt;
@JsonProperty("pinyin_abbr")
private String pinyinAbbr;
}
@@ -385,9 +385,15 @@ public class AdminUserService {
&& (wantRole == null || wantRole.isEmpty())
&& request.getColumnIds() == null
&& request.getCompanyId() == null
&& request.getExpiresAt() == null) {
&& request.getExpiresAt() == null
&& request.getDisabled() == null) {
throw new BusinessException("请提供要修改的内容");
}
// 不许停自己:现有的角色闸(admin 只动自建普通账号 / 公司超管与超管目标互斥)已经
// 把三种角色都挡住了,这里显式再钉一道——上面的结构变了时,这道不能跟着悄悄消失。
if (request.getDisabled() != null && currentUser.getId().equals(uid)) {
throw new BusinessException(400, "不能停用自己的账号");
}
AdminUserEntity target = adminUserMapper.selectById(uid);
if (target == null) {
@@ -468,6 +474,13 @@ public class AdminUserService {
request.getExpiresAt().trim().isEmpty() ? null : parseExpiresAt(request.getExpiresAt()));
dirty = true;
}
if (request.getDisabled() != null) {
// 停用/解除停用。停用是硬停点:该账号已发令牌在下一次请求就被 assertSessionAllowed
// 拒成 401(排在在跑容忍之前),前端据此强制退出到登录页。
update.set(AdminUserEntity::getDisabledAt,
Boolean.TRUE.equals(request.getDisabled()) ? LocalDateTime.now() : null);
dirty = true;
}
String roleBefore = DeviceSessionPolicy.resolveRole(target.getRole(), target.getIsAdmin(),
target.getCreatedById());
if (request.getExpiresAt() == null && mayCarryOwnExpiry(roleBefore) && !mayCarryOwnExpiry(roleAfter)
@@ -627,6 +640,8 @@ public class AdminUserService {
vo.setUpdatedAt(updatedAt == null ? "" : updatedAt.format(CREATED_AT_FORMATTER));
// 到期时间:null(永不过期)与空字符串在列表里都要有明确渲染,前端按空串判"永不过期"
vo.setExpiresAt(entity.getExpiresAt() == null ? "" : entity.getExpiresAt().format(CREATED_AT_FORMATTER));
// 停用时刻(V155):null=未停用,前端按此渲染「已停用」徽标
vo.setDisabledAt(entity.getDisabledAt() == null ? null : entity.getDisabledAt().format(CREATED_AT_FORMATTER));
vo.setPinyinAbbr(PinyinAbbrUtil.abbr(entity.getUsername()));
return vo;
}