| | |
| | | import java.util.regex.Pattern;
|
| | | import org.springframework.cloud.gateway.filter.GatewayFilter;
|
| | | import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
| | | import org.springframework.http.server.reactive.ServerHttpResponse;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.ruoyi.common.core.web.domain.AjaxResult;
|
| | | import reactor.core.publisher.Mono;
|
| | | import com.ruoyi.common.core.utils.ServletUtils;
|
| | |
|
| | | /**
|
| | | * 黑名单过滤器
|
| | |
| | | String url = exchange.getRequest().getURI().getPath();
|
| | | if (config.matchBlacklist(url))
|
| | | {
|
| | | ServerHttpResponse response = exchange.getResponse();
|
| | | response.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
|
| | | return exchange.getResponse().writeWith(
|
| | | Mono.just(response.bufferFactory().wrap(JSON.toJSONBytes(AjaxResult.error("请求地址不允许访问")))));
|
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求地址不允许访问");
|
| | | }
|
| | |
|
| | | return chain.filter(exchange);
|
| | |
| | |
|
| | | public boolean matchBlacklist(String url)
|
| | | {
|
| | | return blacklistUrlPattern.isEmpty() ? false : blacklistUrlPattern.stream().filter(p -> p.matcher(url).find()).findAny().isPresent();
|
| | | return !blacklistUrlPattern.isEmpty() && blacklistUrlPattern.stream().anyMatch(p -> p.matcher(url).find());
|
| | | }
|
| | |
|
| | | public List<String> getBlacklistUrl()
|