From ae3349d2ff53767b5bc9cb30e1bf7e15f9e814ee Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期五, 03 十月 2025 20:45:44 +0800
Subject: [PATCH] 清理测试代码和调试文件

---
 backend/src/main/java/com/rongyichuang/auth/filter/JwtAuthenticationFilter.java |   44 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/backend/src/main/java/com/rongyichuang/auth/filter/JwtAuthenticationFilter.java b/backend/src/main/java/com/rongyichuang/auth/filter/JwtAuthenticationFilter.java
index 4fef1a3..96e6413 100644
--- a/backend/src/main/java/com/rongyichuang/auth/filter/JwtAuthenticationFilter.java
+++ b/backend/src/main/java/com/rongyichuang/auth/filter/JwtAuthenticationFilter.java
@@ -36,12 +36,52 @@
 
     @Autowired
     private UserRepository userRepository;
+    
+    /**
+     * 鍒ゆ柇鏄惁搴旇璺宠繃JWT璁よ瘉
+     */
+    private boolean shouldSkipAuthentication(String requestURI) {
+        // 杩欎簺璺緞涓嶉渶瑕丣WT璁よ瘉锛堝凡鍘绘帀context path锛�
+        String[] skipPaths = {
+            "/auth/",
+            "/actuator/",
+            "/test/",
+            "/cleanup/",
+            "/upload/",
+            "/graphql",
+            "/graphiql"
+        };
+        
+        for (String path : skipPaths) {
+            if (requestURI.startsWith(path)) {
+                return true;
+            }
+        }
+        
+        return false;
+    }
 
     @Override
     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, 
                                     FilterChain filterChain) throws ServletException, IOException {
-        System.out.println("=== JWT杩囨护鍣ㄨ璋冪敤 === URI: " + request.getRequestURI());
-        logger.debug("JWT杩囨护鍣ㄥ紑濮嬪鐞嗚姹�: {}", request.getRequestURI());
+        String requestURI = request.getRequestURI();
+        String contextPath = request.getContextPath();
+        
+        // 鍘绘帀context path锛屼笌Spring Security鐨勮涓轰繚鎸佷竴鑷�
+        String pathWithoutContext = requestURI;
+        if (contextPath != null && !contextPath.isEmpty() && requestURI.startsWith(contextPath)) {
+            pathWithoutContext = requestURI.substring(contextPath.length());
+        }
+        
+        System.out.println("=== JWT杩囨护鍣ㄨ璋冪敤 === 鍘熷URI: " + requestURI + ", 鍘绘帀context path鍚�: " + pathWithoutContext);
+        logger.debug("JWT杩囨护鍣ㄥ紑濮嬪鐞嗚姹�: {}", pathWithoutContext);
+        
+        // 璺宠繃涓嶉渶瑕佽璇佺殑璺緞
+        if (shouldSkipAuthentication(pathWithoutContext)) {
+            logger.debug("璺宠繃JWT璁よ瘉锛岃矾寰�: {}", pathWithoutContext);
+            filterChain.doFilter(request, response);
+            return;
+        }
         
         String authHeader = request.getHeader("Authorization");
         String token = null;

--
Gitblit v1.8.0