|
|
@@ -25,7 +25,7 @@ import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * 账号管理
|
|
|
+ * JMX 关联操作
|
|
|
*
|
|
|
* @author TRX
|
|
|
* @date 2024/5/17
|
|
|
@@ -190,47 +190,9 @@ public class JMXSyncService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除mqtt用户
|
|
|
- *
|
|
|
- * @param mqttInfo
|
|
|
- * @param gateWayUserInfoList
|
|
|
- */
|
|
|
- private void deleteMqttUsers(MqttInfo mqttInfo, List<GateWayUserInfo> gateWayUserInfoList) {
|
|
|
- if (ObjectUtils.isNotEmpty(mqttInfo) && ObjectUtils.isNotEmpty(gateWayUserInfoList)) {
|
|
|
- try {
|
|
|
- String urlStr = JMXUtil.buildServiceURL(mqttInfo);
|
|
|
- JMXServiceURL url = new JMXServiceURL(urlStr);
|
|
|
- @Cleanup JMXConnector connector = JMXConnectorFactory.connect(url, null);
|
|
|
- connector.connect();
|
|
|
- log.info("JMX deleteMqttUsers {}:{} 连接成功...", mqttInfo.getJmxHost(), mqttInfo.getJmxPort());
|
|
|
- MBeanServerConnection connection = connector.getMBeanServerConnection();
|
|
|
- ObjectName addressObjectName = ObjectNameBuilder.create("org.apache.activemq.artemis", mqttInfo.getBrokerName()).getActiveMQServerObjectName();
|
|
|
- ActiveMQServerControl addressControl = MBeanServerInvocationHandler.newProxyInstance(connection, addressObjectName, ActiveMQServerControl.class, false);
|
|
|
-
|
|
|
- for (GateWayUserInfo gateWayUserInfo : gateWayUserInfoList) {
|
|
|
- Mqtt2User mqtt2User = mqtt2UserDao.findTopByMqttInfoAndGateWayUserInfo(mqttInfo, gateWayUserInfo);
|
|
|
- try {
|
|
|
- String oldUserStr = addressControl.listUser(gateWayUserInfo.getUserName());
|
|
|
- if (JMXUtil.mqttUserIsExit(oldUserStr)) {
|
|
|
- addressControl.removeUser(gateWayUserInfo.getUserName());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("deleteMqttUsers: {}", e.getMessage());
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotEmpty(mqtt2User)) {
|
|
|
- mqtt2UserDao.delete(mqtt2User);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 同步网关
|
|
|
+ *
|
|
|
* @param gateWayInfo
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -247,7 +209,7 @@ public class JMXSyncService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 同步网关的权限
|
|
|
+ * 同步网关的权限 网关的:网关监听权限
|
|
|
*
|
|
|
* @param gateWayInfo
|
|
|
* @return
|
|
|
@@ -460,36 +422,4 @@ public class JMXSyncService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- //-----------------------------同步权限数据 end----------------------
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除用户 从MQTT服务
|
|
|
- *
|
|
|
- * @param gateWayUserInfo
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultContent deleteGateWayUser(GateWayUserInfo gateWayUserInfo) {
|
|
|
- List<MqttInfo> list = mqttInfoDao.findAll();
|
|
|
- if (ObjectUtils.isNotEmpty(list)) {
|
|
|
- for (MqttInfo mqttInfo : list) {
|
|
|
- try {
|
|
|
- String urlStr = String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", mqttInfo.getJmxHost(), mqttInfo.getJmxPort());
|
|
|
- JMXServiceURL url = new JMXServiceURL(urlStr);
|
|
|
- @Cleanup JMXConnector connector = JMXConnectorFactory.connect(url, null);
|
|
|
- connector.connect();
|
|
|
- log.info("JMX %s:%s 连接成功...", mqttInfo.getJmxHost(), mqttInfo.getJmxPort());
|
|
|
- MBeanServerConnection connection = connector.getMBeanServerConnection();
|
|
|
- ObjectName addressObjectName = ObjectNameBuilder.create("org.apache.activemq.artemis", mqttInfo.getBrokerName()).getActiveMQServerObjectName();
|
|
|
- ActiveMQServerControl addressControl = MBeanServerInvocationHandler.newProxyInstance(connection, addressObjectName, ActiveMQServerControl.class, false);
|
|
|
- addressControl.removeUser(gateWayUserInfo.getUserName());
|
|
|
- // 删除关系记录
|
|
|
- mqtt2UserDao.deleteByMqttInfoAndGateWayUserInfo(mqttInfo, gateWayUserInfo);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return ResultContent.buildSuccess();
|
|
|
- }
|
|
|
-
|
|
|
}
|