|
|
@@ -113,11 +113,17 @@ private static final String[] PUBLIC_PATHS = {
|
|
|
SecurityContextHolder.clearContext();
|
|
|
|
|
|
String path = request.getRequestURI();
|
|
|
+ // 公开路径标记:不提前返回,改为“携有效 token 则解析用户上下文,否则匿名放行”。
|
|
|
+ // 修复:商品列表等公开接口此前永远拿不到 userId(白名单短路直接 return),
|
|
|
+ // 导致登录用户被当作游客处理,供应商体系可见性(vendor_visible=1 同体系内可见)
|
|
|
+ // 对登录用户失效(如 Enagic 体系成员看不到本体系 vendor 商品)。
|
|
|
+ boolean isPublicPath = false;
|
|
|
for (String publicPath : PUBLIC_PATHS) {
|
|
|
String boundaryPath = publicPath.endsWith("/**")
|
|
|
? publicPath.substring(0, publicPath.length() - 3) : publicPath;
|
|
|
if (path.equals(publicPath) || path.startsWith(boundaryPath + "/")) {
|
|
|
- return true;
|
|
|
+ isPublicPath = true;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -144,6 +150,11 @@ private static final String[] PUBLIC_PATHS = {
|
|
|
writeUnauthorized(response);
|
|
|
return false;
|
|
|
}
|
|
|
+ if (isPublicPath) {
|
|
|
+ // 公开路径无 token:保持原行为(不设置 userId,控制器取 null),放行匿名浏览
|
|
|
+ log.debug("请求 {} 公开路径无Token,匿名放行", path);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
log.debug("请求 {} 无Token,设为匿名用户", path);
|
|
|
setAnonymousUser(request);
|
|
|
setAnonymousSecurityContext();
|
|
|
@@ -235,6 +246,11 @@ private static final String[] PUBLIC_PATHS = {
|
|
|
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
|
+ if (isPublicPath) {
|
|
|
+ // 公开路径 token 无效/过期:不 401,降级匿名放行,保持游客可浏览
|
|
|
+ log.warn("公开路径token无效, 降级匿名放行: path={}, error={}", path, e.getMessage());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
// Token 无效/过期一律 401(不区分 loginRequired):
|
|
|
// 避免前端带残留 token 时被静默降级为匿名,导致需登录接口返回
|
|
|
// "请先登录"(code=500) 而前端仍认为已登录。前端收到 401 后
|