فهرست منبع

前端调用 重新加载账套的接口,直接调用网关服务器的接口,不在从应用服务器中转。如果网关服务器设置了ssl,那么从应用服务器中转会出现 ssl
调用报错的问题。

yangzhijie1488@163.com 3 سال پیش
والد
کامیت
fbb014d872

+ 2 - 1
src/main/java/com/leanwo/gateway/GlobalAccountFilter.java

@@ -59,8 +59,9 @@ public class GlobalAccountFilter implements GlobalFilter, Ordered{
         String domainName = url.substring(0, endIndex);
         logger.debug("未截取前域名:" + domainName);
         domainName = domainName.replace("http://", "").replace("https://", "");
-        logger.debug("域名:" + domainName);
+        logger.debug("获取的域名:" + domainName);
         Long accountId = accountManagementService.getAccountIdByDomainName(domainName);
+        logger.debug("获取的AccountId:" + accountId);
     	
     	request.mutate().header("account", accountId.toString()).build();
     	//代表放行请求

+ 17 - 2
src/main/java/com/leanwo/gateway/rest/AccountManagementResource.java

@@ -4,6 +4,8 @@ import javax.inject.Inject;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.http.server.reactive.ServerHttpResponse;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -11,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import com.leanwo.gateway.dto.BaseResponse;
 import com.leanwo.gateway.service.AccountManagementService;
+import com.leanwo.gateway.service.SystemAdminService;
 
 
 
@@ -20,7 +23,7 @@ import com.leanwo.gateway.service.AccountManagementService;
  */
 
 @RestController
-@RequestMapping("/AccountManagementResource")
+@RequestMapping("/gateway-api/AccountManagementResource")
 public class AccountManagementResource {
 
     private static Logger logger = LoggerFactory.getLogger(AccountManagementResource.class);
@@ -28,16 +31,28 @@ public class AccountManagementResource {
     @Inject
     private AccountManagementService accountManagementService; 
     
+    @Inject
+    private SystemAdminService systemAdminService;
     
     /**
      * 重新加载账套
      * @param accountId
      * @return
+     * @author YangZhiJie 20220826
      */
     @RequestMapping(value = "/reloadAccountManagement", method = RequestMethod.GET)
     @ResponseBody
-    public BaseResponse reloadAccountManagement() {
+    public BaseResponse reloadAccountManagement(ServerHttpRequest httpServletRequest, ServerHttpResponse httpServletResponse) {
+    	boolean isSystemAdmin = systemAdminService.isSystemAdmin(httpServletRequest);
+    	
         BaseResponse baseResponse = new BaseResponse();
+		if (isSystemAdmin == false) {
+			logger.info("Cookies中不存在SystemAdmin参数。");
+			baseResponse.setErrorCode(2);
+			baseResponse.setErrorMessage("Cookies中不存在SystemAdmin参数。");
+			return baseResponse;
+		}
+    	
         try {
             accountManagementService.loadAccountManagement(true);
             baseResponse.setErrorCode(0);

+ 36 - 0
src/main/java/com/leanwo/gateway/service/SystemAdminService.java

@@ -0,0 +1,36 @@
+package com.leanwo.gateway.service;
+
+import org.springframework.http.HttpCookie;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.stereotype.Service;
+import org.springframework.util.MultiValueMap;
+
+import com.leanwo.gateway.dto.BaseResponse;
+
+/**
+ * 系统管理员服务
+ * @author YangZhiJie 20220826
+ *
+ */
+@Service
+public class SystemAdminService {
+
+	/**
+	 * 是否是系统管理员
+	 * @param httpServletRequest
+	 * @return
+	 */
+	public boolean isSystemAdmin(ServerHttpRequest httpServletRequest) {
+		String systemAdminValue = null;
+    	MultiValueMap<String, HttpCookie> cookies = httpServletRequest.getCookies();
+    	if(cookies != null && cookies.containsKey("SystemAdmin")) {
+    		HttpCookie systemAdminHttpCookie = cookies.getFirst("SystemAdmin");
+    		systemAdminValue = systemAdminHttpCookie.getValue();
+    	}
+
+		if (systemAdminValue == null || !systemAdminValue.equalsIgnoreCase("true")) {
+			return false;
+		}
+		return true;
+	}
+}