diff --git a/README.en-us.md b/README.en-us.md
index 8246652..84bcc38 100644
--- a/README.en-us.md
+++ b/README.en-us.md
@@ -27,7 +27,7 @@ http://demo.fizzgate.com/
account/password:`admin`/`Aa123!`
-health checking url:http://demo.fizzgate.com/serviceConfigs
+health checking url:http://demo.fizzgate.com/admin/health
API access:http://demo.fizzgate.com/proxy/[Service Name]/[API Path]
diff --git a/README.md b/README.md
index 8b3b148..0765cb5 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ http://demo.fizzgate.com/
账号/密码:`admin`/`Aa123!`
-健康检查地址:http://demo.fizzgate.com/serviceConfigs
+健康检查地址:http://demo.fizzgate.com/admin/health
API地址:http://demo.fizzgate.com/proxy/[服务名]/[API Path]
diff --git a/src/main/java/we/controller/ConfigController.java b/src/main/java/we/controller/ConfigController.java
index fe0e39d..953d82c 100644
--- a/src/main/java/we/controller/ConfigController.java
+++ b/src/main/java/we/controller/ConfigController.java
@@ -34,7 +34,7 @@ import java.nio.charset.StandardCharsets;
*/
@RestController
-@RequestMapping(value = "/config")
+@RequestMapping(value = "/admin/config")
public class ConfigController {
@Resource
diff --git a/src/main/java/we/controller/HealthCheckController.java b/src/main/java/we/controller/HealthCheckController.java
new file mode 100644
index 0000000..e1e6765
--- /dev/null
+++ b/src/main/java/we/controller/HealthCheckController.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package we.controller;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+import we.plugin.auth.ApiConfigService;
+import we.plugin.auth.AppService;
+import we.plugin.auth.GatewayGroupService;
+import we.stats.ratelimit.ResourceRateLimitConfigService;
+import we.util.Constants;
+import we.util.DateTimeUtils;
+import we.util.JacksonUtils;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+
+/**
+ * @author hongqiaowei
+ */
+
+@RestController
+@RequestMapping("/admin")
+public class HealthCheckController {
+
+ @GetMapping("/health")
+ public Mono health(ServerWebExchange exchange) {
+ long mills = System.currentTimeMillis();
+ String now = DateTimeUtils.toDate(mills, Constants.DatetimePattern.DP23);
+ return Mono.just(now + " ok");
+ }
+}
diff --git a/src/main/java/we/controller/ManagerConfigController.java b/src/main/java/we/controller/ManagerConfigController.java
index eb2929b..9ec623a 100644
--- a/src/main/java/we/controller/ManagerConfigController.java
+++ b/src/main/java/we/controller/ManagerConfigController.java
@@ -43,7 +43,7 @@ import java.util.stream.Collectors;
* @author zhongjie
*/
@RestController
-@RequestMapping(value = "/managerConfig")
+@RequestMapping(value = "/admin/managerConfig")
public class ManagerConfigController {
@NacosValue(value = "${fizz.manager.config.key:fizz-manager-key}", autoRefreshed = true)
@Value("${fizz.manager.config.key:fizz-manager-key}")
diff --git a/src/main/java/we/plugin/auth/ApiConfig.java b/src/main/java/we/plugin/auth/ApiConfig.java
index 21b3798..8a0794c 100644
--- a/src/main/java/we/plugin/auth/ApiConfig.java
+++ b/src/main/java/we/plugin/auth/ApiConfig.java
@@ -53,10 +53,12 @@ public class ApiConfig {
private static final String match_all = "/**";
- // @JsonIgnore
+ private static final int ENABLE = 1;
+
+ private static final int UNABLE = 0;
+
public int id; // tb_api_auth.id
- // @JsonIgnore
public int isDeleted = 0; // tb_api_auth.is_deleted
public Set gatewayGroups = Stream.of(GatewayGroup.DEFAULT).collect(Collectors.toSet());
@@ -67,28 +69,27 @@ public class ApiConfig {
public HttpMethod method = HttpMethod.X;
-// public String path = String.valueOf(Constants.Symbol.FORWARD_SLASH);
public String path = match_all;
public boolean exactMatch = false;
public String backendPath;
- public Set apps = Stream.of(App.ALL_APP).collect(Collectors.toSet());
+// public Set apps = Stream.of(App.ALL_APP).collect(Collectors.toSet());
@JsonProperty("proxyMode")
public byte type = Type.SERVICE_DISCOVERY;
private AtomicInteger counter = new AtomicInteger(-1);
-// public List backendUrls;
-
public List httpHostPorts;
public char access = ALLOW;
public List pluginConfigs;
+ public boolean checkApp = false;
+
public static boolean isAntPathPattern(String path) {
boolean uriVar = false;
for (int i = 0; i < path.length(); i++) {
@@ -120,18 +121,18 @@ public class ApiConfig {
}
}
- public void setApp(String as) {
- apps.remove(App.ALL_APP);
- if (StringUtils.isBlank(as)) {
- apps.add("*");
- } else {
- Arrays.stream(StringUtils.split(as, ',')).forEach(
- a -> {
- apps.add(a.trim());
- }
- );
- }
- }
+ // public void setApp(String as) {
+ // apps.remove(App.ALL_APP);
+ // if (StringUtils.isBlank(as)) {
+ // apps.add("*");
+ // } else {
+ // Arrays.stream(StringUtils.split(as, ',')).forEach(
+ // a -> {
+ // apps.add(a.trim());
+ // }
+ // );
+ // }
+ // }
public void setPath(String p) {
if (StringUtils.isNotBlank(p)) {
@@ -155,15 +156,13 @@ public class ApiConfig {
}
}
- // @JsonIgnore
- // public String getNextBackendUrl() {
- // int idx = counter.incrementAndGet();
- // if (idx < 0) {
- // counter.set(0);
- // idx = 0;
- // }
- // return backendUrls.get(idx % backendUrls.size());
- // }
+ public void setAppEnable(int v) {
+ if (v == ENABLE) {
+ checkApp = true;
+ } else {
+ checkApp = false;
+ }
+ }
@JsonIgnore
public String getNextHttpHostPort() {
@@ -182,6 +181,20 @@ public class ApiConfig {
return UrlTransformUtils.transform(path, backendPath, reqPath);
}
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ApiConfig) {
+ ApiConfig that = (ApiConfig) obj;
+ return this.id == that.id;
+ }
+ return false;
+ }
+
@Override
public String toString() {
return JacksonUtils.writeValueAsString(this);
diff --git a/src/main/java/we/plugin/auth/ApiConfig2apps.java b/src/main/java/we/plugin/auth/ApiConfig2apps.java
new file mode 100644
index 0000000..ae11afe
--- /dev/null
+++ b/src/main/java/we/plugin/auth/ApiConfig2apps.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package we.plugin.auth;
+
+import we.util.JacksonUtils;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author hongqiaowei
+ */
+
+public class ApiConfig2apps {
+
+ public static final int DELETED = 1;
+
+ public int id;
+
+ public int isDeleted = 0;
+
+ public List apps;
+
+ @Override
+ public String toString() {
+ return JacksonUtils.writeValueAsString(this);
+ }
+}
diff --git a/src/main/java/we/plugin/auth/ApiConfigService.java b/src/main/java/we/plugin/auth/ApiConfigService.java
index 8935d2d..c546e3d 100644
--- a/src/main/java/we/plugin/auth/ApiConfigService.java
+++ b/src/main/java/we/plugin/auth/ApiConfigService.java
@@ -18,9 +18,6 @@
package we.plugin.auth;
import com.alibaba.nacos.api.config.annotation.NacosValue;
-import com.ctrip.framework.apollo.model.ConfigChange;
-import com.ctrip.framework.apollo.model.ConfigChangeEvent;
-import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,12 +28,11 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;
-import org.springframework.util.ObjectUtils;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
-import we.flume.clients.log4j2appender.LogService;
import we.config.AggregateRedisConfig;
+import we.flume.clients.log4j2appender.LogService;
import we.util.*;
import javax.annotation.PostConstruct;
@@ -71,48 +67,6 @@ public class ApiConfigService {
private Map apiConfigMap = new HashMap<>(128);
- // TODO XXX
- @Value("${serviceWhiteList:x}")
- private String serviceWhiteList;
- private Set whiteListSet = new HashSet<>(196);
- @ApolloConfigChangeListener
- private void configChangeListter(ConfigChangeEvent cce) {
- cce.changedKeys().forEach(
- k -> {
- ConfigChange cc = cce.getChange(k);
- if (cc.getPropertyName().equalsIgnoreCase("serviceWhiteList")) {
- this.updateServiceWhiteList(cc.getOldValue(), cc.getNewValue());
- }
- }
- );
- }
-
- private void updateServiceWhiteList(String oldValue, String newValue) {
- if (ObjectUtils.nullSafeEquals(oldValue, newValue)) {
- return;
- }
- log.info("old service white list: " + oldValue);
- serviceWhiteList = newValue;
- afterServiceWhiteListSet();
- }
-
- @NacosValue(value = "${serviceWhiteList:x}", autoRefreshed = true)
- public void setServiceWhiteList(String serviceWhiteList) {
- this.updateServiceWhiteList(this.serviceWhiteList, serviceWhiteList);
- }
-
- public void afterServiceWhiteListSet() {
- if (StringUtils.isNotBlank(serviceWhiteList)) {
- whiteListSet.clear();
- Arrays.stream(StringUtils.split(serviceWhiteList, Constants.Symbol.COMMA)).forEach(s -> {
- whiteListSet.add(s);
- });
- log.info("new service white list: " + whiteListSet.toString());
- } else {
- log.info("no service white list");
- }
- }
-
@NacosValue(value = "${need-auth:false}", autoRefreshed = true)
@Value("${need-auth:false}")
private boolean needAuth;
@@ -123,6 +77,9 @@ public class ApiConfigService {
@Resource
private AppService appService;
+ @Resource
+ private ApiConifg2appsService apiConifg2appsService;
+
@Resource
private GatewayGroupService gatewayGroupService;
@@ -136,8 +93,6 @@ public class ApiConfigService {
@PostConstruct
public void init() throws Throwable {
- afterServiceWhiteListSet(); // TODO XXX
-
final Throwable[] throwable = new Throwable[1];
Throwable error = Mono.just(Objects.requireNonNull(rt.opsForHash().entries(fizzApiConfig)
.defaultIfEmpty(new AbstractMap.SimpleEntry<>(ReactorUtils.OBJ, ReactorUtils.OBJ)).onErrorStop().doOnError(t -> {
@@ -226,6 +181,7 @@ public class ApiConfigService {
log.info("no " + ac.service + " config to delete");
} else {
sc.remove(ac);
+ apiConifg2appsService.remove(ac.id);
}
} else {
if (sc == null) {
@@ -260,8 +216,6 @@ public class ApiConfigService {
CUSTOM_AUTH_REJECT ("custom auth reject"),
- SERVICE_NOT_OPEN ("service not open"),
-
CANT_ACCESS_SERVICE_API ("cant access service api");
private String reason;
@@ -275,6 +229,21 @@ public class ApiConfigService {
}
}
+ public ApiConfig getApiConfig(String service, HttpMethod method, String path, String gatewayGroup, String app) {
+ ServiceConfig sc = serviceConfigMap.get(service);
+ if (sc != null) {
+ Set acs = sc.getApiConfigs(method, path, gatewayGroup);
+ if (acs != null) {
+ for (ApiConfig ac : acs) {
+ if (apiConifg2appsService.contains(ac.id, app)) {
+ return ac;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
public Mono