forked from sofastack/sofa-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fury serializer (sofastack#1348)
* add FurySerializer --------- Co-authored-by: pankoli <[email protected]> Co-authored-by: liujianjun.ljj <[email protected]> Co-authored-by: Lo1nt <[email protected]>
- Loading branch information
1 parent
1e99afb
commit 7980b1f
Showing
30 changed files
with
1,221 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,9 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.rpc.codec.sofahessian; | ||
package com.alipay.sofa.rpc.codec.common; | ||
|
||
import com.alipay.sofa.rpc.common.SofaConfigs; | ||
import com.alipay.sofa.rpc.common.SofaOptions; | ||
import com.alipay.sofa.common.config.SofaConfigs; | ||
import com.alipay.sofa.rpc.common.utils.StringUtils; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
|
@@ -30,28 +29,33 @@ | |
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import static com.alipay.sofa.rpc.common.config.RpcConfigKeys.SERIALIZE_BLACKLIST_OVERRIDE; | ||
import static com.alipay.sofa.rpc.common.config.RpcConfigKeys.SERIALIZE_WHITELIST_OVERRIDE; | ||
import static com.alipay.sofa.rpc.common.utils.IOUtils.closeQuietly; | ||
|
||
/** | ||
* Load blacklist from file. | ||
* | ||
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
public class BlackListFileLoader { | ||
public class BlackAndWhiteListFileLoader { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(BlackListFileLoader.class); | ||
private static final Logger LOGGER = LoggerFactory | ||
.getLogger(BlackAndWhiteListFileLoader.class); | ||
|
||
public static final List<String> SOFA_SERIALIZE_BLACK_LIST = loadFile("/sofa-rpc/serialize_blacklist.txt"); | ||
public static final List<String> SOFA_SERIALIZE_BLACK_LIST = loadBlackListFile("/sofa-rpc/serialize_blacklist.txt"); | ||
|
||
static List<String> loadFile(String path) { | ||
List<String> blackPrefixList = new ArrayList<String>(); | ||
public static final List<String> SOFA_SERIALIZER_WHITE_LIST = loadWhiteListFile("/sofa-rpc/serialize_whitelist.txt"); | ||
|
||
public static List<String> loadBlackListFile(String path) { | ||
List<String> blackPrefixList = new ArrayList<>(); | ||
InputStream input = null; | ||
try { | ||
input = BlackListFileLoader.class.getResourceAsStream(path); | ||
input = BlackAndWhiteListFileLoader.class.getResourceAsStream(path); | ||
if (input != null) { | ||
readToList(input, "UTF-8", blackPrefixList); | ||
} | ||
String overStr = SofaConfigs.getStringValue(SofaOptions.CONFIG_SERIALIZE_BLACKLIST_OVERRIDE, ""); | ||
String overStr = SofaConfigs.getOrCustomDefault(SERIALIZE_BLACKLIST_OVERRIDE, ""); | ||
if (StringUtils.isNotBlank(overStr)) { | ||
if (LOGGER.isInfoEnabled()) { | ||
LOGGER.info("Serialize blacklist will override with configuration: {}", overStr); | ||
|
@@ -68,6 +72,31 @@ static List<String> loadFile(String path) { | |
return blackPrefixList; | ||
} | ||
|
||
public static List<String> loadWhiteListFile(String path) { | ||
List<String> whitePrefixList = new ArrayList<>(); | ||
InputStream input = null; | ||
try { | ||
input = BlackAndWhiteListFileLoader.class.getResourceAsStream(path); | ||
if (input != null) { | ||
readToList(input, "UTF-8", whitePrefixList); | ||
} | ||
String overStr = SofaConfigs.getOrCustomDefault(SERIALIZE_WHITELIST_OVERRIDE, ""); | ||
if (StringUtils.isNotBlank(overStr)) { | ||
if (LOGGER.isInfoEnabled()) { | ||
LOGGER.info("Serialize whitelist will override with configuration: {}", overStr); | ||
} | ||
overrideWhiteList(whitePrefixList, overStr); | ||
} | ||
} catch (Exception e) { | ||
if (LOGGER.isErrorEnabled()) { | ||
LOGGER.error(e.getMessage(), e); | ||
} | ||
} finally { | ||
closeQuietly(input); | ||
} | ||
return whitePrefixList; | ||
} | ||
|
||
/** | ||
* 读文件,将结果丢入List | ||
* | ||
|
@@ -100,12 +129,12 @@ private static void readToList(InputStream input, String encoding, List<String> | |
|
||
/** | ||
* Override blacklist with override string. | ||
* | ||
* @param originList Origin black list | ||
* | ||
* @param originList Origin black list | ||
* @param overrideStr The override string | ||
*/ | ||
static void overrideBlackList(List<String> originList, String overrideStr) { | ||
List<String> adds = new LinkedList<String>(); | ||
public static void overrideBlackList(List<String> originList, String overrideStr) { | ||
List<String> adds = new LinkedList<>(); | ||
String[] overrideItems = StringUtils.splitWithCommaOrSemicolon(overrideStr); | ||
for (String overrideItem : overrideItems) { | ||
if (StringUtils.isNotBlank(overrideItem)) { | ||
|
@@ -127,4 +156,19 @@ static void overrideBlackList(List<String> originList, String overrideStr) { | |
originList.addAll(adds); | ||
} | ||
} | ||
|
||
public static void overrideWhiteList(List<String> originList, String overrideStr) { | ||
List<String> adds = new LinkedList<>(); | ||
String[] overrideItems = StringUtils.splitWithCommaOrSemicolon(overrideStr); | ||
for (String overrideItem : overrideItems) { | ||
if (StringUtils.isNotBlank(overrideItem)) { | ||
if (!originList.contains(overrideItem)) { | ||
adds.add(overrideItem); | ||
} | ||
} | ||
} | ||
if (adds.size() > 0) { | ||
originList.addAll(adds); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
codec/codec-api/src/main/java/com/alipay/sofa/rpc/codec/common/SerializeCheckStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.sofa.rpc.codec.common; | ||
|
||
/** | ||
* @author Even | ||
* @date 2024/1/5 19:12 | ||
*/ | ||
public enum SerializeCheckStatus { | ||
/** | ||
* Disable serialize check for all classes | ||
*/ | ||
DISABLE(0), | ||
|
||
/** | ||
* Only deny danger classes, warn if other classes are not in allow list | ||
*/ | ||
WARN(1), | ||
|
||
/** | ||
* Only allow classes in allow list, deny if other classes are not in allow list | ||
*/ | ||
STRICT(2); | ||
|
||
private final int mode; | ||
|
||
SerializeCheckStatus(int mode) { | ||
this.mode = mode; | ||
} | ||
|
||
public int getSerializeCheckMode() { | ||
return mode; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-codec</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>sofa-rpc-codec-sofa-fury</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-codec-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-log</artifactId> | ||
</dependency> | ||
|
||
<!-- 默认不主动依赖 --> | ||
<dependency> | ||
<groupId>org.furyio</groupId> | ||
<artifactId>fury-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.