From dc643ba44fd2a426263015491268a0f0d6b4671d Mon Sep 17 00:00:00 2001 From: lrj <owen.stl@gmail.com> Date: 星期三, 01 十月 2025 08:39:29 +0800 Subject: [PATCH] 删除包含test、check、fix的文件名的文件 --- backend/src/main/java/com/rongyichuang/common/util/UserContextUtil.java | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/rongyichuang/common/util/UserContextUtil.java b/backend/src/main/java/com/rongyichuang/common/util/UserContextUtil.java index e659917..7ab37f2 100644 --- a/backend/src/main/java/com/rongyichuang/common/util/UserContextUtil.java +++ b/backend/src/main/java/com/rongyichuang/common/util/UserContextUtil.java @@ -51,6 +51,12 @@ return userId; } + if (token == null) { + logger.debug("鏈兘浠庤姹傚ご鑾峰彇鍒癑WT token"); + } else { + logger.debug("浠庤姹傚ご鑾峰彇鍒皌oken浣嗘牎楠屽け璐�"); + } + // 濡傛灉娌℃湁鏈夋晥鐨凧WT token锛屽皾璇曚粠Spring Security涓婁笅鏂囪幏鍙� Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated() && @@ -86,11 +92,18 @@ private String getTokenFromRequest() { try { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (attributes != null) { + if (attributes == null) { + logger.warn("RequestContextHolder涓棤ServletRequestAttributes锛屽彲鑳戒负寮傛鎵ц鎴栭潪Servlet鐜"); + } else { HttpServletRequest request = attributes.getRequest(); String authHeader = request.getHeader("Authorization"); + logger.debug("璇诲彇鍒癆uthorization澶�: {}", authHeader); if (authHeader != null && authHeader.startsWith("Bearer ")) { - return authHeader.substring(7); + String token = authHeader.substring(7); + logger.debug("浠嶢uthorization澶存彁鍙栧埌Bearer token锛岄暱搴�: {}", token != null ? token.length() : 0); + return token; + } else { + logger.debug("Authorization澶翠笉瀛樺湪鎴栦笉浠earer寮�澶�"); } } } catch (Exception e) { -- Gitblit v1.8.0