Fix classname (#11444)

This commit is contained in:
Albumen Kevin 2023-02-02 16:15:47 +08:00 committed by GitHub
parent fe14026f68
commit 47f7419d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 30 deletions

View File

@ -290,7 +290,7 @@ public class SerializeSecurityConfigurator implements ScopeClassLoaderListener<M
if (subs.length > trustSerializeClassLevel) {
serializeSecurityManager.addToAllowed(Arrays.stream(subs)
.limit(trustSerializeClassLevel)
.collect(Collectors.joining(".")));
.collect(Collectors.joining(".")) + ".");
} else {
serializeSecurityManager.addToAllowed(className);
}

View File

@ -363,7 +363,7 @@ class SerializeSecurityConfiguratorTest {
serializeSecurityConfigurator.onAddClassLoader(moduleModel, Thread.currentThread().getContextClassLoader());
serializeSecurityConfigurator.registerInterface(DemoService3.class);
Assertions.assertTrue(ssm.getAllowedPrefix().contains("com.service.deep1.deep2"));
Assertions.assertTrue(ssm.getAllowedPrefix().contains("com.service.deep1.deep2."));
frameworkModel.destroy();
}

View File

@ -32,6 +32,7 @@ import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
import org.apache.dubbo.rpc.model.ServiceMetadata;
import org.apache.dubbo.rpc.model.ServiceModel;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
@ -59,14 +60,18 @@ public class ProtocolSecurityWrapper implements Protocol {
try {
ServiceModel serviceModel = invoker.getUrl().getServiceModel();
ScopeModel scopeModel = invoker.getUrl().getScopeModel();
SerializeSecurityConfigurator serializeSecurityConfigurator = ScopeModelUtil.getModuleModel(scopeModel)
.getBeanFactory().getBean(SerializeSecurityConfigurator.class);
Optional.ofNullable(serviceModel)
.map(ServiceModel::getServiceModel)
.map(ServiceDescriptor::getServiceInterfaceClass)
.ifPresent((interfaceClass) -> {
SerializeSecurityConfigurator serializeSecurityConfigurator = ScopeModelUtil.getModuleModel(scopeModel)
.getBeanFactory().getBean(SerializeSecurityConfigurator.class);
serializeSecurityConfigurator.registerInterface(interfaceClass);
});
.ifPresent(serializeSecurityConfigurator::registerInterface);
Optional.ofNullable(serviceModel)
.map(ServiceModel::getServiceMetadata)
.map(ServiceMetadata::getServiceType)
.ifPresent(serializeSecurityConfigurator::registerInterface);
} catch (Throwable t) {
logger.error(INTERNAL_ERROR, "", "", "Failed to register interface for security check", t);
}
@ -85,6 +90,11 @@ public class ProtocolSecurityWrapper implements Protocol {
.map(ServiceModel::getServiceModel)
.map(ServiceDescriptor::getServiceInterfaceClass)
.ifPresent(serializeSecurityConfigurator::registerInterface);
Optional.ofNullable(serviceModel)
.map(ServiceModel::getServiceMetadata)
.map(ServiceMetadata::getServiceType)
.ifPresent(serializeSecurityConfigurator::registerInterface);
serializeSecurityConfigurator.registerInterface(type);
} catch (Throwable t) {
logger.error(INTERNAL_ERROR, "", "", "Failed to register interface for security check", t);

View File

@ -16,16 +16,17 @@
*/
package org.apache.dubbo.common.serialize.fastjson2;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.serialize.ObjectInput;
import org.apache.dubbo.common.serialize.ObjectOutput;
import org.apache.dubbo.common.serialize.Serialization;
import org.apache.dubbo.rpc.model.FrameworkModel;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static org.apache.dubbo.common.serialize.Constants.FASTJSON2_SERIALIZATION_ID;
/**
@ -37,15 +38,6 @@ import static org.apache.dubbo.common.serialize.Constants.FASTJSON2_SERIALIZATIO
*/
public class FastJson2Serialization implements Serialization {
private final Fastjson2CreatorManager fastjson2CreatorManager;
private final Fastjson2SecurityManager fastjson2SecurityManager;
public FastJson2Serialization(FrameworkModel frameworkModel) {
this.fastjson2CreatorManager = frameworkModel.getBeanFactory().getBean(Fastjson2CreatorManager.class);
this.fastjson2SecurityManager = frameworkModel.getBeanFactory().getBean(Fastjson2SecurityManager.class);
}
@Override
public byte getContentTypeId() {
return FASTJSON2_SERIALIZATION_ID;
@ -58,11 +50,25 @@ public class FastJson2Serialization implements Serialization {
@Override
public ObjectOutput serialize(URL url, OutputStream output) throws IOException {
Fastjson2CreatorManager fastjson2CreatorManager = Optional.ofNullable(url)
.map(URL::getOrDefaultFrameworkModel)
.orElse(FrameworkModel.defaultModel())
.getBeanFactory().getBean(Fastjson2CreatorManager.class);
return new FastJson2ObjectOutput(fastjson2CreatorManager, output);
}
@Override
public ObjectInput deserialize(URL url, InputStream input) throws IOException {
Fastjson2CreatorManager fastjson2CreatorManager = Optional.ofNullable(url)
.map(URL::getOrDefaultFrameworkModel)
.orElse(FrameworkModel.defaultModel())
.getBeanFactory().getBean(Fastjson2CreatorManager.class);
Fastjson2SecurityManager fastjson2SecurityManager = Optional.ofNullable(url)
.map(URL::getOrDefaultFrameworkModel)
.orElse(FrameworkModel.defaultModel())
.getBeanFactory().getBean(Fastjson2SecurityManager.class);
return new FastJson2ObjectInput(fastjson2CreatorManager, fastjson2SecurityManager, input);
}

View File

@ -16,16 +16,17 @@
*/
package org.apache.dubbo.common.serialize.hessian2;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.serialize.ObjectInput;
import org.apache.dubbo.common.serialize.ObjectOutput;
import org.apache.dubbo.common.serialize.Serialization;
import org.apache.dubbo.rpc.model.FrameworkModel;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static org.apache.dubbo.common.serialize.Constants.HESSIAN2_SERIALIZATION_ID;
/**
@ -37,12 +38,6 @@ import static org.apache.dubbo.common.serialize.Constants.HESSIAN2_SERIALIZATION
*/
public class Hessian2Serialization implements Serialization {
private final Hessian2FactoryManager hessian2FactoryManager;
public Hessian2Serialization(FrameworkModel frameworkModel) {
hessian2FactoryManager = frameworkModel.getBeanFactory().getBean(Hessian2FactoryManager.class);
}
@Override
public byte getContentTypeId() {
return HESSIAN2_SERIALIZATION_ID;
@ -55,11 +50,19 @@ public class Hessian2Serialization implements Serialization {
@Override
public ObjectOutput serialize(URL url, OutputStream out) throws IOException {
Hessian2FactoryManager hessian2FactoryManager = Optional.ofNullable(url)
.map(URL::getOrDefaultFrameworkModel)
.orElse(FrameworkModel.defaultModel())
.getBeanFactory().getBean(Hessian2FactoryManager.class);
return new Hessian2ObjectOutput(out, hessian2FactoryManager);
}
@Override
public ObjectInput deserialize(URL url, InputStream is) throws IOException {
Hessian2FactoryManager hessian2FactoryManager = Optional.ofNullable(url)
.map(URL::getOrDefaultFrameworkModel)
.orElse(FrameworkModel.defaultModel())
.getBeanFactory().getBean(Hessian2FactoryManager.class);
return new Hessian2ObjectInput(is, hessian2FactoryManager);
}