|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.tuoheng.gateway.commons.CommonsConfig; |
|
|
import com.tuoheng.gateway.commons.CommonsConfig; |
|
|
|
|
|
import io.micrometer.core.instrument.util.StringUtils; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.http.*; |
|
|
import org.springframework.http.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String HHZ_MP = "tuoheng-hhz-mp"; |
|
|
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 |
|
|
* 获取 gateway 路由前缀,匹配url |
|
|
* @param clientId |
|
|
* @param clientId |
|
|
|
|
|
|
|
|
case HHZ_MP: |
|
|
case HHZ_MP: |
|
|
apiPath = "/hhz/api"; |
|
|
apiPath = "/hhz/api"; |
|
|
break; |
|
|
break; |
|
|
|
|
|
case FREEWAY_ADMIN: |
|
|
|
|
|
apiPath = "/freeway/admin"; |
|
|
|
|
|
break; |
|
|
|
|
|
case FREEWAY_MP: |
|
|
|
|
|
apiPath = "/freeway/miniprogram"; |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
return apiPath; |
|
|
return apiPath; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public static List<Integer> getRoleIdByApiUrlPermission(String clientId, String apiUrl, String token){ |
|
|
public static List<Integer> getRoleIdByApiUrlPermission(String clientId, String apiUrl, String token){ |
|
|
|
|
|
log.info("getRoleIdByApiUrlPermission - start"); |
|
|
List<Integer> resList = new ArrayList<>(); |
|
|
List<Integer> resList = new ArrayList<>(); |
|
|
|
|
|
String url = ""; |
|
|
if(clientId.equals(HHZ_ADMIN) || clientId.equals(HHZ_MP)){ |
|
|
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(); |
|
|
HttpHeaders resultRequestHeader = new HttpHeaders(); |
|
|
resultRequestHeader.add("Authorization", "Bearer " + token); |
|
|
resultRequestHeader.add("Authorization", "Bearer " + token); |
|
|
JSONObject json = new JSONObject(); |
|
|
JSONObject json = new JSONObject(); |
|
|
json.put("apiUrl", apiUrl); |
|
|
json.put("apiUrl", apiUrl); |
|
|
HttpEntity<JSONObject> entity = new HttpEntity<>(json, resultRequestHeader); |
|
|
HttpEntity<JSONObject> entity = new HttpEntity<>(json, resultRequestHeader); |
|
|
String result = new RestTemplate().postForObject(url, entity, String.class); |
|
|
String result = new RestTemplate().postForObject(url, entity, String.class); |
|
|
|
|
|
log.info("getRoleIdByApiUrlPermission - result:{}", result); |
|
|
JSONObject jsonObject = JSONObject.parseObject(result); |
|
|
JSONObject jsonObject = JSONObject.parseObject(result); |
|
|
Object obj = jsonObject.get("data"); |
|
|
Object obj = jsonObject.get("data"); |
|
|
if(!Objects.isNull(obj)){ |
|
|
if(!Objects.isNull(obj)){ |