1、服务端SDK支持IP黑名单拦截

2、优化代码注释和升级依赖组件版本
This commit is contained in:
xia jun 2025-03-29 13:19:39 +08:00
parent 965abd1467
commit 4a68b47fdb
2 changed files with 30 additions and 2 deletions

View File

@ -0,0 +1,25 @@
package com.farsunset.cim.component.predicate;
import org.springframework.stereotype.Component;
import java.util.function.Predicate;
@Component
public class BlacklistPredicate implements Predicate<String> {
/**
* IP黑名单拦截处理
* @param remoteAddress IP地址
* @return true:不拦截 false:拦截
*/
@Override
public boolean test(String remoteAddress) {
/*
* 自行根据IP判断是否需要拦截
*/
return true;
}
}

View File

@ -28,6 +28,7 @@ import com.farsunset.cim.acceptor.config.WebsocketConfig;
import com.farsunset.cim.component.handler.annotation.CIMHandler;
import com.farsunset.cim.component.logger.CIMEventLogger;
import com.farsunset.cim.component.predicate.AuthPredicate;
import com.farsunset.cim.component.predicate.BlacklistPredicate;
import com.farsunset.cim.config.properties.APNsProperties;
import com.farsunset.cim.config.properties.CIMAppSocketProperties;
import com.farsunset.cim.config.properties.CIMWebsocketProperties;
@ -77,8 +78,9 @@ public class CIMConfig implements CIMRequestHandler, ApplicationListener<Applica
@Bean(destroyMethod = "destroy",initMethod = "bind")
@ConditionalOnProperty(name = {"cim.websocket.enable"},matchIfMissing = true)
public WebsocketAcceptor websocketAcceptor(CIMWebsocketProperties properties, AuthPredicate authPredicate, CIMEventLogger cimEventLogger) {
public WebsocketAcceptor websocketAcceptor(CIMWebsocketProperties properties, AuthPredicate authPredicate, BlacklistPredicate blacklistPredicate, CIMEventLogger cimEventLogger) {
WebsocketConfig config = new WebsocketConfig();
config.setBlacklistPredicate(blacklistPredicate);
config.setAuthPredicate(authPredicate);
config.setPath(properties.getPath());
config.setPort(properties.getPort());
@ -95,7 +97,7 @@ public class CIMConfig implements CIMRequestHandler, ApplicationListener<Applica
@Bean(destroyMethod = "destroy",initMethod = "bind")
@ConditionalOnProperty(name = {"cim.app.enable"},matchIfMissing = true)
public AppSocketAcceptor appSocketAcceptor(CIMAppSocketProperties properties, CIMEventLogger cimEventLogger) {
public AppSocketAcceptor appSocketAcceptor(CIMAppSocketProperties properties,BlacklistPredicate blacklistPredicate, CIMEventLogger cimEventLogger) {
SocketConfig config = new SocketConfig();
config.setPort(properties.getPort());
@ -106,6 +108,7 @@ public class CIMConfig implements CIMRequestHandler, ApplicationListener<Applica
config.setReadIdle(properties.getReadIdle());
config.setMaxPongTimeout(properties.getMaxPongTimeout());
config.setLoggingHandler(cimEventLogger);
config.setBlacklistPredicate(blacklistPredicate);
return new AppSocketAcceptor(config);
}