From 853b29be5dd6969d135a5ae5341c0133876b9ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A2=A7=E8=BF=9C?= Date: Thu, 16 Apr 2020 15:33:21 +0800 Subject: [PATCH 1/8] feat:optimize for blacklist --- pom.xml | 12 +++++ .../com/alipay/hessian/CallStackUtil.java | 34 +++++++++++++ .../com/alipay/hessian/ClassNameResolver.java | 41 +++++++--------- .../hessian/ClassNameResolverBuilder.java | 2 +- .../alipay/hessian/NameBlackListFilter.java | 49 +++++++++++++++++-- .../internal/InternalNameBlackListFilter.java | 17 +++++++ 6 files changed, 125 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/alipay/hessian/CallStackUtil.java diff --git a/pom.xml b/pom.xml index 2657b45..127e536 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,18 @@ 1.1-rev-1 provided + + org.slf4j + slf4j-api + 1.7.9 + provided + + + com.alipay.sofa.common + sofa-common-tools + 1.0.14 + provided + junit diff --git a/src/main/java/com/alipay/hessian/CallStackUtil.java b/src/main/java/com/alipay/hessian/CallStackUtil.java new file mode 100644 index 0000000..3610061 --- /dev/null +++ b/src/main/java/com/alipay/hessian/CallStackUtil.java @@ -0,0 +1,34 @@ +/* + * 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 com.alipay.hessian; + +/** + * + * @author ruoshan + * @version $Id: CallStackUtil.java, v 0.1 2019年02月13日 11:29 ruoshan Exp $ + */ +public class CallStackUtil { + + public static String getCurrentCallStack() { + StringBuilder msg = new StringBuilder(); + StackTraceElement[] elements = Thread.currentThread().getStackTrace(); + for (int index = 2; index < elements.length; index++) { + msg.append(elements[index].toString()).append("\n"); + } + return msg.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/alipay/hessian/ClassNameResolver.java b/src/main/java/com/alipay/hessian/ClassNameResolver.java index ccd0f0f..eb6b762 100644 --- a/src/main/java/com/alipay/hessian/ClassNameResolver.java +++ b/src/main/java/com/alipay/hessian/ClassNameResolver.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.concurrent.locks.ReentrantLock; /** * 类名处理器,包含一组类名过滤器 @@ -33,14 +33,12 @@ public class ClassNameResolver { /** * 锁 */ - private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - private ReentrantReadWriteLock.ReadLock readLock = lock.readLock(); - private ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock(); + private ReentrantLock lock = new ReentrantLock(); /** * 过滤器列表 */ - List filters = null; + List filters = null; /** * 增加类名过滤器 @@ -48,7 +46,7 @@ public class ClassNameResolver { * @param classNameFilter 类名过滤器t */ public void addFilter(ClassNameFilter classNameFilter) { - writeLock.lock(); + lock.lock(); try { if (filters == null) { filters = new ArrayList(); @@ -61,46 +59,41 @@ public int compare(ClassNameFilter o1, ClassNameFilter o2) { } }); } finally { - writeLock.unlock(); + lock.unlock(); } } /** * 删除类名过滤器 - * + * * @param classNameFilter 类名过滤器 */ public void removeFilter(ClassNameFilter classNameFilter) { - writeLock.lock(); + lock.lock(); try { if (filters != null) { filters.remove(classNameFilter); // 删除不用重新排序 } } finally { - writeLock.unlock(); + lock.unlock(); } } /** * 决定类名 - * + * 这个地方调用非常频繁,读锁也有一定的性能影响。 * @param className 类名 - * @return 过滤器执行后的类名 + * @return */ public String resolve(String className) throws IOException { - readLock.lock(); - try { - if (filters == null || filters.isEmpty()) { - return className; - } - String cls = className; - for (ClassNameFilter filter : filters) { - cls = filter.resolve(cls); - } - return cls; - } finally { - readLock.unlock(); + if (filters == null || filters.isEmpty()) { + return className; + } + String cls = className; + for (ClassNameFilter filter : filters) { + cls = filter.resolve(cls); } + return cls; } } diff --git a/src/main/java/com/alipay/hessian/ClassNameResolverBuilder.java b/src/main/java/com/alipay/hessian/ClassNameResolverBuilder.java index 4c8bde3..39d35e9 100644 --- a/src/main/java/com/alipay/hessian/ClassNameResolverBuilder.java +++ b/src/main/java/com/alipay/hessian/ClassNameResolverBuilder.java @@ -34,7 +34,7 @@ public static ClassNameResolver buildDefault() { String enable = System.getProperty("serialize.blacklist.enable", "true"); if (Boolean.TRUE.toString().equalsIgnoreCase(enable)) { ClassNameResolver resolver = new ClassNameResolver(); - resolver.addFilter(new InternalNameBlackListFilter()); + resolver.addFilter(InternalNameBlackListFilter.Singleton()); return resolver; } return null; diff --git a/src/main/java/com/alipay/hessian/NameBlackListFilter.java b/src/main/java/com/alipay/hessian/NameBlackListFilter.java index c8de670..739b948 100644 --- a/src/main/java/com/alipay/hessian/NameBlackListFilter.java +++ b/src/main/java/com/alipay/hessian/NameBlackListFilter.java @@ -17,6 +17,8 @@ package com.alipay.hessian; import com.alipay.hessian.clhm.ConcurrentLinkedHashMap; +import com.alipay.sofa.common.log.LoggerSpaceManager; +import org.slf4j.Logger; import java.io.IOException; import java.util.List; @@ -27,7 +29,24 @@ * * @author zhanggeng */ -public class NameBlackListFilter implements ClassNameFilter { +public abstract class NameBlackListFilter implements ClassNameFilter { + + private static Logger LOGGER = judgeLogger(); + + //do not change this + public static final String HESSIAN_SERIALIZE_LOG_NAME = "HessianSerializeLog"; + public static final String CONFIG_LOG_SPACE_NAME = "com.alipay.sofa.middleware.config"; + + private static Logger judgeLogger() { + + try { + NameBlackListFilter.class.getClassLoader().loadClass("com.alipay.sofa.middleware.log.ConfigLogFactory"); + } catch (Throwable e) { + //do nothing + return null; + } + return LoggerSpaceManager.getLoggerBySpace(HESSIAN_SERIALIZE_LOG_NAME, CONFIG_LOG_SPACE_NAME); + } /** * 黑名单 包名前缀 @@ -71,9 +90,9 @@ public static void buildCache(List blackPrefixList, int maxCacheSize) { int max = Math.min(10240, maxCacheSize); ConcurrentLinkedHashMap.Builder builder = new ConcurrentLinkedHashMap.Builder() .initialCapacity(min).maximumWeightedCapacity(max); - NameBlackListFilter.resultOfInBlackList = builder.build(); + resultOfInBlackList = builder.build(); } else { - NameBlackListFilter.resultOfInBlackList = null; + resultOfInBlackList = null; } } @@ -85,12 +104,32 @@ public String resolve(String className) throws IOException { if (blackPrefixList == null || resultOfInBlackList == null) { return className; } + final String monitorKey = "@" + className; + Boolean monitorResult = resultOfInBlackList.get(monitorKey); + if (monitorResult == null) { + monitorResult = inBlackList(monitorKey); + resultOfInBlackList.putIfAbsent(monitorKey, monitorResult); + } + + if (monitorResult && LOGGER != null) { + LOGGER.info(String.format( + "[status] %s, [class] %s, [rule] %s, [callStack] %s", + "watch", className, monitorKey, CallStackUtil + .getCurrentCallStack())); + + } + Boolean result = resultOfInBlackList.get(className); if (result == null) { result = inBlackList(className); resultOfInBlackList.putIfAbsent(className, result); } - if (result) { + if (result && LOGGER != null) { + LOGGER.info(String.format( + "[status] %s, [class] %s, [rule] %s, [callStack] %s", + "control", className, className, CallStackUtil + .getCurrentCallStack())); + throw new IOException("Class " + className + " is in blacklist. "); } else { return className; @@ -101,7 +140,7 @@ public String resolve(String className) throws IOException { * 检测类名是否不在黑名单中 * * @param className - * @return 是否在黑名单中 + * @return */ protected boolean inBlackList(String className) { for (String prefix : blackPrefixList) { diff --git a/src/main/java/com/alipay/hessian/internal/InternalNameBlackListFilter.java b/src/main/java/com/alipay/hessian/internal/InternalNameBlackListFilter.java index d08daa1..d599ff5 100644 --- a/src/main/java/com/alipay/hessian/internal/InternalNameBlackListFilter.java +++ b/src/main/java/com/alipay/hessian/internal/InternalNameBlackListFilter.java @@ -103,4 +103,21 @@ static boolean isBlank(String cs) { } return true; } + + /** + * 单例 + */ + private volatile static InternalNameBlackListFilter instance; + + public static InternalNameBlackListFilter Singleton() { + if (instance == null) { //step1 + synchronized (InternalNameBlackListFilter.class) { //step2 + if (instance == null) { //step3 + instance = new InternalNameBlackListFilter(); //step4 + } + } + } + + return instance; + } } From 2dc2b43cf72ab8a0c0a7e31dbe90c77afa97daec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A2=A7=E8=BF=9C?= Date: Thu, 16 Apr 2020 15:33:37 +0800 Subject: [PATCH 2/8] chore:update hessian 3.3.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 127e536..3b225a1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.alipay.sofa hessian - 3.3.7 + 3.3.8 jar ${project.groupId}:${project.artifactId} From d7490509f81a344bc90d4530f7acd0bb0e76ae8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A2=A7=E8=BF=9C?= Date: Thu, 16 Apr 2020 15:41:58 +0800 Subject: [PATCH 3/8] chore:update maven settings --- tools/ci/.travis.settings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ci/.travis.settings.xml b/tools/ci/.travis.settings.xml index ddd1cfe..07e3075 100644 --- a/tools/ci/.travis.settings.xml +++ b/tools/ci/.travis.settings.xml @@ -14,7 +14,7 @@ central Central Repository - http://repo1.maven.org/maven2 + https://repo1.maven.org/maven2 true always @@ -108,7 +108,7 @@ central - http://repo1.maven.org/maven2 + https://repo1.maven.org/maven2 true always From ea2c8d2e230d11dfc51b9b999abbffab785dddd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A2=A7=E8=BF=9C?= Date: Thu, 16 Apr 2020 15:57:32 +0800 Subject: [PATCH 4/8] feat:fix bug --- .../com/alipay/hessian/ClassNameResolver.java | 39 +++++++++++-------- .../alipay/hessian/NameBlackListFilter.java | 7 ++-- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/alipay/hessian/ClassNameResolver.java b/src/main/java/com/alipay/hessian/ClassNameResolver.java index eb6b762..041c31f 100644 --- a/src/main/java/com/alipay/hessian/ClassNameResolver.java +++ b/src/main/java/com/alipay/hessian/ClassNameResolver.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; /** * 类名处理器,包含一组类名过滤器 @@ -33,12 +33,14 @@ public class ClassNameResolver { /** * 锁 */ - private ReentrantLock lock = new ReentrantLock(); + private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + private ReentrantReadWriteLock.ReadLock readLock = lock.readLock(); + private ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock(); /** * 过滤器列表 */ - List filters = null; + List filters = null; /** * 增加类名过滤器 @@ -46,7 +48,7 @@ public class ClassNameResolver { * @param classNameFilter 类名过滤器t */ public void addFilter(ClassNameFilter classNameFilter) { - lock.lock(); + writeLock.lock(); try { if (filters == null) { filters = new ArrayList(); @@ -59,7 +61,7 @@ public int compare(ClassNameFilter o1, ClassNameFilter o2) { } }); } finally { - lock.unlock(); + writeLock.unlock(); } } @@ -69,31 +71,36 @@ public int compare(ClassNameFilter o1, ClassNameFilter o2) { * @param classNameFilter 类名过滤器 */ public void removeFilter(ClassNameFilter classNameFilter) { - lock.lock(); + writeLock.lock(); try { if (filters != null) { filters.remove(classNameFilter); // 删除不用重新排序 } } finally { - lock.unlock(); + writeLock.unlock(); } } /** * 决定类名 - * 这个地方调用非常频繁,读锁也有一定的性能影响。 + * * @param className 类名 - * @return + * @return 过滤器执行后的类名 */ public String resolve(String className) throws IOException { - if (filters == null || filters.isEmpty()) { - return className; - } - String cls = className; - for (ClassNameFilter filter : filters) { - cls = filter.resolve(cls); + readLock.lock(); + try { + if (filters == null || filters.isEmpty()) { + return className; + } + String cls = className; + for (ClassNameFilter filter : filters) { + cls = filter.resolve(cls); + } + return cls; + } finally { + readLock.unlock(); } - return cls; } } diff --git a/src/main/java/com/alipay/hessian/NameBlackListFilter.java b/src/main/java/com/alipay/hessian/NameBlackListFilter.java index 739b948..68b2dc2 100644 --- a/src/main/java/com/alipay/hessian/NameBlackListFilter.java +++ b/src/main/java/com/alipay/hessian/NameBlackListFilter.java @@ -17,7 +17,6 @@ package com.alipay.hessian; import com.alipay.hessian.clhm.ConcurrentLinkedHashMap; -import com.alipay.sofa.common.log.LoggerSpaceManager; import org.slf4j.Logger; import java.io.IOException; @@ -40,12 +39,14 @@ public abstract class NameBlackListFilter implements ClassNameFilter { private static Logger judgeLogger() { try { - NameBlackListFilter.class.getClassLoader().loadClass("com.alipay.sofa.middleware.log.ConfigLogFactory"); + NameBlackListFilter.class.getClassLoader().loadClass("com.alipay.sofa.common.log.LoggerSpaceManager"); } catch (Throwable e) { //do nothing return null; } - return LoggerSpaceManager.getLoggerBySpace(HESSIAN_SERIALIZE_LOG_NAME, CONFIG_LOG_SPACE_NAME); + + return com.alipay.sofa.common.log.LoggerSpaceManager.getLoggerBySpace(HESSIAN_SERIALIZE_LOG_NAME, + CONFIG_LOG_SPACE_NAME); } /** From 3017cbe67e5e1535758df43bb180ab7c1f90507f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A2=A7=E8=BF=9C?= Date: Thu, 16 Apr 2020 16:08:32 +0800 Subject: [PATCH 5/8] test:fix test --- src/test/java/com/alipay/stc/ArrayInjectTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/alipay/stc/ArrayInjectTest.java b/src/test/java/com/alipay/stc/ArrayInjectTest.java index 3e537f7..e103f88 100644 --- a/src/test/java/com/alipay/stc/ArrayInjectTest.java +++ b/src/test/java/com/alipay/stc/ArrayInjectTest.java @@ -40,10 +40,9 @@ public void testHessian2Array() throws IOException { ByteArrayInputStream input = new ByteArrayInputStream(bs, 0, bs.length); Hessian2Input hin = new Hessian2Input(input); hin.setSerializerFactory(factory); - try { hin.readObject(); - Assert.fail(); + Assert.fail("should be intercepted"); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); } From 800377a359f7be0bf14f40970f79dccb7cfc1181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A2=A7=E8=BF=9C?= Date: Thu, 16 Apr 2020 16:25:01 +0800 Subject: [PATCH 6/8] test:fix test --- src/test/java/com/alipay/stc/Hessian1BlackListTest.java | 8 ++++++++ src/test/java/com/alipay/stc/Hessian2BlackListTest.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/test/java/com/alipay/stc/Hessian1BlackListTest.java b/src/test/java/com/alipay/stc/Hessian1BlackListTest.java index 5a1b56d..0c2b94e 100644 --- a/src/test/java/com/alipay/stc/Hessian1BlackListTest.java +++ b/src/test/java/com/alipay/stc/Hessian1BlackListTest.java @@ -18,11 +18,13 @@ import com.alipay.hessian.ClassNameResolver; import com.alipay.hessian.NameBlackListFilter; +import com.alipay.hessian.internal.InternalNameBlackListFilter; import com.alipay.stc.bl.MockNameBlacklistFilter; import com.alipay.stc.bl.TestBlackBean; import com.caucho.hessian.io.HessianInput; import com.caucho.hessian.io.HessianOutput; import com.caucho.hessian.io.SerializerFactory; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -53,6 +55,12 @@ public static void init() { serializerFactory.setClassNameResolver(resolver); } + //reset + @AfterClass + public static void afterClass() { + InternalNameBlackListFilter nameBlackListFilter = new InternalNameBlackListFilter(); + } + @Test public void testBeanSerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); diff --git a/src/test/java/com/alipay/stc/Hessian2BlackListTest.java b/src/test/java/com/alipay/stc/Hessian2BlackListTest.java index 4070315..8152aed 100644 --- a/src/test/java/com/alipay/stc/Hessian2BlackListTest.java +++ b/src/test/java/com/alipay/stc/Hessian2BlackListTest.java @@ -18,11 +18,13 @@ import com.alipay.hessian.ClassNameResolver; import com.alipay.hessian.NameBlackListFilter; +import com.alipay.hessian.internal.InternalNameBlackListFilter; import com.alipay.stc.bl.MockNameBlacklistFilter; import com.alipay.stc.bl.TestBlackBean; import com.caucho.hessian.io.Hessian2Input; import com.caucho.hessian.io.Hessian2Output; import com.caucho.hessian.io.SerializerFactory; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -53,6 +55,12 @@ public static void init() { serializerFactory.setClassNameResolver(resolver); } + //reset + @AfterClass + public static void afterClass() { + InternalNameBlackListFilter nameBlackListFilter = new InternalNameBlackListFilter(); + } + @Test public void testBeanSerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); From bf61a6b1690c246a5a03a042bfee1a84d20b59fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A2=A7=E8=BF=9C?= Date: Thu, 16 Apr 2020 18:10:08 +0800 Subject: [PATCH 7/8] feat:black list --- .../alipay/hessian/NameBlackListFilter.java | 31 +++++++++++++++---- .../hessian/NameBlackListFilterManager.java | 2 +- .../com/alipay/stc/Hessian1BlackListTest.java | 6 ---- .../com/alipay/stc/Hessian2BlackListTest.java | 6 ---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/alipay/hessian/NameBlackListFilter.java b/src/main/java/com/alipay/hessian/NameBlackListFilter.java index 68b2dc2..9179e04 100644 --- a/src/main/java/com/alipay/hessian/NameBlackListFilter.java +++ b/src/main/java/com/alipay/hessian/NameBlackListFilter.java @@ -52,7 +52,12 @@ private static Logger judgeLogger() { /** * 黑名单 包名前缀 */ - protected static List blackPrefixList; + protected List blackPrefixList; + + /** + * 黑名单 包名前缀 + */ + protected static List addBlackPrefixList; /** * 类名是否在黑名单中结果缓存。{className:true/false} @@ -75,7 +80,7 @@ public NameBlackListFilter(List blackPrefixList) { * @param maxCacheSize 最大缓存大小 */ public NameBlackListFilter(List blackPrefixList, int maxCacheSize) { - NameBlackListFilter.blackPrefixList = blackPrefixList; + this.blackPrefixList = blackPrefixList; buildCache(blackPrefixList, maxCacheSize); } @@ -86,7 +91,6 @@ public NameBlackListFilter(List blackPrefixList, int maxCacheSize) { */ public static void buildCache(List blackPrefixList, int maxCacheSize) { if (blackPrefixList != null && !blackPrefixList.isEmpty()) { - NameBlackListFilter.blackPrefixList = blackPrefixList; int min = Math.min(256, maxCacheSize); int max = Math.min(10240, maxCacheSize); ConcurrentLinkedHashMap.Builder builder = new ConcurrentLinkedHashMap.Builder() @@ -144,11 +148,26 @@ public String resolve(String className) throws IOException { * @return */ protected boolean inBlackList(String className) { - for (String prefix : blackPrefixList) { - if (className.startsWith(prefix)) { - return Boolean.TRUE; + + //动态推送不允许推空,推送一个白名单的值即可 + if (addBlackPrefixList != null && addBlackPrefixList.size() != 0) { + for (String prefix : addBlackPrefixList) { + if (className.startsWith(prefix)) { + return Boolean.TRUE; + } + } + } else { + for (String prefix : blackPrefixList) { + if (className.startsWith(prefix)) { + return Boolean.TRUE; + } } } + return Boolean.FALSE; } + + public static void setAddBlackPrefixList(List addBlackPrefixList) { + NameBlackListFilter.addBlackPrefixList = addBlackPrefixList; + } } diff --git a/src/main/java/com/alipay/hessian/NameBlackListFilterManager.java b/src/main/java/com/alipay/hessian/NameBlackListFilterManager.java index 1879e77..b10a3a9 100644 --- a/src/main/java/com/alipay/hessian/NameBlackListFilterManager.java +++ b/src/main/java/com/alipay/hessian/NameBlackListFilterManager.java @@ -25,6 +25,6 @@ public class NameBlackListFilterManager { */ public static void rebuildBlackList(List blackList) { - NameBlackListFilter.buildCache(blackList, 4096); + NameBlackListFilter.setAddBlackPrefixList(blackList); } } diff --git a/src/test/java/com/alipay/stc/Hessian1BlackListTest.java b/src/test/java/com/alipay/stc/Hessian1BlackListTest.java index 0c2b94e..b65f3df 100644 --- a/src/test/java/com/alipay/stc/Hessian1BlackListTest.java +++ b/src/test/java/com/alipay/stc/Hessian1BlackListTest.java @@ -55,12 +55,6 @@ public static void init() { serializerFactory.setClassNameResolver(resolver); } - //reset - @AfterClass - public static void afterClass() { - InternalNameBlackListFilter nameBlackListFilter = new InternalNameBlackListFilter(); - } - @Test public void testBeanSerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); diff --git a/src/test/java/com/alipay/stc/Hessian2BlackListTest.java b/src/test/java/com/alipay/stc/Hessian2BlackListTest.java index 8152aed..6c41c9a 100644 --- a/src/test/java/com/alipay/stc/Hessian2BlackListTest.java +++ b/src/test/java/com/alipay/stc/Hessian2BlackListTest.java @@ -55,12 +55,6 @@ public static void init() { serializerFactory.setClassNameResolver(resolver); } - //reset - @AfterClass - public static void afterClass() { - InternalNameBlackListFilter nameBlackListFilter = new InternalNameBlackListFilter(); - } - @Test public void testBeanSerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); From c73e4846e715bff73de75ccbeeabc866b90df481 Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Thu, 16 Apr 2020 18:21:52 +0800 Subject: [PATCH 8/8] add comment --- src/main/java/com/alipay/hessian/NameBlackListFilter.java | 2 +- src/test/java/com/alipay/stc/Hessian1BlackListTest.java | 2 -- src/test/java/com/alipay/stc/Hessian2BlackListTest.java | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/alipay/hessian/NameBlackListFilter.java b/src/main/java/com/alipay/hessian/NameBlackListFilter.java index 9179e04..c84c72f 100644 --- a/src/main/java/com/alipay/hessian/NameBlackListFilter.java +++ b/src/main/java/com/alipay/hessian/NameBlackListFilter.java @@ -55,7 +55,7 @@ private static Logger judgeLogger() { protected List blackPrefixList; /** - * 黑名单 包名前缀 + * 全局黑名单 包名前缀, 优先级高于上者 */ protected static List addBlackPrefixList; diff --git a/src/test/java/com/alipay/stc/Hessian1BlackListTest.java b/src/test/java/com/alipay/stc/Hessian1BlackListTest.java index b65f3df..5a1b56d 100644 --- a/src/test/java/com/alipay/stc/Hessian1BlackListTest.java +++ b/src/test/java/com/alipay/stc/Hessian1BlackListTest.java @@ -18,13 +18,11 @@ import com.alipay.hessian.ClassNameResolver; import com.alipay.hessian.NameBlackListFilter; -import com.alipay.hessian.internal.InternalNameBlackListFilter; import com.alipay.stc.bl.MockNameBlacklistFilter; import com.alipay.stc.bl.TestBlackBean; import com.caucho.hessian.io.HessianInput; import com.caucho.hessian.io.HessianOutput; import com.caucho.hessian.io.SerializerFactory; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/com/alipay/stc/Hessian2BlackListTest.java b/src/test/java/com/alipay/stc/Hessian2BlackListTest.java index 6c41c9a..4070315 100644 --- a/src/test/java/com/alipay/stc/Hessian2BlackListTest.java +++ b/src/test/java/com/alipay/stc/Hessian2BlackListTest.java @@ -18,13 +18,11 @@ import com.alipay.hessian.ClassNameResolver; import com.alipay.hessian.NameBlackListFilter; -import com.alipay.hessian.internal.InternalNameBlackListFilter; import com.alipay.stc.bl.MockNameBlacklistFilter; import com.alipay.stc.bl.TestBlackBean; import com.caucho.hessian.io.Hessian2Input; import com.caucho.hessian.io.Hessian2Output; import com.caucho.hessian.io.SerializerFactory; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test;