chore: sync develop branch

This commit is contained in:
hongqiaowei
2020-12-08 11:46:11 +08:00
parent 1dd3119e5f
commit 45ac89f243

View File

@@ -24,9 +24,11 @@ import java.util.Map;
import javax.annotation.Resource;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
@@ -52,6 +54,7 @@ import we.fizz.ConfigLoader;
import we.fizz.Pipeline;
import we.fizz.input.Input;
import we.flume.clients.log4j2appender.LogService;
import we.plugin.auth.ApiConfig;
import we.util.Constants;
import we.util.MapUtil;
import we.util.WebUtils;
@@ -69,18 +72,24 @@ public class FizzGatewayFilter implements WebFilter {
@Resource
private ConfigLoader configLoader;
@NacosValue(value = "${need-auth:false}", autoRefreshed = true)
@Value("${need-auth:false}")
private boolean needAuth;
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
String serviceId = WebUtils.getServiceId(exchange);
if (serviceId == null || (ApiConfig.Type.SERVICE_ARRANGE != WebUtils.getApiConfigType(exchange) && needAuth) ) {
return chain.filter(exchange);
}
long start = System.currentTimeMillis();
ServerHttpRequest request = exchange.getRequest();
ServerHttpResponse serverHttpResponse = exchange.getResponse();
if (WebUtils.getServiceId(exchange) == null) {
return chain.filter(exchange);
}
String path = WebUtils.getPathPrefix(exchange) + WebUtils.getServiceId(exchange) + WebUtils.getReqPath(exchange);
String path = WebUtils.getPathPrefix(exchange) + serviceId + WebUtils.getReqPath(exchange);
String method = request.getMethodValue();
AggregateResource aggregateResource = configLoader.matchAggregateResource(method, path);
if (aggregateResource == null) {