Skip to content
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 @@ -29,6 +29,8 @@

import lombok.Data;

import org.apache.hugegraph.pd.raft.serializer.HugegraphHessianSerializerFactory;

@Data
public class KVOperation {

Expand Down Expand Up @@ -84,6 +86,7 @@ public static KVOperation fromByteArray(byte[] value) throws IOException {

try (ByteArrayInputStream bis = new ByteArrayInputStream(value, 1, value.length - 1)) {
Hessian2Input input = new Hessian2Input(bis);
input.setSerializerFactory(HugegraphHessianSerializerFactory.getInstance());
KVOperation op = new KVOperation();
op.op = value[0];
op.key = input.readBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.Metapb;
import org.apache.hugegraph.pd.grpc.Pdpb;
import org.apache.hugegraph.pd.raft.auth.IpAuthHandler;

import com.alipay.remoting.ExtendedNettyChannelHandler;
import com.alipay.remoting.config.BoltServerOption;
import com.alipay.sofa.jraft.JRaftUtils;
import com.alipay.sofa.jraft.Node;
import com.alipay.sofa.jraft.RaftGroupService;
Expand All @@ -47,10 +52,12 @@
import com.alipay.sofa.jraft.option.RpcOptions;
import com.alipay.sofa.jraft.rpc.RaftRpcServerFactory;
import com.alipay.sofa.jraft.rpc.RpcServer;
import com.alipay.sofa.jraft.rpc.impl.BoltRpcServer;
import com.alipay.sofa.jraft.util.Endpoint;
import com.alipay.sofa.jraft.util.ThreadId;
import com.alipay.sofa.jraft.util.internal.ThrowUtil;

import io.netty.channel.ChannelHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down Expand Up @@ -117,7 +124,7 @@ public boolean init(PDConfig.Raft config) {

final PeerId serverId = JRaftUtils.getPeerId(config.getAddress());

rpcServer = createRaftRpcServer(config.getAddress());
rpcServer = createRaftRpcServer(config.getAddress(), initConf.getPeers());
// construct raft group and start raft
this.raftGroupService =
new RaftGroupService(groupId, serverId, nodeOptions, rpcServer, true);
Expand All @@ -130,14 +137,40 @@ public boolean init(PDConfig.Raft config) {
/**
* Create a Raft RPC Server for communication between PDs
*/
private RpcServer createRaftRpcServer(String raftAddr) {
private RpcServer createRaftRpcServer(String raftAddr, List<PeerId> peers) {
Endpoint endpoint = JRaftUtils.getEndPoint(raftAddr);
RpcServer rpcServer = RaftRpcServerFactory.createRaftRpcServer(endpoint);
configureRaftServerIpWhitelist(peers, rpcServer);
Copy link
Contributor

@zyxxoo zyxxoo Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the raft group member change? If the raft member changed, the whiteList ip should been sync changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1、The whitelist IPs are sourced from the peer-list configuration file. The current solution rejects all Raft-related requests from nodes not in the peer-list.
2、I understand that the members of the Raft group are a subset of the peer-list. Please correct me if there are any errors in this understanding.
thanks

RaftRpcProcessor.registerProcessor(rpcServer, this);
rpcServer.init(null);
return rpcServer;
}

private static void configureRaftServerIpWhitelist(List<PeerId> peers, RpcServer rpcServer) {
if (rpcServer instanceof BoltRpcServer) {
((BoltRpcServer) rpcServer).getServer().option(
BoltServerOption.EXTENDED_NETTY_CHANNEL_HANDLER,
new ExtendedNettyChannelHandler() {
@Override
public List<ChannelHandler> frontChannelHandlers() {
return Collections.singletonList(
IpAuthHandler.getInstance(
peers.stream()
.map(PeerId::getIp)
.collect(Collectors.toSet())
)
);
}

@Override
public List<ChannelHandler> backChannelHandlers() {
return Collections.emptyList();
}
}
);
}
}

public void shutDown() {
if (this.raftGroupService != null) {
this.raftGroupService.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void onApply(Iterator iter) {
done.run(Status.OK());
}
} catch (Throwable t) {
log.error("StateMachine meet critical error: {}.", t);
log.error("StateMachine encountered critical error", t);
if (done != null) {
done.run(new Status(RaftError.EINTERNAL, t.getMessage()));
}
Expand All @@ -101,7 +101,7 @@ public void onApply(Iterator iter) {

@Override
public void onError(final RaftException e) {
log.error("Raft StateMachine on error {}", e);
log.error("Raft StateMachine encountered an error", e);
}

@Override
Expand All @@ -117,9 +117,7 @@ public void onLeaderStart(final long term) {
log.info("Raft becomes leader");
Utils.runInThread(() -> {
if (!CollectionUtils.isEmpty(stateListeners)) {
stateListeners.forEach(listener -> {
listener.onRaftLeaderChanged();
});
stateListeners.forEach(RaftStateListener::onRaftLeaderChanged);
}
});
}
Expand All @@ -136,9 +134,7 @@ public void onStartFollowing(final LeaderChangeContext ctx) {
super.onStartFollowing(ctx);
Utils.runInThread(() -> {
if (!CollectionUtils.isEmpty(stateListeners)) {
stateListeners.forEach(listener -> {
listener.onRaftLeaderChanged();
});
stateListeners.forEach(RaftStateListener::onRaftLeaderChanged);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.hugegraph.pd.raft.auth;

import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.Set;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j

Check warning on line 29 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L29

Added line #L29 was not covered by tests
@ChannelHandler.Sharable
public class IpAuthHandler extends ChannelDuplexHandler {

private final Set<String> allowedIps;
private static volatile IpAuthHandler instance;

private IpAuthHandler(Set<String> allowedIps) {
this.allowedIps = Collections.unmodifiableSet(allowedIps);
}

Check warning on line 38 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L36-L38

Added lines #L36 - L38 were not covered by tests

public static IpAuthHandler getInstance(Set<String> allowedIps) {
if (instance == null) {
synchronized (IpAuthHandler.class) {

Check warning on line 42 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L42

Added line #L42 was not covered by tests
if (instance == null) {
instance = new IpAuthHandler(allowedIps);

Check warning on line 44 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L44

Added line #L44 was not covered by tests
}
}

Check warning on line 46 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L46

Added line #L46 was not covered by tests
}
return instance;

Check warning on line 48 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L48

Added line #L48 was not covered by tests
}

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
String clientIp = getClientIp(ctx);

Check warning on line 53 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L53

Added line #L53 was not covered by tests
if (!isIpAllowed(clientIp)) {
log.warn("Blocked connection from {}", clientIp);
ctx.close();
return;

Check warning on line 57 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L55-L57

Added lines #L55 - L57 were not covered by tests
}
super.channelActive(ctx);
}

Check warning on line 60 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L59-L60

Added lines #L59 - L60 were not covered by tests

private static String getClientIp(ChannelHandlerContext ctx) {
InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
return remoteAddress.getAddress().getHostAddress();

Check warning on line 64 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L63-L64

Added lines #L63 - L64 were not covered by tests
}

private boolean isIpAllowed(String ip) {
return allowedIps.isEmpty() || allowedIps.contains(ip);
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
String clientIp = getClientIp(ctx);
log.warn("Client : {} connection exception : {}", clientIp, cause);

Check warning on line 74 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L73-L74

Added lines #L73 - L74 were not covered by tests
if (ctx.channel().isActive()) {
ctx.close().addListener(future -> {

Check warning on line 76 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L76

Added line #L76 was not covered by tests
if (!future.isSuccess()) {
log.warn("Client: {} connection closed failed: {}",
clientIp, future.cause().getMessage());

Check warning on line 79 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L78-L79

Added lines #L78 - L79 were not covered by tests
}
});

Check warning on line 81 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L81

Added line #L81 was not covered by tests
}
}

Check warning on line 83 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/auth/IpAuthHandler.java#L83

Added line #L83 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* 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.hugegraph.pd.raft.serializer;

import com.caucho.hessian.io.Deserializer;
import com.caucho.hessian.io.HessianProtocolException;
import com.caucho.hessian.io.Serializer;
import com.caucho.hessian.io.SerializerFactory;


import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

@Slf4j

Check warning on line 55 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L55

Added line #L55 was not covered by tests
public class HugegraphHessianSerializerFactory extends SerializerFactory {

private static final HugegraphHessianSerializerFactory INSTANCE = new HugegraphHessianSerializerFactory();

Check warning on line 58 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L58

Added line #L58 was not covered by tests

private HugegraphHessianSerializerFactory() {
super();
initWhitelist();
}

Check warning on line 63 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L61-L63

Added lines #L61 - L63 were not covered by tests

public static HugegraphHessianSerializerFactory getInstance() {
return INSTANCE;

Check warning on line 66 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L66

Added line #L66 was not covered by tests
}

private final Set<String> whitelist = new HashSet<>();

Check warning on line 69 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L69

Added line #L69 was not covered by tests

private void initWhitelist() {
allowBasicType();
allowCollections();
allowConcurrent();
allowTime();
allowBusinessClasses();
}

Check warning on line 77 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L72-L77

Added lines #L72 - L77 were not covered by tests

private void allowBasicType() {
addToWhitelist(

Check warning on line 80 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L80

Added line #L80 was not covered by tests
boolean.class, byte.class, char.class, double.class,
float.class, int.class, long.class, short.class,
Boolean.class, Byte.class, Character.class, Double.class,
Float.class, Integer.class, Long.class, Short.class,
String.class, Class.class, Number.class
);
}

Check warning on line 87 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L87

Added line #L87 was not covered by tests

private void allowCollections() {
addToWhitelist(

Check warning on line 90 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L90

Added line #L90 was not covered by tests
List.class, ArrayList.class, LinkedList.class,
Set.class, HashSet.class, LinkedHashSet.class, TreeSet.class,
Map.class, HashMap.class, LinkedHashMap.class, TreeMap.class
);
}

Check warning on line 95 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L95

Added line #L95 was not covered by tests

private void allowConcurrent() {
addToWhitelist(

Check warning on line 98 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L98

Added line #L98 was not covered by tests
AtomicBoolean.class, AtomicInteger.class, AtomicLong.class, AtomicReference.class,
ConcurrentMap.class, ConcurrentHashMap.class, ConcurrentSkipListMap.class, CopyOnWriteArrayList.class
);
}

Check warning on line 102 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L102

Added line #L102 was not covered by tests

private void allowTime() {
addToWhitelist(

Check warning on line 105 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L105

Added line #L105 was not covered by tests
Date.class, Calendar.class, TimeUnit.class,
SimpleDateFormat.class, DateTimeFormatter.class
);
tryAddClass("java.time.LocalDate");
tryAddClass("java.time.LocalDateTime");
tryAddClass("java.time.Instant");
}

Check warning on line 112 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L109-L112

Added lines #L109 - L112 were not covered by tests

private void allowBusinessClasses() {
addToWhitelist(

Check warning on line 115 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L115

Added line #L115 was not covered by tests
org.apache.hugegraph.pd.raft.KVOperation.class,
byte[].class
);
}

Check warning on line 119 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L119

Added line #L119 was not covered by tests

private void addToWhitelist(Class<?>... classes) {
for (Class<?> clazz : classes) {
whitelist.add(clazz.getName());

Check warning on line 123 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L123

Added line #L123 was not covered by tests
}
}

Check warning on line 125 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L125

Added line #L125 was not covered by tests

private void tryAddClass(String className) {
try {
Class.forName(className);
whitelist.add(className);
} catch (ClassNotFoundException e) {
log.warn("Failed to load class {}", className);
}
}

Check warning on line 134 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L129-L134

Added lines #L129 - L134 were not covered by tests

@Override
public Serializer getSerializer(Class cl) throws HessianProtocolException {
checkWhitelist(cl);
return super.getSerializer(cl);

Check warning on line 139 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L138-L139

Added lines #L138 - L139 were not covered by tests
}

@Override
public Deserializer getDeserializer(Class cl) throws HessianProtocolException {
checkWhitelist(cl);
return super.getDeserializer(cl);

Check warning on line 145 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L144-L145

Added lines #L144 - L145 were not covered by tests
}

private void checkWhitelist(Class cl) {
String className = cl.getName();

Check warning on line 149 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L149

Added line #L149 was not covered by tests
if (!whitelist.contains(className)) {
log.warn("Security alert: Blocked unauthorized class [{}] at {}",

Check warning on line 151 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L151

Added line #L151 was not covered by tests
className, new Date());
throw new SecurityException("hessian serialize unauthorized class: " + className);

Check warning on line 153 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L153

Added line #L153 was not covered by tests
}
}

Check warning on line 155 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/serializer/HugegraphHessianSerializerFactory.java#L155

Added line #L155 was not covered by tests
}
Loading