fix: 如果鉴权码校验失败则失败
All checks were successful
iot-test-platform CI/CD / build-and-deploy (push) Successful in 17s
All checks were successful
iot-test-platform CI/CD / build-and-deploy (push) Successful in 17s
This commit is contained in:
@@ -11,13 +11,13 @@ import com.iot.transport.jt808.service.handler.MessageHandler;
|
||||
|
||||
/**
|
||||
* 终端鉴权 ==> 平台通用应答
|
||||
*
|
||||
* @author huaxl
|
||||
*/
|
||||
public class AuthenticationHandler extends MessageHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
|
||||
public AuthenticationHandler() {
|
||||
super();
|
||||
}
|
||||
@@ -27,32 +27,41 @@ public class AuthenticationHandler extends MessageHandler {
|
||||
//
|
||||
|
||||
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 {
|
||||
|
||||
AuthenticationPack msg = new AuthenticationPack(packageData);
|
||||
//this.msgProcessService.processAuthMsg(authenticationMsg);
|
||||
log.debug("终端鉴权:{}", msg);
|
||||
// this.msgProcessService.processAuthMsg(authenticationMsg);
|
||||
log.info("终端鉴权:{}", msg);
|
||||
|
||||
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(true);
|
||||
session.setTerminalPhone(msg.getPackHead().getTerminalPhone());
|
||||
sessionManager.put(session.getId(), session);
|
||||
boolean isSuccess = false;
|
||||
if ("testtoken".equals(msg.getAuthCode())) {
|
||||
isSuccess = true;
|
||||
} else {
|
||||
logger.warn("终端鉴权失败: msgId={}, phone={}, token={}", header.getId(), header.getTerminalPhone(),
|
||||
msg.getAuthCode());
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("[终端鉴权]错误,err={}", e.getMessage());
|
||||
logger.error("[终端鉴权]错误,err={}", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user