Sfoglia il codice sorgente

Merge branch 'develop' of gitadmin/tuoheng_gateway into master

pull/49/head
gitadmin 1 anno fa
parent
commit
65f34e0328
3 ha cambiato i file con 20 aggiunte e 3 eliminazioni
  1. +1
    -1
      src/main/java/com/tuoheng/gateway/config/GatewayFilterConfig.java
  2. +18
    -1
      src/main/java/com/tuoheng/gateway/utils/GatewayUrlPathUtil.java
  3. +1
    -1
      src/main/resources/application-test.yml

+ 1
- 1
src/main/java/com/tuoheng/gateway/config/GatewayFilterConfig.java Vedi File

@@ -62,7 +62,7 @@ public class GatewayFilterConfig implements GlobalFilter, Ordered {
if(!StringUtils.isEmpty(clientId)){
log.info("clientId is :{}", clientId);
String requestUrl = exchange.getRequest().getPath().value();
log.info("requestUrl is :{}", clientId);
log.info("requestUrl is :{}", requestUrl);
//去除gateway path 前缀
String apiUrl = requestUrl.replace(GatewayUrlPathUtil.getPathByClientId(clientId),"");
log.info("apiUrl is :{}", apiUrl);

+ 18
- 1
src/main/java/com/tuoheng/gateway/utils/GatewayUrlPathUtil.java Vedi File

@@ -2,6 +2,7 @@ package com.tuoheng.gateway.utils;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.gateway.commons.CommonsConfig;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
@@ -25,6 +26,10 @@ public class GatewayUrlPathUtil {

private static final String HHZ_MP = "tuoheng-hhz-mp";

private static final String FREEWAY_ADMIN = "tuoheng-freeway-admin";

private static final String FREEWAY_MP = "tuoheng-freeway-miniprogram";

/**
* 获取 gateway 路由前缀,匹配url
* @param clientId
@@ -39,6 +44,12 @@ public class GatewayUrlPathUtil {
case HHZ_MP:
apiPath = "/hhz/api";
break;
case FREEWAY_ADMIN:
apiPath = "/freeway/admin";
break;
case FREEWAY_MP:
apiPath = "/freeway/miniprogram";
break;
}
return apiPath;
}
@@ -48,15 +59,21 @@ public class GatewayUrlPathUtil {
* @return
*/
public static List<Integer> getRoleIdByApiUrlPermission(String clientId, String apiUrl, String token){
log.info("getRoleIdByApiUrlPermission - start");
List<Integer> resList = new ArrayList<>();
String url = "";
if(clientId.equals(HHZ_ADMIN) || clientId.equals(HHZ_MP)){
String url = CommonsConfig.hhzPermissionUrl;
url = CommonsConfig.hhzPermissionUrl;
}
if(StringUtils.isNotBlank(url)){
log.info("getRoleIdByApiUrlPermission - url:{}", url);
HttpHeaders resultRequestHeader = new HttpHeaders();
resultRequestHeader.add("Authorization", "Bearer " + token);
JSONObject json = new JSONObject();
json.put("apiUrl", apiUrl);
HttpEntity<JSONObject> entity = new HttpEntity<>(json, resultRequestHeader);
String result = new RestTemplate().postForObject(url, entity, String.class);
log.info("getRoleIdByApiUrlPermission - result:{}", result);
JSONObject jsonObject = JSONObject.parseObject(result);
Object obj = jsonObject.get("data");
if(!Objects.isNull(obj)){

+ 1
- 1
src/main/resources/application-test.yml Vedi File

@@ -186,4 +186,4 @@ security:

# 获取 apiUrl 可访问的 roleIdList
tuoheng:
hhz-admin-perUrl: http://172.15.1.21:9055/permission/getRoleIdList
hhz-admin-perUrl: https://hhz-test.t-aaron.com/hhz/admin/permission/getRoleIdList

Loading…
Annulla
Salva