Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Codec check, default deny #8449

Merged
merged 6 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
package org.apache.dubbo.rpc.model;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.context.FrameworkExt;
import org.apache.dubbo.common.context.LifecycleAdapter;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ReferenceConfigBase;
import org.apache.dubbo.config.ServiceConfigBase;
Expand Down Expand Up @@ -50,6 +52,9 @@ public class ServiceRepository extends LifecycleAdapter implements FrameworkExt
// useful to find a provider model quickly with serviceInterfaceName:version
private ConcurrentMap<String, ProviderModel> providersWithoutGroup = new ConcurrentHashMap<>();

// useful to find a url quickly with serviceInterfaceName:version
private ConcurrentMap<String, Set<URL>> providerUrlsWithoutGroup = new ConcurrentHashMap<>();

public ServiceRepository() {
Set<BuiltinServiceDetector> builtinServices
= ExtensionLoader.getExtensionLoader(BuiltinServiceDetector.class).getSupportedExtensionInstances();
Expand Down Expand Up @@ -180,6 +185,24 @@ public ConsumerModel lookupReferredService(String serviceKey) {
return consumers.get(serviceKey);
}

public void registerProviderUrl(URL url) {
providerUrlsWithoutGroup.computeIfAbsent(keyWithoutGroup(url.getServiceKey()), (k) -> new ConcurrentHashSet<>()).add(url);
}

public Set<URL> lookupRegisteredProviderUrlsWithoutGroup(String key) {
return providerUrlsWithoutGroup.get(key);
}

@Deprecated
public ConcurrentMap<String, Set<URL>> getProviderUrlsWithoutGroup() {
return providerUrlsWithoutGroup;
}

@Deprecated
public void setProviderUrlsWithoutGroup(ConcurrentMap<String, Set<URL>> providerUrlsWithoutGroup) {
this.providerUrlsWithoutGroup = providerUrlsWithoutGroup;
}

@Override
public void destroy() throws IllegalStateException {
// currently works for unit test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.service.GenericService;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -66,6 +67,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;

import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_SERIALIZATION_BEAN;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
Expand Down Expand Up @@ -132,8 +135,10 @@ public void testServiceClass() {
try {
ctx.start();

ConcurrentMap<String, Set<URL>> tmp = ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
// clear config manager
DubboBootstrap.reset(false);
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);

DemoService demoService = refer("dubbo://127.0.0.1:20887");
String hello = demoService.sayName("hello");
Expand Down Expand Up @@ -240,8 +245,10 @@ public void testMultiProtocol() {
try {
ctx.start();

ConcurrentMap<String, Set<URL>> tmp = ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
// clear config manager
DubboBootstrap.reset(false);
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);

DemoService demoService = refer("dubbo://127.0.0.1:20881");
String hello = demoService.sayName("hello");
Expand Down Expand Up @@ -480,8 +487,10 @@ public void testInitReference() throws Exception {
try {
providerContext.start();

ConcurrentMap<String, Set<URL>> tmp = ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
// clear config manager
DubboBootstrap.reset(false);
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/init-reference.xml",
resourcePath + "/init-reference-properties.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
*/
package org.apache.dubbo.config.spring.context.annotation;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.api.DemoService;
import org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration;
import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl;
import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration;
import org.apache.dubbo.rpc.model.ApplicationModel;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -29,6 +32,9 @@
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;
import java.util.concurrent.ConcurrentMap;

import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;

/**
Expand Down Expand Up @@ -70,8 +76,10 @@ public void test() {
// Test @Transactional is present or not
Assertions.assertNotNull(findAnnotation(beanClass, Transactional.class));

ConcurrentMap<String, Set<URL>> tmp = ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
// reset ConfigManager of provider context
DubboBootstrap.reset(false);
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);

AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
*/
package org.apache.dubbo.config.spring.propertyconfigurer.consumer;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.api.HelloService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.config.spring.registrycenter.DefaultSingleRegistryCenter;
import org.apache.dubbo.config.spring.registrycenter.SingleRegistryCenter;
import org.apache.dubbo.rpc.model.ApplicationModel;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -32,6 +35,9 @@
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Set;
import java.util.concurrent.ConcurrentMap;

public class PropertyConfigurerTest {

private static SingleRegistryCenter singleRegistryCenter;
Expand All @@ -56,8 +62,10 @@ public void testEarlyInit() {
try {
providerContext.start();

// clear config manager
ConcurrentMap<String, Set<URL>> tmp = ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
// reset ConfigManager of provider context
DubboBootstrap.reset(false);
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);

try {
Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
*/
package org.apache.dubbo.config.spring.propertyconfigurer.consumer2;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.api.HelloService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.config.spring.propertyconfigurer.consumer.DemoBeanFactoryPostProcessor;
import org.apache.dubbo.config.spring.registrycenter.DefaultSingleRegistryCenter;
import org.apache.dubbo.config.spring.registrycenter.SingleRegistryCenter;
import org.apache.dubbo.rpc.model.ApplicationModel;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -33,6 +36,9 @@
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Set;
import java.util.concurrent.ConcurrentMap;

public class PropertySourcesConfigurerTest {

private static SingleRegistryCenter singleRegistryCenter;
Expand Down Expand Up @@ -62,8 +68,10 @@ public void testEarlyInit() {
} catch (InterruptedException e) {
}

// reset config
ConcurrentMap<String, Set<URL>> tmp = ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
// reset ConfigManager of provider context
DubboBootstrap.reset(false);
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);

// Resolve placeholder by PropertySourcesPlaceholderConfigurer in dubbo-consumer.xml, without import property source.
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
*/
package org.apache.dubbo.config.spring.propertyconfigurer.consumer3;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.spring.api.HelloService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.config.spring.propertyconfigurer.consumer.DemoBeanFactoryPostProcessor;
import org.apache.dubbo.config.spring.registrycenter.DefaultSingleRegistryCenter;
import org.apache.dubbo.config.spring.registrycenter.SingleRegistryCenter;
import org.apache.dubbo.rpc.model.ApplicationModel;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -37,6 +40,9 @@
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;

import java.util.Set;
import java.util.concurrent.ConcurrentMap;

public class PropertySourcesInJavaConfigTest {

private static final String SCAN_PACKAGE_NAME = "org.apache.dubbo.config.spring.propertyconfigurer.consumer3.notexist";
Expand Down Expand Up @@ -72,8 +78,10 @@ public void testImportPropertySource() {
} catch (InterruptedException e) {
}

// reset config
ConcurrentMap<String, Set<URL>> tmp = ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
// reset ConfigManager of provider context
DubboBootstrap.reset(false);
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);

// Resolve placeholder by import property sources
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class, ImportPropertyConfiguration.class);
Expand Down Expand Up @@ -108,8 +116,10 @@ public void testCustomPropertySourceBean() {
} catch (InterruptedException e) {
}

// reset config
ConcurrentMap<String, Set<URL>> tmp = ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
// reset ConfigManager of provider context
DubboBootstrap.reset(false);
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);

// Resolve placeholder by custom PropertySourcesPlaceholderConfigurer bean
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class, PropertyBeanConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.apache.dubbo.qos.command.impl;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.legacy.ProtocolUtils;
import org.apache.dubbo.qos.legacy.service.DemoService;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;

import io.netty.channel.Channel;
Expand Down Expand Up @@ -71,22 +73,22 @@ public void after() {

@Test
public void testChangeSimpleName() {
DubboProtocol.getDubboProtocol().export(mockInvoker);
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
String result = change.execute(mockCommandContext, new String[]{"DemoService"});
assertEquals("Used the DemoService as default.\r\nYou can cancel default service by command: cd /", result);
}

@Test
public void testChangeName() {
DubboProtocol.getDubboProtocol().export(mockInvoker);
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
String result = change.execute(mockCommandContext, new String[]{"org.apache.dubbo.qos.legacy.service.DemoService"});
assertEquals("Used the org.apache.dubbo.qos.legacy.service.DemoService as default.\r\nYou can cancel default service by command: cd /",
result);
}

@Test
public void testChangePath() {
DubboProtocol.getDubboProtocol().export(mockInvoker);
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
String result = change.execute(mockCommandContext, new String[]{"demo"});
assertEquals("Used the demo as default.\r\nYou can cancel default service by command: cd /", result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package org.apache.dubbo.qos.command.impl;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.impl.channel.MockNettyChannel;
import org.apache.dubbo.qos.legacy.ProtocolUtils;
import org.apache.dubbo.qos.legacy.service.DemoService;
import org.apache.dubbo.remoting.telnet.support.TelnetUtils;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.RpcStatus;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;

Expand Down Expand Up @@ -76,7 +78,7 @@ public void test() throws Exception {
String methodName = "sayHello";
String[] args = new String[]{"org.apache.dubbo.qos.legacy.service.DemoService", "sayHello", "1"};

DubboProtocol.getDubboProtocol().export(mockInvoker);
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
RpcStatus.beginCount(url, methodName);
RpcStatus.endCount(url, methodName, 10L, true);
count.execute(mockCommandContext, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.qos.command.impl;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
Expand All @@ -26,6 +27,7 @@
import org.apache.dubbo.remoting.exchange.ExchangeClient;
import org.apache.dubbo.remoting.exchange.Exchangers;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;

import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -54,7 +56,7 @@ public void before() {
given(mockInvoker.getInterface()).willReturn(DemoService.class);
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:" + availablePort + "/demo"));

DubboProtocol.getDubboProtocol().export(mockInvoker);
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.apache.dubbo.qos.legacy;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.qos.legacy.service.DemoService;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.telnet.TelnetHandler;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;

import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -78,22 +80,22 @@ public void after() {

@Test
public void testChangeSimpleName() throws RemotingException {
DubboProtocol.getDubboProtocol().export(mockInvoker);
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
String result = change.telnet(mockChannel, "DemoService");
assertEquals("Used the DemoService as default.\r\nYou can cancel default service by command: cd /", result);
}

@Test
public void testChangeName() throws RemotingException {
DubboProtocol.getDubboProtocol().export(mockInvoker);
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
String result = change.telnet(mockChannel, "org.apache.dubbo.qos.legacy.service.DemoService");
assertEquals("Used the org.apache.dubbo.qos.legacy.service.DemoService as default.\r\nYou can cancel default service by command: cd /",
result);
}

@Test
public void testChangePath() throws RemotingException {
DubboProtocol.getDubboProtocol().export(mockInvoker);
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
String result = change.telnet(mockChannel, "demo");
assertEquals("Used the demo as default.\r\nYou can cancel default service by command: cd /", result);
}
Expand Down
Loading