From afbc6e46578c4f2c42cf213b354ab0a0b545fc07 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 11 七月 2023 09:43:57 +0800
Subject: [PATCH] 1

---
 src/main/java/com/moon/server/interceptor/ProxyFilter.java |   51 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/moon/server/interceptor/ProxyFilter.java b/src/main/java/com/moon/server/interceptor/ProxyFilter.java
index ff353bb..1e729db 100644
--- a/src/main/java/com/moon/server/interceptor/ProxyFilter.java
+++ b/src/main/java/com/moon/server/interceptor/ProxyFilter.java
@@ -4,10 +4,12 @@
 import com.moon.server.entity.all.HttpStatus;
 import com.moon.server.entity.all.ResponseMsg;
 import com.moon.server.entity.all.StaticData;
+import com.moon.server.entity.sys.ResEntity;
 import com.moon.server.entity.sys.ResLogEntity;
 import com.moon.server.entity.sys.TokenEntity;
 import com.moon.server.entity.sys.UserEntity;
 import com.moon.server.helper.AsyncHelper;
+import com.moon.server.helper.HttpHelper;
 import com.moon.server.helper.StringHelper;
 import com.moon.server.helper.WebHelper;
 import com.moon.server.service.all.PermsService;
@@ -66,11 +68,20 @@
             }
 
             int resId = getResId(req.getRequestURI(), LEN + token.length() + 1);
-            if (!check(req, res, ue, token, resId)) {
+            if (!check(req, res, ue, token)) {
+                return;
+            }
+
+            // 9.鑾峰彇璧勬簮瀹炰綋
+            ResEntity entity = getResEntity(ue, resId);
+            if (null == entity) {
+                WebHelper.writeStr2Page(res, ILLEGAL_RESOURCE);
                 return;
             }
 
             insertLog(req, ue, resId);
+            String url = getSourceUrl(req, entity);
+            proxy(req, res, url);
         } catch (Exception ex) {
             log.error(ex.getMessage(), ex);
         }
@@ -113,7 +124,7 @@
     /**
      * 妫�鏌�
      */
-    private boolean check(HttpServletRequest req, HttpServletResponse res, UserEntity ue, String token, int resId) {
+    private boolean check(HttpServletRequest req, HttpServletResponse res, UserEntity ue, String token) {
         // 4.鑾峰彇IP
         String ip = WebHelper.getIpAddress(req);
         if (StringHelper.isEmpty(ip)) {
@@ -123,11 +134,6 @@
         // 5.妫�鏌ラ粦鍚嶅崟
         if (!checkBlackList(ip, req)) {
             return WebHelper.writeStr2Page(res, AuthInterceptor.BLACK_LIST);
-        }
-
-        // 9.妫�鏌ヨ祫婧愭潈闄�
-        if (!checkResPerms(ue, resId)) {
-            return WebHelper.writeStr2Page(res, ILLEGAL_RESOURCE);
         }
 
         // 6.admin璺宠繃鏉冮檺妫�娴�
@@ -190,14 +196,21 @@
     /**
      * 妫�鏌ヨ祫婧愭潈闄�
      */
-    private boolean checkResPerms(UserEntity ue, int resId) {
+    private ResEntity getResEntity(UserEntity ue, int resId) {
         String uid = StaticData.ADMIN.equals(ue.getUid()) ? null : ue.getUid();
-        List<Integer> rs = permsService.selectResList(uid);
+        List<ResEntity> rs = permsService.selectResList(uid);
         if (null == rs || rs.isEmpty()) {
-            return false;
+            return null;
         }
 
-        return rs.contains(resId);
+        // List<ResEntity> list = rs.stream().filter(resEntity -> resEntity.getId() == resId).collect(Collectors.toList());
+        for (ResEntity entity : rs) {
+            if (resId == entity.getId()) {
+                return entity;
+            }
+        }
+
+        return null;
     }
 
     /**
@@ -248,4 +261,20 @@
                 return -1;
         }
     }
+
+    /**
+     * 鑾峰彇鍘熷Url
+     */
+    private String getSourceUrl(HttpServletRequest req, ResEntity entity) {
+
+        return "";
+    }
+
+    /**
+     * 浠g悊鏈嶅姟
+     */
+    private void proxy(HttpServletRequest request, HttpServletResponse response, String url) throws Exception {
+        HttpHelper httpHelper = new HttpHelper();
+        httpHelper.service(request, response, url, null);
+    }
 }

--
Gitblit v1.9.3