[ https://issues.apache.org/jira/browse/ARTEMIS-3913?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17573974#comment-17573974 ]
gongping.zhu edited comment on ARTEMIS-3913 at 8/2/22 12:54 AM: ---------------------------------------------------------------- public class ArtemisBrokerPlugin implements ActiveMQServerPlugin, Serializable { ... } !image-2022-08-02-08-54-34-267.png! !image-2022-08-02-08-23-52-965.png! !image-2022-08-02-08-24-39-288.png! public class MQTTProtocolHandler extends ChannelInboundHandlerAdapter { ... ... } !image-2022-08-02-08-45-11-459.png! when i use wireshark capture log !image-2022-08-02-08-31-01-074.png! was (Author: JIRAUSER293605): my ArtemisBorkderPlugin code {quote}public class ArtemisBrokerPlugin implements ActiveMQServerPlugin, Serializable {{quote} {quote}...{quote} {quote}@Override public void beforeCreateSession(String name, String username, int minLargeMessageSize, RemotingConnection connection, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, boolean xa, String defaultAddress, SessionCallback callback, boolean autoCreateQueues, OperationContext context, Map<SimpleString, RoutingType> prefixes) throws ActiveMQException { if(debug) { log.info("beforeCreateSession {},{},{},{},{}", connection.getClientID(), connection.getRemoteAddress(), connection.getID(), name, username); } String connId = connection.getID().toString(); if(deviceAuthEnabled && !authConnectTables.containsKey(connId)) { // Debug.print(log); authConnectTables.put(connId,0); doConnectValidation(connection); } }{quote} {quote}private void doConnectValidation(RemotingConnection connection) throws ActiveMQException{ Boolean success = false; String error = ""; boolean invalid = false; int locked = 0; int eft = 0; String clientId = connection.getClientID(); String connId = connection.getID().toString(); String clientIp = connection.getRemoteAddress().toString(); clientIp = formatClientIP(clientIp); try{ /** * 设备授权校验 */ boolean invalidClientId = invalidClientId(clientId); if(invalidClientId){//licId@mac /** * 无效的ClientId */ invalid = true; throw new MQTTRuntimesException(MQTTReasonCodes.CLIENT_IDENTIFIER_NOT_VALID,String.format("%s,非授权设备",clientId)); } /** * 连接用户校验 * 有效的ClientId格式 */ if(!isService(clientId)){ String[] clientIdElements = clientId.split(CLIENT_SPLITOR); String licId = clientIdElements[0]; String devId = clientIdElements[1]; /** * 开启设备授权 */ if(deviceAuthEnabled){ /** * 新设备 */ if(!authDeviceTables.containsKey(clientId)){ /** * 验证设备 */ DeviceAuth auth = validate(licId,devId); /** * 新设备 */ if(ObjectUtil.isNotEmpty(auth)){ /** * 设备第一次 */ if(ObjectUtil.isEmpty(auth.getDevId())){ String lockerSql = deviceAuthLockerSQL; /** * 防止一个licId被多台设备使用 */ locked = deviceJdbcTemplate.update(lockerSql, new Object[]\{devId, licId}); if(locked==0){ throw new MQTTRuntimesException(MQTTReasonCodes.CLIENT_IDENTIFIER_NOT_VALID,String.format("%s,不能在多台设备上使用",licId)); } auth.setDevId(devId); authDeviceTables.put(clientId,auth); } } } } /** * 更新设备状态【连接】 */ if(deviceStatusSyncabled){ String sql = connectUpdateSQL; String brokerIp = IPUntil.getLocalIp(); eft = deviceJdbcTemplate.update(sql, new Object[]\{connId,clientIp, brokerIp,licId}); } } success = true; } catch(ActiveMQException ex){ error = ex.getMessage(); throw ex; } finally{ String prefix = "连接异常"; if(success){ prefix = "连接成功"; log.info("{} {} {} {} {} {}", prefix, formatClientId(clientId), clientIp,connId,locked,eft); } else{ if(invalid) { log.debug("{} {} {} {} {} {} {}", prefix, formatClientId(clientId), clientIp,connId,locked,eft, error); } else{ log.info("{} {} {} {} {} {} {}", prefix, formatClientId(clientId), clientIp,connId, locked,eft,error); } } } }{quote} {quote}/** * @param licId yekerId * @param devId cpusn or mac_address */ private DeviceAuth validate(String licId,String devId) throws ActiveMQException { /** * YekerId@CPU_SN;保证一个YekerId只被一台设备使用 */ String sql = deviceAuthCheckSQL; List<DeviceAuth> deviceAuths = deviceJdbcTemplate.query(sql, new Object[]\{licId}, new RowMapperResultSetExtractor<DeviceAuth>(new BeanPropertyRowMapper<DeviceAuth>(DeviceAuth.class))); if (deviceAuths == null || ObjectUtil.isEmpty(deviceAuths)) { throw new MQTTRuntimesException(MQTTReasonCodes.CLIENT_IDENTIFIER_NOT_VALID,String.format("%s,非授权设备",licId)); } DeviceAuth auth = deviceAuths.get(0); if (ObjectUtil.isNotEmpty(auth.getDevId()) && !auth.getDevId().equalsIgnoreCase(devId)) { throw new MQTTRuntimesException(MQTTReasonCodes.CLIENT_IDENTIFIER_NOT_VALID,String.format("%s,不能在多台设备上使用",licId)); } return auth; }{quote} {quote}..{quote} !image-2022-08-02-08-23-52-965.png! !image-2022-08-02-08-24-39-288.png! public class MQTTProtocolHandler extends ChannelInboundHandlerAdapter { ... ... } !image-2022-08-02-08-45-11-459.png! when i use wireshark capture log !image-2022-08-02-08-31-01-074.png! > MQTTReasonCodes byte loss of precision,must int type > ---------------------------------------------------- > > Key: ARTEMIS-3913 > URL: https://issues.apache.org/jira/browse/ARTEMIS-3913 > Project: ActiveMQ Artemis > Issue Type: Bug > Reporter: gongping.zhu > Priority: Major > Attachments: image-2022-08-02-08-23-52-965.png, > image-2022-08-02-08-24-39-288.png, image-2022-08-02-08-31-01-074.png, > image-2022-08-02-08-42-24-117.png, image-2022-08-02-08-43-39-442.png, > image-2022-08-02-08-45-11-459.png, image-2022-08-02-08-54-34-267.png > > -- This message was sent by Atlassian Jira (v8.20.10#820010)