Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
Lo1nt committed Jan 8, 2024
2 parents c7a474d + 7980b1f commit bcf0d88
Show file tree
Hide file tree
Showing 30 changed files with 1,221 additions and 34 deletions.
6 changes: 6 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@
<artifactId>sofa-rpc-codec-jackson</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-codec-sofa-fury</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-fault-tolerance</artifactId>
Expand Down Expand Up @@ -519,6 +524,7 @@
<include>com.alipay.sofa:sofa-rpc-codec-jackson</include>
<include>com.alipay.sofa:sofa-rpc-codec-msgpack</include>
<include>com.alipay.sofa:sofa-rpc-codec-sofa-hessian</include>
<include>com.alipay.sofa:sofa-rpc-codec-sofa-fury</include>
<include>com.alipay.sofa:sofa-rpc-fault-tolerance</include>
<include>com.alipay.sofa:sofa-rpc-fault-hystrix</include>
<include>com.alipay.sofa:sofa-rpc-log-common-tools</include>
Expand Down
6 changes: 6 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<jackson.databind.version>2.12.7.1</jackson.databind.version>
<msgpack.version>0.6.12</msgpack.version>
<protostuff.version>1.5.9</protostuff.version>
<fury.version>0.4.1</fury.version>
<grpc.version>1.53.0</grpc.version>

<!--common-->
Expand Down Expand Up @@ -298,6 +299,11 @@
<artifactId>msgpack</artifactId>
<version>${msgpack.version}</version>
</dependency>
<dependency>
<groupId>org.furyio</groupId>
<artifactId>fury-core</artifactId>
<version>${fury.version}</version>
</dependency>
<!-- zk client -->
<dependency>
<groupId>org.apache.curator</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
*
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
}
}
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;
}
}
46 changes: 46 additions & 0 deletions codec/codec-sofa-fury/pom.xml
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>
Loading

0 comments on commit bcf0d88

Please sign in to comment.