feat(上架): 店铺互斥改为按(设备,店铺),同店可在不同客户端并行跑不同国家
背景:紫鸟浏览器会话是每台客户端一份,同一家店可以在两台机器上并行; 国家是会话内的可切换状态(SwitchingCountries,断线重连还会再切), 所以真正必须串行的只有"同一台设备上的同一家店"。原来的全局按店铺互斥 把跨机器的合法并行也挡了(2026-09-18 任务 28624 被 28616 误挡)。 - V130:biz_publish_file 增加 device_id 列 - AdminAuthSupport.currentDeviceId():只读 JWT 签名的 deviceId claim, 不信任客户端可控的 X-Device-Id 请求头 - activateFile 互斥键改为 (device_id, shop_name);device 为空(旧客户端 token 无该 claim / 内部令牌调用)时退回全局店铺互斥,保守不放宽; 存量 RUNNING 行的 NULL device 视为"来源不明",同样保守拦到跑完为止 - 前端与客户端无需改动:页面 axios 对 /newApi 已带 Authorization Bearer
This commit is contained in:
@@ -9,6 +9,7 @@ import io.jsonwebtoken.Claims;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -19,6 +20,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AdminAuthSupport {
|
||||
@@ -62,8 +64,30 @@ public class AdminAuthSupport {
|
||||
return user;
|
||||
}
|
||||
|
||||
/** 当前用户必须是管理员或超级管理员,否则抛 403。 */
|
||||
public AdminUserEntity requireAdmin(HttpServletRequest request) {
|
||||
/**
|
||||
* 解析当前请求 JWT 中**签名的**设备标识(deviceId claim);识别不出时返回空串。
|
||||
*
|
||||
* <p>无 token、token 过期/非法、内部令牌通道调用一律返回空串——调用方必须把空串
|
||||
* 当作"来源不明"做保守判定,绝不据此放宽任何限制。只认签名 claim,不接受
|
||||
* X-Device-Id 请求头(头由客户端可控,见 {@link DeviceSessionPolicy} 类注释)。</p>
|
||||
*
|
||||
* <p>本方法只做识别、不做鉴权,因此解析失败不抛异常,仅记日志后返回空串,
|
||||
* 避免把匿名/内部调用直接升级成 401。</p>
|
||||
*/
|
||||
public String currentDeviceId(HttpServletRequest request) {
|
||||
String token = resolveToken(request);
|
||||
if (token == null || token.isBlank()) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return DeviceSessionPolicy.claimDeviceId(jwtService.parse(token));
|
||||
} catch (Exception ex) {
|
||||
log.warn("[auth] 解析 token 取设备标识失败,按来源不明处理: {}", ex.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/** 当前用户必须是管理员或超级管理员,否则抛 403。 */ public AdminUserEntity requireAdmin(HttpServletRequest request) {
|
||||
AdminUserEntity user = requireUser(request);
|
||||
String role = currentRole(user);
|
||||
if (role == null) {
|
||||
|
||||
Reference in New Issue
Block a user