|
@@ -1,13 +1,13 @@
|
|
|
package com.diagbot.filter;
|
|
|
|
|
|
-import com.diagbot.client.DiagbotmanServiceClient;
|
|
|
+//import com.diagbot.client.DiagbotmanServiceClient;
|
|
|
+
|
|
|
+import com.diagbot.biz.log.entity.SysLog;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
-import com.diagbot.entity.HasPermissionDTO;
|
|
|
import com.diagbot.entity.ServiceFilter;
|
|
|
import com.diagbot.entity.ServiceToken;
|
|
|
import com.diagbot.enums.SysTypeEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
-import com.diagbot.biz.log.entity.SysLog;
|
|
|
import com.diagbot.rabbit.MySender;
|
|
|
import com.diagbot.util.EnDecodeUtil;
|
|
|
import com.diagbot.util.GsonUtil;
|
|
@@ -22,6 +22,7 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.core.io.buffer.DataBuffer;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
@@ -31,9 +32,12 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.LinkedHashSet;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+//import com.diagbot.entity.HasPermissionDTO;
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 全局过滤器
|
|
|
* @author: gaodm
|
|
@@ -51,10 +55,12 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
@Value("${lantone.product}")
|
|
|
private String lantonePrduct;
|
|
|
|
|
|
- @Autowired
|
|
|
- DiagbotmanServiceClient diagbotmanServiceClient;
|
|
|
+ // @Autowired
|
|
|
+ // DiagbotmanServiceClient diagbotmanServiceClient;
|
|
|
@Autowired
|
|
|
private MySender mySender;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -121,7 +127,8 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
st.setAppkey(appkey);
|
|
|
st.setSecret(secret);
|
|
|
st.setProductId(productId);
|
|
|
- RespDTO<HasPermissionDTO> res = diagbotmanServiceClient.hasPermission(st);
|
|
|
+ // RespDTO<HasPermissionDTO> res = diagbotmanServiceClient.hasPermission(st);
|
|
|
+ RespDTO<LinkedHashMap> res = hasPermission(st);
|
|
|
if (res == null || !RespDTO.TRUE_CODE.equals(res.code)) {
|
|
|
return getVoidMono(serverWebExchange, res);
|
|
|
}
|
|
@@ -137,14 +144,15 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
sysLog.setOperation(GsonUtil.toJson(serviceFilter));
|
|
|
sysLog.setParams(requestUri);
|
|
|
sysLog.setSysType(SysTypeEnum.APPKEY.getKey());
|
|
|
- sysLog.setUsername(res.data.getUserId());
|
|
|
+ LinkedHashMap<String, String> map = res.data;
|
|
|
+ sysLog.setUsername(map.get("userId"));
|
|
|
mySender.outputLogSend(sysLog);
|
|
|
|
|
|
}
|
|
|
|
|
|
ServerHttpRequest.Builder builder = serverWebExchange.getRequest().mutate();
|
|
|
-// builder.header("Authorization", "Authorization Bearer token");
|
|
|
-// gatewayFilterChain.filter(serverWebExchange.mutate().request(builder.build()).build());
|
|
|
+ // builder.header("Authorization", "Authorization Bearer token");
|
|
|
+ // gatewayFilterChain.filter(serverWebExchange.mutate().request(builder.build()).build());
|
|
|
return gatewayFilterChain.filter(serverWebExchange.mutate().request(builder.build()).build());
|
|
|
}
|
|
|
|
|
@@ -176,4 +184,22 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
}
|
|
|
return serviceFilters;
|
|
|
}
|
|
|
+
|
|
|
+ public RespDTO<LinkedHashMap> hasPermission(ServiceToken st) {
|
|
|
+ try {
|
|
|
+ RespDTO<LinkedHashMap> res
|
|
|
+ = restTemplate.postForObject("http://diagbotman-service/serviceToken/hasPermission", st, RespDTO.class);
|
|
|
+ return res;
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return hasPermissionFallback(st);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public RespDTO hasPermissionFallback(ServiceToken st) {
|
|
|
+ log.error("【hystrix】调用{}异常", "hasPermisson");
|
|
|
+ RespDTO respDTO = new RespDTO();
|
|
|
+ respDTO.msg = CommonErrorCode.RPC_ERROR.getMsg();
|
|
|
+ respDTO.code = CommonErrorCode.RPC_ERROR.getCode();
|
|
|
+ return respDTO;
|
|
|
+ }
|
|
|
}
|