Bläddra i källkod

提取方法到单独类

andy 1 år sedan
förälder
incheckning
2d39132c36
1 ändrade filer med 3 tillägg och 102 borttagningar
  1. 3 102
      src/main/java/com/scbfkj/uni/api/LogAop.java

+ 3 - 102
src/main/java/com/scbfkj/uni/api/LogAop.java

@@ -1,6 +1,5 @@
 package com.scbfkj.uni.api;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.google.common.util.concurrent.RateLimiter;
 import com.scbfkj.uni.library.DataAliasGetUtil;
 import com.scbfkj.uni.library.DataFormatUtil;
@@ -8,8 +7,8 @@ import com.scbfkj.uni.library.RequestUtil;
 import com.scbfkj.uni.library.UniReturnUtil;
 import com.scbfkj.uni.process.DataBase;
 import com.scbfkj.uni.service.LoggerService;
-import com.scbfkj.uni.service.SecurityService;
 import com.scbfkj.uni.system.Config;
+import com.scbfkj.uni.utils.Util;
 import jakarta.annotation.Resource;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
@@ -28,7 +27,7 @@ public class LogAop {
     private static final Map<String, RateLimiter> rateLimiterMap = new HashMap<>();
     private static final DataBase DATA_BASE = new DataBase();
     @Resource
-    private SecurityService securityService;
+    private Util util;
 
     @Around(value = "within(com.scbfkj.uni.api.*Api)")
     public ResponseEntity<Map<String, Object>> invokeAround(ProceedingJoinPoint joinPoint) {
@@ -88,7 +87,7 @@ public class LogAop {
                 return ResponseEntity.ok(UniReturnUtil.fail(message));
             }
 
-            addFilter(body, serviceid);
+            util.addFilter(body, serviceid,uri,true);
 
             ResponseEntity<Map<String, Object>> responseEntity = (ResponseEntity<Map<String, Object>>) joinPoint.proceed(args);
             if (!responseEntity.getStatusCode().is2xxSuccessful()) {
@@ -161,104 +160,6 @@ public class LogAop {
         return ResponseEntity.ok(returnData);
     }
 
-    private void addFilter(Map<String, Object> body, Optional<String> serviceid) throws Exception {
-
-
-        List<Map<String, Object>> permission = (List<Map<String, Object>>) securityService.permission().get("returnData");
-
-        String uri = RequestUtil.getUri();
-
-        checkToken(uri);
-
-        if (Objects.nonNull(body) && uri.startsWith("/openApi")) {
-
-            Map<String, Object> userInfo = RequestUtil.getUserInfo();
-
-            if (Objects.nonNull(userInfo)) {
-                Object usergroupid = userInfo.get("usergroupid");
-
-//                超级管理员
-                if (Objects.nonNull(usergroupid) && Objects.equals("0", usergroupid.toString())) {
-                    body.put("filterColumns", Collections.singletonList("*"));
-                } else {
-                    if (Objects.nonNull(permission)) {
-                        Optional finalServiceid = serviceid;
-                        Optional<Map<String, Object>> any = permission.stream().filter(it -> Objects.equals(it.get("serviceid"), finalServiceid.get())).filter(it -> Objects.nonNull(it.get("filterset"))).findAny();
-                        if (any.isPresent()) {
-                            Map<String, Object> data = any.get();
-                            Object filterset = data.get("filterset");
-                            if (Objects.nonNull(filterset) && !filterset.toString().trim().isEmpty()) {
-                                try {
-                                    List list = DataFormatUtil.getObjectMapper().readValue(filterset.toString(), List.class);
-                                    body.put("filterLines", list);
-                                } catch (JsonProcessingException e) {
-                                    if (Config.isDebug()) {
-                                        e.printStackTrace();
-                                        throw e;
-                                    }
-                                }
-                            } else {
-                                body.put("filterLines", new ArrayList<>());
-                            }
-                        }
-                        List<String> columns = DATA_BASE.query(Config.getSecurityConnectionStr(), "select pagecode from pageconfiguration where pagetype='column' and pageconfiguration.pageconfigurationid  in (select userpermissions.pageconfigurationid from userpermissions where serviceid = ? and userid =?)", serviceid.get(), RequestUtil.getUserId()).stream().map(it -> it.get("pagecode").toString()).toList();
-                        if (!columns.isEmpty()) {
-                            body.put("filterColumns", columns);
-                        }
-                    }
-                }
-            }
-//                    不需要登录也没有设置权限的默认添加一个所有列权限
-
-            if (!Config.isSecurityEnable() && body != null && !body.containsKey("filterColumns")) {
-                body.put("filterColumns", Collections.singletonList("*"));
-            }
-
-        }
-    }
-
-    private void checkToken(String uri) throws Exception {
-        if (Config.isSecurityEnable()) {
-            List<Map<String, Object>> apiInfos = DATA_BASE.query(Config.getSecurityConnectionStr(), "select * from apiinfo");
-
-
-            Optional<Map<String, Object>> requestpath = apiInfos.stream().filter(it -> {
-                Object o = it.get("requestpath");
-                return Objects.equals(o, uri);
-            }).findAny();
-            if (requestpath.isPresent()) {
-                Map<String, Object> stringObjectMap = requestpath.get();
-                Object o = stringObjectMap.get("securitykey");
-                if (Objects.nonNull(o)) {
-                    String[] securityCheck = o.toString().split(",");
-                    for (String s : securityCheck) {
-                        if (Objects.equals(s, "token")) {
-                            String appToken = RequestUtil.getAppToken();
-                            if (Objects.isNull(appToken)) {
-                                throw new RuntimeException("没有找到token");
-                            }
-                            try {
-//                                    校验apptoken 成功表示验证通过
-                                RequestUtil.getApplication();
-                            } catch (Exception e) {
-                                throw new RuntimeException("token验证失败");
-                            }
-                        }
-                        if (Objects.equals("usertoken", s)) {
-                            String userToken = RequestUtil.getUserToken();
-                            if (Objects.isNull(userToken)) {
-                                throw new RuntimeException("没有找到 usertoken");
-                            }
-                            Map<String, Object> checkResult = securityService.checkUserToken(userToken);
-                            if (!checkResult.get("code").equals("0")) {
-                                throw new RuntimeException(checkResult.getOrDefault("message", "").toString());
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
 
     private String checkratelimitrule(String uri) throws Exception {