瀏覽代碼

修改采集器中的身份验证方式字段,以前为是否匿名登录

zhoupeng 1 年之前
父節點
當前提交
ee5fa23374

+ 3 - 3
industry-system/cqcy-ei-common/src/main/java/com/example/opc_common/util/ClientInfoUtil.java

@@ -86,9 +86,9 @@ public class ClientInfoUtil {
             } else if (OpcUtil.isOpcUa(type)) {
                 item.set("items", entry.getValue());
                 item.set("port", dataSource.get("ipPort"));
-                Integer isAnonymous = Convert.toInt(dataSource.get("isAnonymous"), 1);
-                item.set("isAnonymous", isAnonymous);
-                if (isAnonymous == 0) {
+                Integer identityProvider = Convert.toInt(dataSource.get("identityProvider"), 0);
+                item.set("identityProvider", identityProvider);
+                if (identityProvider == 1) {
                     item.set("userName", dataSource.get("userName"));
                     try {
                         item.set("password", RSAUtil.decrypt(Convert.toStr(dataSource.get("ipPassword")), "UTF-8"));

+ 1 - 1
industry-system/industry-da/src/main/resources/mapper/CollectorDao.xml

@@ -116,7 +116,7 @@
     <!--获取所有数据源-->
     <select id="getAllDataSource" resultType="java.util.Map">
         SELECT tds.id, tds.ip_address ipAddress, tds.ip_port ipPort, tds.prog_id progId, tdst.data_source_type_key typeKey, tds.slave_id slaveId,
-               tds.is_anonymous isAnonymous, tds.ip_user_name userName, tds.ip_password ipPassword FROM t_data_source tds
+               tds.identity_provider identityProvider, tds.ip_user_name userName, tds.ip_password ipPassword FROM t_data_source tds
         LEFT JOIN t_data_source_type tdst ON tds.type_id = tdst.id
     </select>
 

+ 2 - 1
industry-system/industry-da/src/main/resources/mapper/ReportTableDao.xml

@@ -72,7 +72,8 @@
 
     <sql id="dataSource">
         id
-        , type_id, data_source_name, data_source_describe, ip_address, ip_port, ip_user_name, ip_password, is_anonymous, cls_id, prog_id, driver_describe, create_time
+        , type_id, data_source_name, data_source_describe, ip_address, ip_port, ip_user_name, ip_password,
+        security_mode, security_policy, identity_provider, certificate_dir, certificate_key, cls_id, prog_id, driver_describe, create_time
     </sql>
 
     <sql id="dataSourceType">

+ 35 - 34
新采集器/fast-api/src/main/java/com/ws/fastapi/util/ConfUtil.java

@@ -5,53 +5,54 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.ws.fastapi.entity.Pact;
 
 import java.util.Objects;
 
-import com.ws.fastapi.entity.Pact;
-
 
 public class ConfUtil {
-	
-	public static String getPath() {
-		String path = System.getProperty("user.dir").replace("\\", "/");
-		path = path.substring(0, path.lastIndexOf("/"));
-		return path + "/workspace/bin";
-	}
+
+    public static String getPath() {
+        String path = System.getProperty("user.dir").replace("\\", "/");
+        path = path.substring(0, path.lastIndexOf("/"));
+        return path + "/workspace/bin";
+    }
 
     /**
      * 创建opcda配置文件
+     *
      * @param obj
      * @return
      */
     public static String createOpcDaConf(JSONObject obj) {
         StringBuilder buffer;
         FileWriter writer;
-            buffer = new StringBuilder();
-            buffer.append("[[inputs.opcda]]\n")
-                    .append("name = \"").append(obj.getStr("name")).append("\"\n")
-                    .append("server = \"").append(obj.getStr("server")).append("\"\n")
-                    .append("nodes = [\"").append(obj.getStr("ip")).append("\"]\n")
-                    .append("items = [\n");
-            JSONArray items = obj.getJSONArray("items");
-            for (int j = 0; j < items.size(); j++) {
-                buffer.append("{ item = \"").append(items.getStr(j)).append("\"");
-                buffer.append(", tags = [[\"DataSource\", \"").append(obj.getStr("datasource")).append("\"]]");
-                buffer.append("},\n");
-            }
-            buffer.append("]\n");
-            String url = getPath() + "/opcDa/da_" + obj.getStr("id") + "_" + obj.getStr("interval") + ".conf";
-            writer = new FileWriter(url);
-            writer.write(buffer.toString());
+        buffer = new StringBuilder();
+        buffer.append("[[inputs.opcda]]\n")
+                .append("name = \"").append(obj.getStr("name")).append("\"\n")
+                .append("server = \"").append(obj.getStr("server")).append("\"\n")
+                .append("nodes = [\"").append(obj.getStr("ip")).append("\"]\n")
+                .append("items = [\n");
+        JSONArray items = obj.getJSONArray("items");
+        for (int j = 0; j < items.size(); j++) {
+            buffer.append("{ item = \"").append(items.getStr(j)).append("\"");
+            buffer.append(", tags = [[\"DataSource\", \"").append(obj.getStr("datasource")).append("\"]]");
+            buffer.append("},\n");
+        }
+        buffer.append("]\n");
+        String url = getPath() + "/opcDa/da_" + obj.getStr("id") + "_" + obj.getStr("interval") + ".conf";
+        writer = new FileWriter(url);
+        writer.write(buffer.toString());
         return url;
     }
 
     /**
      * 创建telegraf配置文件
+     *
      * @param obj
      */
     public static void createTelegrafConf(JSONObject obj) {
-    	String path = ConfUtil.getPath();
+        String path = ConfUtil.getPath();
         JSONObject agent = obj.getJSONObject("agent");
         StringBuilder buffer = new StringBuilder();
         // 默认数据收集间隔
@@ -102,7 +103,7 @@ public class ConfUtil {
             } else if (Pact.OPC_UA.getValue().equals(item.getStr("type"))) {
                 buffer.append(createOpcUa(item));
             } else if (Pact.OPC_UA_fast.getValue().equals(item.getStr("type"))) {
-            	buffer.append(createOpcUaFast(item));
+                buffer.append(createOpcUaFast(item));
             }
         }
 
@@ -112,7 +113,7 @@ public class ConfUtil {
                 .append("token = \"").append(output.getStr("token")).append("\"\n")
                 .append("organization = \"").append(output.getStr("organization")).append("\"\n")
                 .append("bucket = \"").append(output.getStr("bucket")).append("\"\n");
-        FileWriter writer = new FileWriter(getPath() + "/telegraf_"+ agent.getStr("interval") +".conf");
+        FileWriter writer = new FileWriter(getPath() + "/telegraf_" + agent.getStr("interval") + ".conf");
         writer.write(buffer.toString());
     }
 
@@ -125,10 +126,10 @@ public class ConfUtil {
                 .append("request_timeout=\"5s\"\n")
                 .append("security_policy=\"auto\"\n")
                 .append("security_mode=\"auto\"\n");
-        Integer isAnonymous = item.getInt("isAnonymous");
-        if (isAnonymous == 1) {
+        Integer identityProvider = item.getInt("identityProvider");
+        if (identityProvider == 0) {
             builder.append("auth_method=\"Anonymous\"\n");
-        } else {
+        } else if (identityProvider == 1) {
             builder.append("auth_method=\"UserName\"\n")
                     .append("username=\"").append(item.getStr("userName")).append("\"\n")
                     .append("password=\"").append(item.getStr("password")).append("\"\n");
@@ -157,7 +158,7 @@ public class ConfUtil {
         builder.append("]\n");
         return builder.toString();
     }
-    
+
     private static String createOpcUaFast(JSONObject item) {
         StringBuilder builder = new StringBuilder();
         builder.append("[[inputs.opcua_listener]]\n")
@@ -168,10 +169,10 @@ public class ConfUtil {
                 .append("request_timeout=\"5s\"\n")
                 .append("security_policy=\"auto\"\n")
                 .append("security_mode=\"auto\"\n");
-        Integer isAnonymous = item.getInt("isAnonymous");
-        if (isAnonymous == 1) {
+        Integer identityProvider = item.getInt("identityProvider");
+        if (identityProvider == 0) {
             builder.append("auth_method=\"Anonymous\"\n");
-        } else {
+        } else if (identityProvider == 1) {
             builder.append("auth_method=\"UserName\"\n")
                     .append("username=\"").append(item.getStr("userName")).append("\"\n")
                     .append("password=\"").append(item.getStr("password")).append("\"\n");