feat: auth switch

This commit is contained in:
hongqiaowei
2020-12-07 19:15:08 +08:00
parent add08fcc58
commit 1dd3119e5f
2 changed files with 8 additions and 6 deletions

View File

@@ -113,9 +113,9 @@ public class ApiConfigService {
}
}
@NacosValue(value = "${auth.compatible-wh:false}", autoRefreshed = true)
@Value("${auth.compatible-wh:false}")
private boolean compatibleWh;
@NacosValue(value = "${need-auth:false}", autoRefreshed = true)
@Value("${need-auth:false}")
private boolean needAuth;
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
private ReactiveStringRedisTemplate rt;
@@ -293,7 +293,7 @@ public class ApiConfigService {
}
ServiceConfig sc = serviceConfigMap.get(service);
if (sc == null) {
if (compatibleWh) {
if (!needAuth) {
return Mono.just(Access.YES);
} else {
return logWarnAndResult(service + Constants.Symbol.BLANK + Access.NO_SERVICE_CONFIG.getReason(), Access.NO_SERVICE_CONFIG);
@@ -309,7 +309,7 @@ public class ApiConfigService {
}
ApiConfig ac = ac0;
if (ac == null) {
if (compatibleWh) {
if (needAuth) {
return Mono.just(Access.YES);
} else {
return logWarnAndResult(api + " no api config", Access.NO_API_CONFIG);

View File

@@ -18,6 +18,7 @@
package we.proxy;
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;
@@ -224,7 +225,8 @@ public class FizzWebClient {
}
private boolean isService(String s) {
if (s.indexOf(Constants.Symbol.DOT) > 0 || s.equals(localhost)) {
if (StringUtils.indexOfAny(s, Constants.Symbol.DOT, Constants.Symbol.COLON) > 0
|| StringUtils.indexOfIgnoreCase(s, localhost) > 0) {
return false;
} else {
return true;