Commit 934cb13c authored by gaozhaochen's avatar gaozhaochen

fix: 生产环境无白名单配置时,全局过滤器白名单标志获取错误问题

parent 25684165
package cn.sh.stc.sict.cloud.common.gateway.filter;
import cn.hutool.json.JSONUtil;
import cn.sh.stc.sict.cloud.common.core.constant.Constant;
import cn.sh.stc.sict.cloud.common.core.constant.SecurityConstants;
import cn.sh.stc.sict.cloud.common.core.util.R;
......@@ -62,12 +63,12 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered {
httpHeaders.remove(SecurityConstants.FROM);
})
.build();
log.error("这里没问题");
// IP白名单
String ip = WebUtils.getIP(request);
// log.error("RemoteAddress = {}, ip = {}", request.getRemoteAddress(), ip);
try {
if (whitIPConfig.getLimitFlag() && !IPStrUtil.matches(ip, whitIPConfig.getWhites())) {
if (whitIPConfig.getLimitFlag() != null && whitIPConfig.getLimitFlag() && !IPStrUtil.matches(ip, whitIPConfig.getWhites())) {
ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED);
response.getHeaders().set("Content-type", "application/json; charset=utf-8");
......@@ -90,6 +91,7 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered {
log.error("对象输出异常", e1);
}
}
log.error("这里没问题2");
// 2. 重写StripPrefix
addOriginalRequestUrl(exchange, request.getURI());
String rawPath = request.getURI().getRawPath();
......@@ -99,7 +101,7 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered {
.path(newPath)
.build();
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, newRequest.getURI());
log.error("这里没问题3");
return chain.filter(exchange.mutate()
.request(newRequest.mutate()
.build()).build());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment