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

Hessian2 whitelist (#6378) #6415

Merged
merged 4 commits into from
Jul 8, 2020
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 @@ -127,7 +127,7 @@ public class DubboBootstrap extends GenericEventListener {

private final Logger logger = LoggerFactory.getLogger(getClass());

private static DubboBootstrap instance;
private static volatile DubboBootstrap instance;

private final AtomicBoolean awaited = new AtomicBoolean(false);

Expand Down Expand Up @@ -176,9 +176,13 @@ public class DubboBootstrap extends GenericEventListener {
/**
* See {@link ApplicationModel} and {@link ExtensionLoader} for why DubboBootstrap is designed to be singleton.
*/
public static synchronized DubboBootstrap getInstance() {
public static DubboBootstrap getInstance() {
if (instance == null) {
instance = new DubboBootstrap();
synchronized (DubboBootstrap.class) {
if (instance == null) {
instance = new DubboBootstrap();
}
}
}
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
/**
* It indicates whether {@link AbstractConfig} binding to multiple Spring Beans.
*
* @return the default value is <code>false</code>
* @return the default value is <code>true</code>
* @see EnableDubboConfig#multiple()
*/
@AliasFor(annotation = EnableDubboConfig.class, attribute = "multiple")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
/**
* It indicates whether binding to multiple Spring Beans.
*
* @return the default value is <code>false</code>
* @return the default value is <code>true</code>
* @revised 2.5.9
*/
boolean multiple() default true;
Expand Down
2 changes: 1 addition & 1 deletion dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<activation_version>1.2.0</activation_version>
<test_container_version>1.11.2</test_container_version>
<etcd_launcher_version>0.3.0</etcd_launcher_version>
<hessian_lite_version>3.2.7</hessian_lite_version>
<hessian_lite_version>3.2.8</hessian_lite_version>
<swagger_version>1.5.19</swagger_version>
<spring_test_version>4.3.16.RELEASE</spring_test_version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.common.serialize.hessian2;

import org.apache.dubbo.common.serialize.ObjectInput;
import org.apache.dubbo.common.serialize.hessian2.dubbo.Hessian2FactoryInitializer;

import com.alibaba.com.caucho.hessian.io.Hessian2Input;

Expand All @@ -31,7 +32,7 @@ public class Hessian2ObjectInput implements ObjectInput {

private static ThreadLocal<Hessian2Input> INPUT_TL = ThreadLocal.withInitial(() -> {
Hessian2Input h2i = new Hessian2Input(null);
h2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
h2i.setSerializerFactory(Hessian2FactoryInitializer.getInstance().getSerializerFactory());
h2i.setCloseStreamOnClose(true);
return h2i;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.common.serialize.hessian2;

import org.apache.dubbo.common.serialize.ObjectOutput;
import org.apache.dubbo.common.serialize.hessian2.dubbo.Hessian2FactoryInitializer;

import com.alibaba.com.caucho.hessian.io.Hessian2Output;

Expand All @@ -30,7 +31,7 @@ public class Hessian2ObjectOutput implements ObjectOutput {

private static ThreadLocal<Hessian2Output> OUTPUT_TL = ThreadLocal.withInitial(() -> {
Hessian2Output h2o = new Hessian2Output(null);
h2o.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
h2o.setSerializerFactory(Hessian2FactoryInitializer.getInstance().getSerializerFactory());
h2o.setCloseStreamOnClose(true);
return h2o;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

public class Hessian2SerializerFactory extends SerializerFactory {

public static final SerializerFactory SERIALIZER_FACTORY = new Hessian2SerializerFactory();

private Hessian2SerializerFactory() {
public Hessian2SerializerFactory() {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.serialize.hessian2.dubbo;

import com.alibaba.com.caucho.hessian.io.SerializerFactory;

public abstract class AbstractHessian2FactoryInitializer implements Hessian2FactoryInitializer {
private static SerializerFactory SERIALIZER_FACTORY;

@Override
public SerializerFactory getSerializerFactory() {
if (SERIALIZER_FACTORY != null) {
return SERIALIZER_FACTORY;
}
synchronized (this) {
SERIALIZER_FACTORY = createSerializerFactory();
}
return SERIALIZER_FACTORY;
}

protected abstract SerializerFactory createSerializerFactory();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.serialize.hessian2.dubbo;

import org.apache.dubbo.common.serialize.hessian2.Hessian2SerializerFactory;

import com.alibaba.com.caucho.hessian.io.SerializerFactory;

public class DefaultHessian2FactoryInitializer extends AbstractHessian2FactoryInitializer {
@Override
protected SerializerFactory createSerializerFactory() {
return new Hessian2SerializerFactory();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.serialize.hessian2.dubbo;

import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.common.utils.StringUtils;

import com.alibaba.com.caucho.hessian.io.SerializerFactory;

@SPI("default")
public interface Hessian2FactoryInitializer {
String WHITELIST = "dubbo.application.hessian2.whitelist";
String ALLOW = "dubbo.application.hessian2.allow";
String DENY = "dubbo.application.hessian2.deny";
ExtensionLoader<Hessian2FactoryInitializer> loader = ExtensionLoader.getExtensionLoader(Hessian2FactoryInitializer.class);

SerializerFactory getSerializerFactory();

static Hessian2FactoryInitializer getInstance() {
String whitelist = ConfigurationUtils.getProperty(WHITELIST);
if (StringUtils.isNotEmpty(whitelist)) {
return loader.getExtension("whitelist");
}
return loader.getDefaultExtension();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.serialize.hessian2.dubbo;

import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.serialize.hessian2.Hessian2SerializerFactory;
import org.apache.dubbo.common.utils.StringUtils;

import com.alibaba.com.caucho.hessian.io.SerializerFactory;

/**
* see https://github.com/ebourg/hessian/commit/cf851f5131707891e723f7f6a9718c2461aed826
*/
public class WhitelistHessian2FactoryInitializer extends AbstractHessian2FactoryInitializer {

@Override
public SerializerFactory createSerializerFactory() {
SerializerFactory serializerFactory = new Hessian2SerializerFactory();
String whiteList = ConfigurationUtils.getProperty(WHITELIST);
if ("true".equals(whiteList)) {
serializerFactory.getClassFactory().setWhitelist(true);
String allowPattern = ConfigurationUtils.getProperty(ALLOW);
if (StringUtils.isNotEmpty(allowPattern)) {
serializerFactory.getClassFactory().allow(allowPattern);
}
} else {
serializerFactory.getClassFactory().setWhitelist(false);
String denyPattern = ConfigurationUtils.getProperty(DENY);
if (StringUtils.isNotEmpty(denyPattern)) {
serializerFactory.getClassFactory().deny(denyPattern);
}
}
return serializerFactory;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default=org.apache.dubbo.common.serialize.hessian2.dubbo.DefaultHessian2FactoryInitializer
whitelist=org.apache.dubbo.common.serialize.hessian2.dubbo.WhitelistHessian2FactoryInitializer