【fix】授权调整

This commit is contained in:
wujiawei
2025-07-16 21:30:09 +08:00
parent 841c24a6ed
commit 50b2b1866c
6 changed files with 37 additions and 26 deletions

View File

@@ -81,7 +81,7 @@ public class NettyClientSocketApplicationListener implements ApplicationListener
authenticationToken.setUsedByClientId(clientId);
authenticationToken.setAppKey(appKey);
authenticationToken.setAppSecret(appSecret);
AuthenticationTokenContext.setAuthenticationToken(authenticationToken);
AuthenticationTokenContext.setAuthenticationToken(clientId, appKey, appSecret);
}catch (Exception e){
e.printStackTrace();
}

View File

@@ -1,14 +1,7 @@
package org.framework.lazy.cloud.network.heartbeat.protocol.auth;
import org.framework.lazy.cloud.network.heartbeat.protocol.properties.ProtocolProxyProperties;
public abstract class AbstractNettyPasswordAuth implements NettyPasswordAuth {
private final ProtocolProxyProperties protocolProxyProperties;
protected AbstractNettyPasswordAuth(ProtocolProxyProperties protocolProxyProperties) {
this.protocolProxyProperties = protocolProxyProperties;
}
public abstract boolean doVerify(String username, String password);
@@ -21,9 +14,6 @@ public abstract class AbstractNettyPasswordAuth implements NettyPasswordAuth {
*/
@Override
public boolean verify(String username, String password) {
if (protocolProxyProperties.getAuthentication()) {
return doVerify(username, password);
}
return true;
return doVerify(username, password);
}
}

View File

@@ -12,10 +12,6 @@ import java.util.concurrent.ConcurrentHashMap;
@Component
public class DefaultNettyPasswordAuth extends AbstractNettyPasswordAuth {
protected DefaultNettyPasswordAuth(ProtocolProxyProperties protocolProxyProperties) {
super(protocolProxyProperties);
}
@Override
public boolean doVerify(String username, String password) {
boolean verify = AuthenticationTokenContext.verify(username, password);

View File

@@ -9,6 +9,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelT
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
import org.framework.lazy.cloud.network.heartbeat.protocol.auth.NettyPasswordAuth;
import org.framework.lazy.cloud.network.heartbeat.protocol.handler.*;
import org.framework.lazy.cloud.network.heartbeat.protocol.properties.ProtocolProxyProperties;
import org.springframework.stereotype.Component;
import java.util.List;
@@ -23,10 +24,12 @@ import java.util.List;
public class NettyTcpProxyFilter extends DebugChannelInitializer<SocketChannel> {
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
private final NettyPasswordAuth nettyPasswordAuth;
private final ProtocolProxyProperties protocolProxyProperties;
public NettyTcpProxyFilter(List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList, NettyPasswordAuth nettyPasswordAuth) {
public NettyTcpProxyFilter(List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList, NettyPasswordAuth nettyPasswordAuth, ProtocolProxyProperties protocolProxyProperties) {
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
this.nettyPasswordAuth = nettyPasswordAuth;
this.protocolProxyProperties = protocolProxyProperties;
}
@Override
@@ -42,12 +45,7 @@ public class NettyTcpProxyFilter extends DebugChannelInitializer<SocketChannel>
pipeline.addLast(Socks5ServerEncoder.DEFAULT);
// 初始化连接
pipeline.addLast(new Socks5InitialRequestDecoder());
pipeline.addLast(new NettySocks5InitialRequestHandler());
// 认证
pipeline.addLast(new Socks5PasswordAuthRequestDecoder());
pipeline.addLast(new NettySocks5PasswordAuthRequestInboundHandler(nettyPasswordAuth));
pipeline.addLast(new NettySocks5InitialRequestHandler(protocolProxyProperties,nettyPasswordAuth));
// 连接请求

View File

@@ -4,9 +4,20 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.socksx.v5.*;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.protocol.auth.NettyPasswordAuth;
import org.framework.lazy.cloud.network.heartbeat.protocol.properties.ProtocolProxyProperties;
@Slf4j
public class NettySocks5InitialRequestHandler extends SimpleChannelInboundHandler<Socks5InitialRequest> {
private final ProtocolProxyProperties protocolProxyProperties;
private final NettyPasswordAuth nettyPasswordAuth;
public NettySocks5InitialRequestHandler(ProtocolProxyProperties protocolProxyProperties, NettyPasswordAuth nettyPasswordAuth) {
this.protocolProxyProperties = protocolProxyProperties;
this.nettyPasswordAuth = nettyPasswordAuth;
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Socks5InitialRequest msg) throws Exception {
boolean failure = msg.decoderResult().isFailure();
@@ -18,9 +29,23 @@ public class NettySocks5InitialRequestHandler extends SimpleChannelInboundHandle
}
log.info("初始化socket连接");
// 验证账号密码
Socks5InitialResponse socks5InitialResponse = new DefaultSocks5InitialResponse(Socks5AuthMethod.PASSWORD);
ctx.writeAndFlush(socks5InitialResponse);
if(protocolProxyProperties.getAuthentication()){
// 验证账号密码
Socks5InitialResponse socks5InitialResponse =
new DefaultSocks5InitialResponse(Socks5AuthMethod.PASSWORD);
ctx.writeAndFlush(socks5InitialResponse);
// 认证
ctx.pipeline().addLast(new Socks5PasswordAuthRequestDecoder());
ctx.pipeline().addLast(new NettySocks5PasswordAuthRequestInboundHandler(nettyPasswordAuth));
}else {
// 不验证账号密码
Socks5InitialResponse socks5InitialResponse =
new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH);
ctx.writeAndFlush(socks5InitialResponse);
}
ctx.pipeline().remove(this);
ctx.pipeline().remove(Socks5InitialRequestDecoder.class);

View File

@@ -28,6 +28,8 @@ spring:
netty:
protocol:
proxy:
authentication: true
enable-proxy-log: true
socket-protocol-proxy:
port: 9002
http-protocol-proxy: