diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index a449b54..7d8fa55 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -12,10 +12,10 @@ com.fizzgate fizz-bootstrap - 2.0.0-beta2 + 2.0.0-beta3 - 2.0.0-beta2 + 2.0.0-beta3 1.8 5.2.14.RELEASE Dysprosium-SR19 diff --git a/fizz-common/pom.xml b/fizz-common/pom.xml index e0f4818..cfa4775 100644 --- a/fizz-common/pom.xml +++ b/fizz-common/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.0.0-beta2 + 2.0.0-beta3 ../pom.xml 4.0.0 diff --git a/fizz-core/pom.xml b/fizz-core/pom.xml index 286766a..bfd7bac 100644 --- a/fizz-core/pom.xml +++ b/fizz-core/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.0.0-beta2 + 2.0.0-beta3 ../pom.xml 4.0.0 diff --git a/fizz-core/src/main/java/we/config/SystemConfig.java b/fizz-core/src/main/java/we/config/SystemConfig.java index ec0d3ea..b0d1deb 100644 --- a/fizz-core/src/main/java/we/config/SystemConfig.java +++ b/fizz-core/src/main/java/we/config/SystemConfig.java @@ -44,19 +44,23 @@ public class SystemConfig { private static final Logger log = LoggerFactory.getLogger(SystemConfig.class); - public static final String DEFAULT_GATEWAY_PREFIX = "/proxy"; + public static final String DEFAULT_GATEWAY_PREFIX = "/proxy"; - public static final String DEFAULT_GATEWAY_TEST_PREFIX = "/_proxytest"; + public static final String DEFAULT_GATEWAY_TEST_PREFIX = "/_proxytest"; - public String gatewayPrefix = DEFAULT_GATEWAY_PREFIX; + public static final String DEFAULT_GATEWAY_TEST_PREFIX0 = "/_proxytest/"; - public List appHeaders = Stream.of("fizz-appid").collect(Collectors.toList()); + public String gatewayPrefix = DEFAULT_GATEWAY_PREFIX; - public List signHeaders = Stream.of("fizz-sign") .collect(Collectors.toList()); + public List appHeaders = Stream.of("fizz-appid").collect(Collectors.toList()); - public List timestampHeaders = Stream.of("fizz-ts") .collect(Collectors.toList()); + public List signHeaders = Stream.of("fizz-sign") .collect(Collectors.toList()); + + public List timestampHeaders = Stream.of("fizz-ts") .collect(Collectors.toList()); - public List proxySetHeaders = new ArrayList<>(); + public List proxySetHeaders = new ArrayList<>(); + + public boolean aggregateTestAuth = false; @NacosValue(value = "${gateway.aggr.proxy_set_headers:}", autoRefreshed = true) @@ -112,6 +116,13 @@ public class SystemConfig { log.info("timestamp headers: " + timestampHeaders); } + @NacosValue(value = "${aggregate-test-auth:false}", autoRefreshed = true) + @Value( "${aggregate-test-auth:false}" ) + public void setAggregateTestAuth(boolean b) { + aggregateTestAuth = b; + log.info("aggregate test auth: " + aggregateTestAuth); + } + // TODO: below to X @Value("${log.response-body:false}") diff --git a/fizz-core/src/main/java/we/filter/AggregateFilter.java b/fizz-core/src/main/java/we/filter/AggregateFilter.java index af07fdc..7b70708 100644 --- a/fizz-core/src/main/java/we/filter/AggregateFilter.java +++ b/fizz-core/src/main/java/we/filter/AggregateFilter.java @@ -17,17 +17,9 @@ package we.filter; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.annotation.Resource; - +import com.alibaba.fastjson.JSON; import com.alibaba.nacos.api.config.annotation.NacosValue; +import io.netty.buffer.UnpooledByteBufAllocator; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,13 +36,10 @@ import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; - -import com.alibaba.fastjson.JSON; - -import io.netty.buffer.UnpooledByteBufAllocator; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; +import we.config.SystemConfig; import we.constants.CommonConstants; import we.fizz.AggregateResource; import we.fizz.AggregateResult; @@ -63,6 +52,14 @@ import we.util.Constants; import we.util.MapUtil; import we.util.WebUtils; +import javax.annotation.Resource; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + /** * @author Francis Dong */ @@ -81,26 +78,44 @@ public class AggregateFilter implements WebFilter { @Value("${need-auth:true}") private boolean needAuth; + @Resource + private SystemConfig systemConfig; + @Override public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { String serviceId = WebUtils.getBackendService(exchange); - if ( serviceId == null || (ApiConfig.Type.SERVICE_AGGREGATE != WebUtils.getApiConfigType(exchange) && needAuth) ) { + if (serviceId == null) { return chain.filter(exchange); + } else { + byte act = WebUtils.getApiConfigType(exchange); + if (act == ApiConfig.Type.UNDEFINED) { + String p = exchange.getRequest().getPath().value(); + if (StringUtils.startsWith(p, SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX0)) { + if (systemConfig.aggregateTestAuth) { + return chain.filter(exchange); + } + } else if (needAuth) { + return chain.filter(exchange); + } + } else if (act != ApiConfig.Type.SERVICE_AGGREGATE) { + return chain.filter(exchange); + } } long start = System.currentTimeMillis(); ServerHttpRequest request = exchange.getRequest(); ServerHttpResponse serverHttpResponse = exchange.getResponse(); - String path = WebUtils.getClientReqPathPrefix(exchange) + serviceId + WebUtils.getBackendPath(exchange); + String clientReqPathPrefix = WebUtils.getClientReqPathPrefix(exchange); + String path = clientReqPathPrefix + serviceId + WebUtils.getBackendPath(exchange); String method = request.getMethodValue(); if (HttpMethod.HEAD.matches(method.toUpperCase())) { method = HttpMethod.GET.name(); } AggregateResource aggregateResource = configLoader.matchAggregateResource(method, path); if (aggregateResource == null) { - if (WebUtils.getApiConfigType(exchange) == ApiConfig.Type.SERVICE_AGGREGATE) { + if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX0.equals(clientReqPathPrefix) || WebUtils.getApiConfigType(exchange) == ApiConfig.Type.SERVICE_AGGREGATE) { return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "no aggregate resource: " + path); } else { return chain.filter(exchange); diff --git a/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java b/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java index c73b820..7df0d68 100644 --- a/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java +++ b/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java @@ -199,12 +199,8 @@ public class ApiConfigService { YES (null), - NO_SERVICE_CONFIG ("no service config"), - ROUTE_NOT_FOUND ("route not found"), - GATEWAY_GROUP_CANT_PROXY_API ("gateway group cant proxy api"), - APP_NOT_IN_API_LEGAL_APPS ("app not in api legal apps"), IP_NOT_IN_WHITE_LIST ("ip not in white list"), @@ -288,29 +284,26 @@ public class ApiConfigService { private Mono canAccess(ServerWebExchange exchange, String app, String ip, String timestamp, String sign, String service, HttpMethod method, String path) { - ServiceConfig sc = serviceConfigMap.get(service); - if (sc == null) { - if (!needAuth) { - ApiConfig ac = getApiConfig(app, service, method, path); - if (ac == null) { - return Mono.just(Access.YES); - } return Mono.just(ac); - } else { - return logAndResult(service + Constants.Symbol.BLANK + Access.NO_SERVICE_CONFIG.getReason(), Access.NO_SERVICE_CONFIG); - } - } else { - String api = ThreadContext.getStringBuilder().append(service).append(Constants.Symbol.BLANK).append(method.name()).append(Constants.Symbol.BLANK + path).toString(); - ApiConfig ac = getApiConfig(app, service, method, path); - if (ac == null) { - if (!needAuth) { - return Mono.just(Access.YES); - } else { - return logAndResult(api + " no route config", Access.ROUTE_NOT_FOUND); - } - } else if (gatewayGroupService.currentGatewayGroupIn(ac.gatewayGroups)) { - if (!ac.checkApp) { + String api = ThreadContext.getStringBuilder().append(service).append(Constants.Symbol.BLANK).append(method.name()).append(Constants.Symbol.BLANK + path).toString(); + ApiConfig ac = getApiConfig(app, service, method, path); + if (ac == null) { + if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX0.equals(WebUtils.getClientReqPathPrefix(exchange))) { + if (systemConfig.aggregateTestAuth) { + return logAndResult(api + " no route config", Access.ROUTE_NOT_FOUND); + } else { + return Mono.just(Access.YES); + } + } + if (!needAuth) { + return Mono.just(Access.YES); + } else { + return logAndResult(api + " no route config", Access.ROUTE_NOT_FOUND); + } + + } else if (!ac.checkApp) { return allow(api, ac); - } else if (app != null && apiConifg2appsService.contains(ac.id, app)) { + + } else if (app != null) { if (ac.access == ApiConfig.ALLOW) { App a = appService.getApp(app); if (a.useWhiteList && !a.allow(ip)) { @@ -319,7 +312,7 @@ public class ApiConfigService { if (a.authType == App.AUTH_TYPE.SIGN) { return authSign(ac, a, timestamp, sign); } else if (a.authType == App.AUTH_TYPE.SECRETKEY) { - return authSecretkey(ac , a, sign); + return authSecretkey(ac, a, sign); } else if (customAuth == null) { return logAndResult(app + " no custom auth", Access.NO_CUSTOM_AUTH); } else { @@ -337,12 +330,9 @@ public class ApiConfigService { } else { return logAndResult("cant access " + api, Access.CANT_ACCESS_SERVICE_API); } - } else { + + } else { return logAndResult(app + " not in " + api + " legal apps", Access.APP_NOT_IN_API_LEGAL_APPS); - } - } else { - return logAndResult(gatewayGroupService.currentGatewayGroupSet + " cant proxy " + api, Access.GATEWAY_GROUP_CANT_PROXY_API); - } } } diff --git a/fizz-plugin/pom.xml b/fizz-plugin/pom.xml index 5b22fd7..c40cbcb 100644 --- a/fizz-plugin/pom.xml +++ b/fizz-plugin/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.0.0-beta2 + 2.0.0-beta3 ../pom.xml 4.0.0 diff --git a/fizz-spring-boot-starter/pom.xml b/fizz-spring-boot-starter/pom.xml index 7926c28..1e1a6c8 100644 --- a/fizz-spring-boot-starter/pom.xml +++ b/fizz-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.0.0-beta2 + 2.0.0-beta3 ../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index d2a10c9..40f03e9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ - 2.0.0-beta2 + 2.0.0-beta3 2.2.13.RELEASE 5.2.14.RELEASE @@ -32,7 +32,7 @@ fizz-gateway-community ${project.artifactId} fizz gateway community - 2.0.0-beta2 + 2.0.0-beta3 pom fizz-common @@ -391,7 +391,7 @@ true - 2.0.0-beta2 + 2.0.0-beta3 -->