|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package com.alibaba.dubbo.common.serialize.hessian2.dubbo; |
| 18 | + |
| 19 | +import com.alibaba.com.caucho.hessian.io.SerializerFactory; |
| 20 | +import com.alibaba.dubbo.common.serialize.hessian2.Hessian2SerializerFactory; |
| 21 | +import com.alibaba.dubbo.common.utils.ConfigUtils; |
| 22 | +import com.alibaba.dubbo.common.utils.StringUtils; |
| 23 | + |
| 24 | +import static com.alibaba.dubbo.common.serialize.hessian2.dubbo.Hessian2FactoryUtil.ALLOW; |
| 25 | +import static com.alibaba.dubbo.common.serialize.hessian2.dubbo.Hessian2FactoryUtil.DENY; |
| 26 | +import static com.alibaba.dubbo.common.serialize.hessian2.dubbo.Hessian2FactoryUtil.WHITELIST; |
| 27 | + |
| 28 | +/** |
| 29 | + * see https://github.com/ebourg/hessian/commit/cf851f5131707891e723f7f6a9718c2461aed826 |
| 30 | + */ |
| 31 | +public class WhitelistHessian2FactoryInitializer extends AbstractHessian2FactoryInitializer { |
| 32 | + |
| 33 | + @Override |
| 34 | + public SerializerFactory createSerializerFactory() { |
| 35 | + SerializerFactory serializerFactory = new Hessian2SerializerFactory(); |
| 36 | + String whiteList = ConfigUtils.getProperty(WHITELIST); |
| 37 | + if ("true".equals(whiteList)) { |
| 38 | + serializerFactory.getClassFactory().setWhitelist(true); |
| 39 | + String allowPattern = ConfigUtils.getProperty(ALLOW); |
| 40 | + if (StringUtils.isNotEmpty(allowPattern)) { |
| 41 | + serializerFactory.getClassFactory().allow(allowPattern); |
| 42 | + } |
| 43 | + } else { |
| 44 | + serializerFactory.getClassFactory().setWhitelist(false); |
| 45 | + String denyPattern = ConfigUtils.getProperty(DENY); |
| 46 | + if (StringUtils.isNotEmpty(denyPattern)) { |
| 47 | + serializerFactory.getClassFactory().deny(denyPattern); |
| 48 | + } |
| 49 | + } |
| 50 | + return serializerFactory; |
| 51 | + } |
| 52 | + |
| 53 | +} |
0 commit comments