Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…eature/optimize-code-js

# Conflicts:
#	plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/AbstractMapper.java
#	plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/mapper/AbstractMapperTest.java
  • Loading branch information
20144101037 committed Dec 6, 2024
2 parents c1ac100 + 28548c1 commit 79f448f
Show file tree
Hide file tree
Showing 44 changed files with 1,803 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ConfigTransportClient(NacosClientProperties properties, ConfigServerListM
this.tenant = properties.getProperty(PropertyKeyConst.NAMESPACE);
this.serverListManager = serverListManager;
this.properties = properties.asProperties();
this.securityProxy = new SecurityProxy(serverListManager.getServerList(),
this.securityProxy = new SecurityProxy(serverListManager,
ConfigHttpClientManager.getInstance().getNacosRestTemplate());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void init(Properties properties) throws NacosException {
InitUtils.initWebRootContext(nacosClientProperties);
serverListManager = new NamingServerListManager(nacosClientProperties, namespace);
serverListManager.start();
securityProxy = new SecurityProxy(serverListManager.getServerList(),
securityProxy = new SecurityProxy(serverListManager,
NamingHttpClientManager.getInstance().getNacosRestTemplate());
initSecurityProxy(properties);
serverProxy = new NamingHttpClientProxy(namespace, securityProxy, serverListManager, nacosClientProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public NamingClientProxyDelegate(String namespace, ServiceInfoHolder serviceInfo
this.serverListManager = new NamingServerListManager(properties, namespace);
this.serverListManager.start();
this.serviceInfoHolder = serviceInfoHolder;
this.securityProxy = new SecurityProxy(this.serverListManager.getServerList(),
this.securityProxy = new SecurityProxy(this.serverListManager,
NamingHttpClientManager.getInstance().getNacosRestTemplate());
initSecurityProxy(properties);
this.httpClientProxy = new NamingHttpClientProxy(namespace, securityProxy, serverListManager, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
package com.alibaba.nacos.client.security;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.address.AbstractServerListManager;
import com.alibaba.nacos.client.address.ServerListChangeEvent;
import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant;
import com.alibaba.nacos.plugin.auth.spi.client.ClientAuthPluginManager;
import com.alibaba.nacos.plugin.auth.api.LoginIdentityContext;
import com.alibaba.nacos.plugin.auth.spi.client.ClientAuthService;
import com.alibaba.nacos.plugin.auth.api.RequestResource;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import com.alibaba.nacos.common.lifecycle.Closeable;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.listener.Subscriber;
import com.alibaba.nacos.plugin.auth.api.LoginIdentityContext;
import com.alibaba.nacos.plugin.auth.api.RequestResource;
import com.alibaba.nacos.plugin.auth.spi.client.ClientAuthPluginManager;
import com.alibaba.nacos.plugin.auth.spi.client.ClientAuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

Expand All @@ -45,15 +49,25 @@ public class SecurityProxy implements Closeable {
private ClientAuthPluginManager clientAuthPluginManager;

/**
* Construct from serverList, nacosRestTemplate, init client auth plugin.
* // TODO change server list to serverListManager after serverListManager refactor and unite.
* Construct from serverListManager, nacosRestTemplate, init client auth plugin.
*
* @param serverList a server list that client request to.
* @param serverListManager a server list manager that client request to.
* @Param nacosRestTemplate http request template.
*/
public SecurityProxy(List<String> serverList, NacosRestTemplate nacosRestTemplate) {
public SecurityProxy(AbstractServerListManager serverListManager, NacosRestTemplate nacosRestTemplate) {
clientAuthPluginManager = new ClientAuthPluginManager();
clientAuthPluginManager.init(serverList, nacosRestTemplate);
clientAuthPluginManager.init(serverListManager.getServerList(), nacosRestTemplate);
NotifyCenter.registerSubscriber(new Subscriber<ServerListChangeEvent>() {
@Override
public void onEvent(ServerListChangeEvent event) {
clientAuthPluginManager.refreshServerList(serverListManager.getServerList());
}

@Override
public Class<? extends Event> subscribeType() {
return ServerListChangeEvent.class;
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.address.AbstractServerListManager;
import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.common.http.HttpRestResult;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import com.alibaba.nacos.common.http.param.Header;
Expand Down Expand Up @@ -68,7 +70,34 @@ void setUp() throws Exception {

List<String> serverList = new ArrayList<>();
serverList.add("localhost");
securityProxy = new SecurityProxy(serverList, nacosRestTemplate);
NacosClientProperties properties = NacosClientProperties.PROTOTYPE.derive(new Properties());
AbstractServerListManager serverListManager = new AbstractServerListManager(properties) {
@Override
protected String getModuleName() {
return "Test";
}

@Override
protected NacosRestTemplate getNacosRestTemplate() {
return nacosRestTemplate;
}

@Override
public String genNextServer() {
return serverList.get(0);
}

@Override
public String getCurrentServer() {
return serverList.get(0);
}

@Override
public List<String> getServerList() {
return serverList;
}
};
securityProxy = new SecurityProxy(serverListManager, nacosRestTemplate);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.constant.ParametersField;
import com.alibaba.nacos.config.server.controller.parameters.SameNamespaceCloneConfigBean;
import com.alibaba.nacos.config.server.enums.ApiVersionEnum;
import com.alibaba.nacos.config.server.model.ConfigAdvanceInfo;
import com.alibaba.nacos.config.server.model.ConfigAllInfo;
import com.alibaba.nacos.config.server.model.ConfigInfo;
Expand Down Expand Up @@ -244,7 +245,7 @@ public void getConfig(HttpServletRequest request, HttpServletResponse response,

final String clientIp = RequestUtil.getRemoteIp(request);
String isNotify = request.getHeader("notify");
inner.doGetConfig(request, response, dataId, group, tenant, tag, isNotify, clientIp);
inner.doGetConfig(request, response, dataId, group, tenant, tag, isNotify, clientIp, ApiVersionEnum.V1);
}

/**
Expand Down
Loading

0 comments on commit 79f448f

Please sign in to comment.