Commit 43eb8f06 authored by 向怀芳's avatar 向怀芳 🎱

1. IP白名单04

parent 5db3bca0
...@@ -20,5 +20,6 @@ import java.util.List; ...@@ -20,5 +20,6 @@ import java.util.List;
@ConditionalOnExpression("!'${whiteip}'.isEmpty()") @ConditionalOnExpression("!'${whiteip}'.isEmpty()")
@ConfigurationProperties(prefix = "whiteip") @ConfigurationProperties(prefix = "whiteip")
public class WhitIPConfig { public class WhitIPConfig {
private Boolean limitFlag;
private List<String> whites = new ArrayList<>(); private List<String> whites = new ArrayList<>();
} }
...@@ -67,7 +67,7 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered { ...@@ -67,7 +67,7 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered {
String ip = WebUtils.getIP(request); String ip = WebUtils.getIP(request);
log.error("RemoteAddress ===================> {}", request.getRemoteAddress()); log.error("RemoteAddress ===================> {}", request.getRemoteAddress());
try { try {
if (!IPStrUtil.matches(ip, whitIPConfig.getWhites())) { if (whitIPConfig.getLimitFlag() && !IPStrUtil.matches(ip, whitIPConfig.getWhites())) {
ServerHttpResponse response = exchange.getResponse(); ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED); response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED);
response.getHeaders().set("Content-type", "application/json; charset=utf-8"); response.getHeaders().set("Content-type", "application/json; charset=utf-8");
......
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