|
@@ -1,13 +1,13 @@
|
|
|
package com.diagbot.filter;
|
|
|
|
|
|
import com.diagbot.client.DiagbotmanServiceClient;
|
|
|
-import com.diagbot.client.UserServiceClient;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.entity.HasPermissionDTO;
|
|
|
import com.diagbot.entity.ServiceToken;
|
|
|
-import com.diagbot.entity.Token;
|
|
|
-import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.entity.SysLog;
|
|
|
+import com.diagbot.enums.SysTypeEnum;
|
|
|
+import com.diagbot.rabbit.MySender;
|
|
|
import com.diagbot.util.GsonUtil;
|
|
|
-import com.diagbot.util.StringUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -25,6 +25,7 @@ import reactor.core.publisher.Mono;
|
|
|
|
|
|
import java.net.URI;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.LinkedHashSet;
|
|
@@ -47,10 +48,10 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
@Value("${lantone.product}")
|
|
|
private String lantonePrduct;
|
|
|
|
|
|
- @Autowired
|
|
|
- UserServiceClient userServiceClient;
|
|
|
@Autowired
|
|
|
DiagbotmanServiceClient diagbotmanServiceClient;
|
|
|
+ @Autowired
|
|
|
+ private MySender mySender;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -73,23 +74,6 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
log.info("APIURL:{}", requestUri);
|
|
|
log.info("SERVICENAME:{}", serviceName);
|
|
|
|
|
|
- //验证token有效性
|
|
|
- String tokenStr = request.getHeaders().getFirst("Authorization");
|
|
|
- if(StringUtil.isNotEmpty(tokenStr)) {
|
|
|
- Token token = new Token();
|
|
|
- tokenStr = tokenStr.replaceFirst("Bearer ", "");
|
|
|
- token.setToken(tokenStr);
|
|
|
- RespDTO<Boolean> res = userServiceClient.verifyToken(token);
|
|
|
- if (res == null || !RespDTO.TRUE_CODE.equals(res.code)) {
|
|
|
- return getVoidMono(serverWebExchange, res);
|
|
|
- }
|
|
|
- if(!res.data) {
|
|
|
- res.code = CommonErrorCode.TOKEN_PAST.getCode();
|
|
|
- res.msg = CommonErrorCode.TOKEN_PAST.getMsg();
|
|
|
- return getVoidMono(serverWebExchange, res);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// if(!IS_GENERATE) {
|
|
|
// RespDTO<List<ServiceFilter>> filter = diagbotmanServiceClient.getAll();
|
|
|
// if (filter != null){
|
|
@@ -103,6 +87,9 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Map<String, Long> serviceFilters = this.dealServiceFilter();
|
|
|
if (serviceFilters.get(serviceName) != null) {
|
|
|
String appkey = request.getHeaders().getFirst("appkey");
|
|
@@ -113,10 +100,22 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
st.setAppkey(appkey);
|
|
|
st.setSecret(secret);
|
|
|
st.setProductId(productId);
|
|
|
- RespDTO<Boolean> res = diagbotmanServiceClient.hasPermission(st);
|
|
|
+ RespDTO<HasPermissionDTO> res = diagbotmanServiceClient.hasPermission(st);
|
|
|
if (res == null || !RespDTO.TRUE_CODE.equals(res.code)) {
|
|
|
return getVoidMono(serverWebExchange, res);
|
|
|
}
|
|
|
+
|
|
|
+ //记录日志
|
|
|
+ SysLog sysLog = new SysLog();
|
|
|
+ sysLog.setGmtCreate(new Date());
|
|
|
+ sysLog.setIp(request.getRemoteAddress().toString());
|
|
|
+ sysLog.setMethod(requestUri);
|
|
|
+ sysLog.setOperation(serviceName);
|
|
|
+ sysLog.setParams(requestUri);
|
|
|
+ sysLog.setSysType(SysTypeEnum.APPKEY.getKey());
|
|
|
+ sysLog.setUsername(res.data.getUserId());
|
|
|
+ mySender.outputLogSend(sysLog);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
ServerHttpRequest.Builder builder = serverWebExchange.getRequest().mutate();
|