fix: 如果鉴权码校验失败则失败
All checks were successful
iot-test-platform CI/CD / build-and-deploy (push) Successful in 17s

This commit is contained in:
lzh
2026-01-19 17:34:43 +08:00
parent aef2405751
commit c5a144d6e0

View File

@@ -11,48 +11,57 @@ import com.iot.transport.jt808.service.handler.MessageHandler;
/** /**
* 终端鉴权 ==> 平台通用应答 * 终端鉴权 ==> 平台通用应答
*
* @author huaxl * @author huaxl
*/ */
public class AuthenticationHandler extends MessageHandler { public class AuthenticationHandler extends MessageHandler {
private final Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());
public AuthenticationHandler() { public AuthenticationHandler() {
super(); super();
} }
@Override @Override
public void process(DataPack packageData) { public void process(DataPack packageData) {
// //
PackHead header = packageData.getPackHead(); PackHead header = packageData.getPackHead();
logger.info("[终端鉴权],msgid={}, phone={},flowid={}", header.getId(), header.getTerminalPhone(), header.getFlowId()); logger.info("[终端鉴权],msgid={}, phone={},flowid={}", header.getId(), header.getTerminalPhone(),
header.getFlowId());
try { try {
AuthenticationPack msg = new AuthenticationPack(packageData); AuthenticationPack msg = new AuthenticationPack(packageData);
//this.msgProcessService.processAuthMsg(authenticationMsg); // this.msgProcessService.processAuthMsg(authenticationMsg);
log.debug("终端鉴权:{}", msg); log.info("终端鉴权:{}", msg);
final String sessionId = Session.buildId(msg.getChannel()); boolean isSuccess = false;
Session session = sessionManager.findBySessionId(sessionId); if ("testtoken".equals(msg.getAuthCode())) {
if (session == null) { isSuccess = true;
session = Session.buildSession(msg.getChannel(), msg.getPackHead().getTerminalPhone()); } else {
} logger.warn("终端鉴权失败: msgId={}, phone={}, token={}", header.getId(), header.getTerminalPhone(),
session.setAuthenticated(true); msg.getAuthCode());
session.setTerminalPhone(msg.getPackHead().getTerminalPhone()); }
sessionManager.put(session.getId(), session);
final String sessionId = Session.buildId(msg.getChannel());
Session session = sessionManager.findBySessionId(sessionId);
if (session == null) {
session = Session.buildSession(msg.getChannel(), msg.getPackHead().getTerminalPhone());
}
session.setAuthenticated(isSuccess);
session.setTerminalPhone(msg.getPackHead().getTerminalPhone());
sessionManager.put(session.getId(), session);
ServerBodyPack respMsgBody = new ServerBodyPack();
respMsgBody.setReplyCode(isSuccess ? ServerBodyPack.success : ServerBodyPack.failure);
respMsgBody.setReplyFlowId(msg.getPackHead().getFlowId());
respMsgBody.setReplyId(msg.getPackHead().getId());
int flowId = super.getFlowId(msg.getChannel());
byte[] bs = this.msgEncoder.encode4ServerCommonRespMsg(msg, respMsgBody, flowId);
super.send2Client(msg.getChannel(), bs);
ServerBodyPack respMsgBody = new ServerBodyPack();
respMsgBody.setReplyCode(ServerBodyPack.success);
respMsgBody.setReplyFlowId(msg.getPackHead().getFlowId());
respMsgBody.setReplyId(msg.getPackHead().getId());
int flowId = super.getFlowId(msg.getChannel());
byte[] bs = this.msgEncoder.encode4ServerCommonRespMsg(msg, respMsgBody, flowId);
super.send2Client(msg.getChannel(), bs);
} catch (Exception e) { } catch (Exception e) {
logger.error("[终端鉴权]错误,err={}", e.getMessage()); logger.error("[终端鉴权]错误,err={}", e.getMessage());
} }
} }