summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshangguan <[email protected]>2022-09-08 17:25:48 +0800
committershangguan <[email protected]>2022-09-08 17:25:48 +0800
commit22bbbef3dd0bbec0384956ab805be8f84bff3cd1 (patch)
treee67ac4b3551e58c34c4aa0d88bcede8f69ff061f
parent97a656aff92ea133cc11576248563e9eb8f927da (diff)
初始化项目
-rw-r--r--pom.xml65
-rw-r--r--src/main/java/com/example/nis/FjTransformApiApplication.java13
-rw-r--r--src/main/java/com/example/nis/common/Code.java28
-rw-r--r--src/main/java/com/example/nis/common/ResponseData.java72
-rw-r--r--src/main/java/com/example/nis/common/TsgServiceImpl.java141
-rw-r--r--src/main/java/com/example/nis/configure/StartedUpRunner.java39
-rw-r--r--src/main/java/com/example/nis/controller/FqdnController.java150
-rw-r--r--src/main/java/com/example/nis/controller/IpController.java120
-rw-r--r--src/main/java/com/example/nis/controller/UrlController.java150
-rw-r--r--src/main/java/com/example/nis/domain/IpObject.java19
-rw-r--r--src/main/java/com/example/nis/domain/IpSource.java14
-rw-r--r--src/main/java/com/example/nis/domain/KeywordsObject.java18
-rw-r--r--src/main/java/com/example/nis/domain/KeywordsSource.java15
-rw-r--r--src/main/java/com/example/nis/util/Constant.java157
-rw-r--r--src/main/java/com/example/nis/util/ToTsgSystemUtil.java110
-rw-r--r--src/main/resources/application.yml25
-rw-r--r--src/main/resources/log4j.properties7
-rw-r--r--src/main/resources/logback-spring.xml56
-rw-r--r--src/test/java/com/example/nis/FjTransformApiApplicationTests.java13
19 files changed, 1212 insertions, 0 deletions
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..7fad404
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-parent</artifactId>
+ <version>2.5.4</version>
+ <relativePath/> <!-- lookup parent from repository -->
+ </parent>
+ <groupId>com.example</groupId>
+ <artifactId>FJ-Transform-Api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>FJ-Transform-Api</name>
+ <description>Demo project for Spring Boot</description>
+ <properties>
+ <java.version>1.8</java.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <!-- hutool工具 -->
+ <dependency>
+ <groupId>cn.hutool</groupId>
+ <artifactId>hutool-all</artifactId>
+ <version>5.7.7</version>
+ </dependency>
+ <!-- commons -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ <!-- httpclient -->
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.13</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>FJ-Transform-Api</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/src/main/java/com/example/nis/FjTransformApiApplication.java b/src/main/java/com/example/nis/FjTransformApiApplication.java
new file mode 100644
index 0000000..b82450e
--- /dev/null
+++ b/src/main/java/com/example/nis/FjTransformApiApplication.java
@@ -0,0 +1,13 @@
+package com.example.nis;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class FjTransformApiApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(FjTransformApiApplication.class, args);
+ }
+
+}
diff --git a/src/main/java/com/example/nis/common/Code.java b/src/main/java/com/example/nis/common/Code.java
new file mode 100644
index 0000000..62eb6e5
--- /dev/null
+++ b/src/main/java/com/example/nis/common/Code.java
@@ -0,0 +1,28 @@
+package com.example.nis.common;
+
+
+public enum Code {
+
+ SUCCESS(200, "success"),
+ ERROR(999, "error");
+
+
+
+
+
+ private Integer code;
+ public Integer getCode() {
+ return code;
+ }
+
+ private String msg;
+ public String getMsg() {
+ return msg;
+ }
+
+
+ private Code(Integer code, String msg) {
+ this.code = code;
+ this.msg = msg;
+ }
+}
diff --git a/src/main/java/com/example/nis/common/ResponseData.java b/src/main/java/com/example/nis/common/ResponseData.java
new file mode 100644
index 0000000..33a4216
--- /dev/null
+++ b/src/main/java/com/example/nis/common/ResponseData.java
@@ -0,0 +1,72 @@
+package com.example.nis.common;
+
+import cn.hutool.json.JSONObject;
+
+import java.util.HashMap;
+
+
+public class ResponseData extends HashMap<String, Object> {
+ private static final long serialVersionUID = 1L;
+
+
+ public ResponseData() {
+ put("code", Code.SUCCESS.getCode());
+ put("msg", Code.SUCCESS.getMsg());
+ }
+
+ public static ResponseData ok(String msg) {
+ ResponseData r = new ResponseData();
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static ResponseData ok() {
+ return new ResponseData();
+ }
+
+ public static ResponseData ok(Object data) {
+ ResponseData r = new ResponseData();
+ r.put("data", data);
+ return r;
+ }
+ public static ResponseData ok(Integer code, String msg ) {
+ ResponseData r = new ResponseData();
+ r.put("code", code);
+ r.put("msg", msg);
+ r.put("data", new JSONObject());
+ return r;
+ }
+ public static ResponseData ok(Integer code, String msg ,Object data) {
+ ResponseData r = new ResponseData();
+ r.put("code", code);
+ r.put("msg", msg);
+ r.put("data", data);
+ return r;
+ }
+
+ public static ResponseData error() {
+
+ return error(Code.ERROR.getCode(), Code.ERROR.getMsg());
+ }
+
+ public static ResponseData error(Code code) {
+ ResponseData r = new ResponseData();
+ r.put("code", code.getCode());
+ r.put("msg", code.getMsg());
+ return r;
+ }
+ public static ResponseData error(String msg) {
+ ResponseData r = new ResponseData();
+ r.put("code", Code.ERROR.getCode());
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static ResponseData error(Integer code, String msg) {
+ ResponseData r = new ResponseData();
+ r.put("code", code);
+ r.put("msg", msg);
+ r.put("data", new JSONObject());
+ return r;
+ }
+}
diff --git a/src/main/java/com/example/nis/common/TsgServiceImpl.java b/src/main/java/com/example/nis/common/TsgServiceImpl.java
new file mode 100644
index 0000000..5985539
--- /dev/null
+++ b/src/main/java/com/example/nis/common/TsgServiceImpl.java
@@ -0,0 +1,141 @@
+package com.example.nis.common;
+
+import cn.hutool.http.Header;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.example.nis.util.Constant;
+import com.example.nis.util.ToTsgSystemUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class TsgServiceImpl {
+
+ private static Integer httpTimeOut;
+ @Value("${tsg.system.httpTimeOut}")
+ public void setTsgUrl(Integer timeOut) {
+ httpTimeOut = timeOut;
+ }
+
+ /**
+ * 查询 item 数据
+ * @param objectId
+ * @param itemType 必填
+ * @param itemIds
+ * @return
+ */
+ public JSONArray getItemList(Integer objectId, String itemType,Integer itemId, Integer[] itemIds,
+ String ip,String port,String keywords) throws Exception {
+ Map<String,Object> paramMap = new HashMap<>();
+ paramMap.put(Constant.TSG_PAGE_NO, 1);
+ paramMap.put(Constant.TSG_PAGE_SIZE, -1);
+ paramMap.put(Constant.TSG_IS_VALID, 1);
+ if (StringUtils.isNotEmpty(itemType)) {
+ paramMap.put(Constant.TSG_ITEM_TYPE, itemType);
+ } else {
+ log.error("itemType参数不能为空");
+ throw new RuntimeException("itemType参数不能为空");
+ }
+ if (StringUtils.isNotEmpty(ip)) {
+ paramMap.put(Constant.TSG_ITEM_IP, ip);
+ }
+ if (StringUtils.isNotEmpty(port)) {
+ paramMap.put(Constant.TSG_ITEM_PORT, port);
+ }
+ if (StringUtils.isNotEmpty(keywords)) {
+ paramMap.put(Constant.TSG_ITEM_KEYWORDS, keywords);
+ }
+ if (objectId !=null) {
+ paramMap.put(Constant.TSG_OBJECT_ID, objectId);
+ }
+ if (itemId !=null) {
+ paramMap.put(Constant.TSG_ITEM_ID, itemId);
+ }
+ if (itemIds !=null && itemIds.length>0) {
+ paramMap.put(Constant.TSG_ITEM_IDS, itemIds);
+ }
+ JSONArray result ;
+ try {
+ String token = ToTsgSystemUtil.sendLoginRequest();
+ String result1 = HttpRequest.get(ToTsgSystemUtil.TSG_URL+"v1/policy/items")
+ .header(Header.AUTHORIZATION, token)
+ .form(paramMap)
+ .timeout(httpTimeOut)
+ .execute().body();
+
+ if (StringUtils.isNotBlank(result1)) {
+ JSONObject jsonObject = JSONUtil.parseObj(result1);
+ if (Constant.TSG_SUCCESS_CODE.equals(jsonObject.get(Constant.TSG_CODE).toString())) {
+ String str = JSONUtil.parseObj(jsonObject.get(Constant.TSG_DATA)).get(Constant.TSG_LIST).toString();
+ result = JSONUtil.parseArray(str);
+ log.info("item查询成功");
+ } else {
+ log.error("item查询失败!Response:{}", result1);
+ throw new RuntimeException("item查询失败!");
+ }
+ } else {
+ log.error("item查询失败!Response:{}", result1);
+ throw new RuntimeException("item查询失败!");
+ }
+ } catch (Exception e) {
+ log.error("item查询失败!", e);
+ throw e;
+ }
+ return result;
+ }
+
+ /**
+ * 对象 修改
+ * @param objectList
+ * @return
+ */
+ public boolean updateObject(JSONArray objectList) throws Exception {
+ JSONObject jsonObject1 = new JSONObject();
+ jsonObject1.set(Constant.TSG_RETURN_DATA, 1);
+ jsonObject1.set(Constant.TSG_OP_ACTION, Constant.TSG_UPDATE);
+ if (objectList !=null && objectList.size()>0) {
+ jsonObject1.set(Constant.TSG_OBJECT_LIST, objectList);
+ } else {
+ log.error("对象修改失败!objectList参数不能为空");
+ throw new RuntimeException("对象修改失败!objectList参数不能为空");
+ }
+ boolean result;
+ try {
+ // 修改
+ String token = ToTsgSystemUtil.sendLoginRequest();
+ String result1 = HttpRequest.put(ToTsgSystemUtil.TSG_URL+"v1/policy/object")
+ .header(Header.AUTHORIZATION, token)
+ .header(Header.CONTENT_TYPE, Constant.TSG_APPLICATION_JSON)
+ .body(jsonObject1.toString())
+ .timeout(httpTimeOut)
+ .execute().body();
+ if (StringUtils.isNotBlank(result1)) {
+ JSONObject jsonObject = JSONUtil.parseObj(result1);
+ if (Constant.TSG_SUCCESS_CODE.equals(jsonObject.get(Constant.TSG_CODE).toString())) {
+ result = true;
+ log.info("对象修改成功");
+ } else {
+ log.error("对象修改失败!Response:{}", result1);
+ throw new RuntimeException("对象修改失败!");
+ }
+ } else {
+ log.error("对象修改失败!Response:{}", result1);
+ throw new RuntimeException("对象修改失败!");
+ }
+ } catch (Exception e) {
+ log.error("对象修改失败!", e);
+ throw e;
+ }
+ return result;
+ }
+
+}
diff --git a/src/main/java/com/example/nis/configure/StartedUpRunner.java b/src/main/java/com/example/nis/configure/StartedUpRunner.java
new file mode 100644
index 0000000..011d274
--- /dev/null
+++ b/src/main/java/com/example/nis/configure/StartedUpRunner.java
@@ -0,0 +1,39 @@
+package com.example.nis.configure;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+
+@Component
+public class StartedUpRunner implements ApplicationRunner {
+
+ private final ConfigurableApplicationContext context;
+ private final Environment environment;
+
+ @Autowired
+ public StartedUpRunner(ConfigurableApplicationContext context, Environment environment) {
+ this.context = context;
+ this.environment = environment;
+ }
+
+ private static void printSystemUpBanner(Environment environment) {
+ String banner = "-----------------------------------------\n" +
+ "服务启动成功,时间:" + LocalDateTime.now() + "\n" +
+ "服务名称:" + environment.getProperty("spring.application.name") + "\n" +
+ "端口号:" + environment.getProperty("server.port") + "\n" +
+ "-----------------------------------------";
+ System.out.println(banner);
+ }
+
+ @Override
+ public void run(ApplicationArguments args) {
+ if (context.isActive()) {
+ printSystemUpBanner(environment);
+ }
+ }
+}
diff --git a/src/main/java/com/example/nis/controller/FqdnController.java b/src/main/java/com/example/nis/controller/FqdnController.java
new file mode 100644
index 0000000..eeac860
--- /dev/null
+++ b/src/main/java/com/example/nis/controller/FqdnController.java
@@ -0,0 +1,150 @@
+package com.example.nis.controller;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.example.nis.common.ResponseData;
+import com.example.nis.common.TsgServiceImpl;
+import com.example.nis.domain.KeywordsObject;
+import com.example.nis.domain.KeywordsSource;
+import com.example.nis.util.Constant;
+import com.example.nis.util.ToTsgSystemUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Slf4j
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/v1/fqdn")
+public class FqdnController {
+
+ private final TsgServiceImpl tsgService;
+
+ @GetMapping
+ public ResponseData get(KeywordsObject object) {
+ try {
+ if (object !=null) {
+ Integer[] itemIds = null;
+ if (StringUtils.isNotEmpty(object.getItemIds())) {
+ String[] split = object.getItemIds().split(",");
+ itemIds = new Integer[split.length];
+ for (int i =0;i<split.length;i++) {
+ itemIds[i] = Integer.parseInt(split[i]);
+ }
+ }
+ JSONArray itemList = tsgService.getItemList(ToTsgSystemUtil.fqdnObjectId, "fqdn", object.getItemId(), itemIds, null, null, object.getKeywords());
+ List<KeywordsObject> list = new ArrayList<>();
+ if (itemList!=null && itemList.size()>0) {
+ for (int i = 0;i<itemList.size();i++) {
+ JSONObject jsonObject = itemList.getJSONObject(i);
+ KeywordsObject fqdnObject = new KeywordsObject();
+ fqdnObject.setItemId(Integer.parseInt(jsonObject.get(Constant.TSG_ITEM_ID).toString()));
+ List<String> list1 = JSONUtil.toList(jsonObject.get(Constant.TSG_POLICY_KEYWORDARRAY).toString(), String.class);
+ if (list1!=null && list1.size()>0) {
+ List<String> newKeyword = new ArrayList<>();
+ newKeyword.add(list1.get(0).substring(1));
+ fqdnObject.setKeywordArray(newKeyword);
+ }
+ list.add(fqdnObject);
+ }
+ }
+ return ResponseData.ok(list);
+ }else {
+ return ResponseData.error();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResponseData.error();
+ }
+ }
+
+ @PutMapping
+ public ResponseData put(@RequestBody KeywordsSource source) {
+ try {
+ JSONArray array =new JSONArray();
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.set(Constant.TSG_OBJECT_ID,ToTsgSystemUtil.fqdnObjectId);
+ jsonObject.set(Constant.TSG_OBJECT_TYPE,Constant.TSG_FQDN_OBJECT);
+ jsonObject.set(Constant.TSG_OBJECT_NAME,ToTsgSystemUtil.fqdnObjectName);
+ jsonObject.set(Constant.TSG_IS_BUILTIN,0);
+ jsonObject.set(Constant.TSG_IS_EXCLUSION,0);
+ jsonObject.set(Constant.TSG_IS_VALID,1);
+ if (source.getAddItemList()!=null && source.getAddItemList().size()>0) {
+ for (KeywordsObject obj :source.getAddItemList()) {
+ if (obj.getKeywordArray().size()>1) {
+ log.error("KeywordArray的长度只能为1");
+ return ResponseData.error("KeywordArray的长度只能为1");
+ }
+ updateKeywordArray(obj);
+ }
+ JSONArray jsonArray = JSONUtil.parseArray(source.getAddItemList());
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ obj.set("isHexbin",0);
+ obj.set("exprType",0);
+ obj.set(Constant.TSG_IS_BUILTIN,0);
+ }
+ jsonObject.set("addItemList",jsonArray);
+ }else {
+ jsonObject.set("addItemList",new JSONArray());
+ }
+ if (source.getUpdateItemList()!=null && source.getUpdateItemList().size()>0) {
+ for (KeywordsObject obj :source.getUpdateItemList()) {
+ if (obj.getKeywordArray().size()>1) {
+ log.error("KeywordArray的长度只能为1");
+ return ResponseData.error("KeywordArray的长度只能为1");
+ }
+ updateKeywordArray(obj);
+ }
+ JSONArray jsonArray = JSONUtil.parseArray(source.getUpdateItemList());
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ obj.set("isHexbin",0);
+ obj.set("exprType",0);
+ obj.set(Constant.TSG_IS_BUILTIN,0);
+ }
+ jsonObject.set("updateItemList",jsonArray);
+ }else {
+ jsonObject.set("updateItemList",new JSONArray());
+ }
+ if (source.getDeleteItemList()!=null && source.getDeleteItemList().size()>0) {
+ JSONArray jsonArray = JSONUtil.parseArray(source.getDeleteItemList());
+ Integer[] deleteItemIds = new Integer[source.getDeleteItemList().size()];
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ deleteItemIds[i] = Integer.parseInt(obj.get("itemId").toString());
+ }
+ jsonObject.set("deleteItemIds",deleteItemIds);
+ }else {
+ jsonObject.set("deleteItemIds",new JSONArray());
+ }
+ array.add(jsonObject);
+ boolean b = tsgService.updateObject(array);
+ if (b) {
+ return ResponseData.ok();
+ } else {
+ return ResponseData.error();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResponseData.error();
+ }
+ }
+
+ private void updateKeywordArray(KeywordsObject obj) {
+ List<String> newKeyword = new ArrayList<>();
+ List<String> keywordArray = obj.getKeywordArray();
+ if (keywordArray!=null && keywordArray.size()>0) {
+ for (String str: keywordArray){
+ newKeyword.add("$"+str);
+ }
+ obj.setKeywordArray(newKeyword);
+ }
+ }
+
+}
diff --git a/src/main/java/com/example/nis/controller/IpController.java b/src/main/java/com/example/nis/controller/IpController.java
new file mode 100644
index 0000000..93d86b9
--- /dev/null
+++ b/src/main/java/com/example/nis/controller/IpController.java
@@ -0,0 +1,120 @@
+package com.example.nis.controller;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.example.nis.common.ResponseData;
+import com.example.nis.common.TsgServiceImpl;
+import com.example.nis.domain.IpObject;
+import com.example.nis.domain.IpSource;
+import com.example.nis.domain.KeywordsObject;
+import com.example.nis.util.Constant;
+import com.example.nis.util.ToTsgSystemUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+@Slf4j
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/v1/ip")
+public class IpController {
+
+ private final TsgServiceImpl tsgService;
+
+ @GetMapping
+ public ResponseData get(IpObject object) {
+ try {
+ if (object !=null) {
+ Integer[] itemIds = null;
+ if (StringUtils.isNotEmpty(object.getItemIds())) {
+ String[] split = object.getItemIds().split(",");
+ itemIds = new Integer[split.length];
+ for (int i =0;i<split.length;i++) {
+ itemIds[i] = Integer.parseInt(split[i]);
+ }
+ }
+ JSONArray itemList = tsgService.getItemList(ToTsgSystemUtil.ipObjectId, Constant.TSG_ITEM_IP, object.getItemId(), itemIds, object.getIp(), object.getPort(), null);
+ List<IpObject> list = new ArrayList<>();
+ if (itemList!=null && itemList.size()>0) {
+ for (int i = 0;i<itemList.size();i++) {
+ JSONObject jsonObject = itemList.getJSONObject(i);
+ IpObject ipObject = new IpObject();
+ ipObject.setItemId(Integer.parseInt(jsonObject.get(Constant.TSG_ITEM_ID).toString()));
+ ipObject.setIp(jsonObject.get(Constant.TSG_ITEM_IP).toString());
+ ipObject.setPort(jsonObject.get(Constant.TSG_ITEM_PORT).toString());
+ list.add(ipObject);
+ }
+ }
+ return ResponseData.ok(list);
+ }else {
+ return ResponseData.error();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResponseData.error();
+ }
+ }
+
+ @PutMapping
+ public ResponseData put(@RequestBody IpSource source) {
+ try {
+ JSONArray array =new JSONArray();
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.set(Constant.TSG_OBJECT_ID,ToTsgSystemUtil.ipObjectId);
+ jsonObject.set(Constant.TSG_OBJECT_TYPE,Constant.TSG_IP_ADDR_OBJECT);
+ jsonObject.set(Constant.TSG_OBJECT_NAME,ToTsgSystemUtil.ipObjectName);
+ jsonObject.set(Constant.TSG_IS_BUILTIN,0);
+ jsonObject.set(Constant.TSG_IS_EXCLUSION,0);
+ jsonObject.set(Constant.TSG_IS_VALID,1);
+ if (source.getAddItemList()!=null && source.getAddItemList().size()>0) {
+ JSONArray jsonArray = JSONUtil.parseArray(source.getAddItemList());
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ obj.set(Constant.TSG_ITEM_ISSESSION,Constant.TSG_ITEM_ENDPOINT);
+ }
+ jsonObject.set("addItemList",jsonArray);
+ }else {
+ jsonObject.set("addItemList",new JSONArray());
+ }
+ if (source.getUpdateItemList()!=null && source.getUpdateItemList().size()>0) {
+ JSONArray jsonArray = JSONUtil.parseArray(source.getUpdateItemList());
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ obj.set(Constant.TSG_ITEM_ISSESSION,Constant.TSG_ITEM_ENDPOINT);
+ }
+ jsonObject.set("updateItemList",jsonArray);
+ }else {
+ jsonObject.set("updateItemList",new JSONArray());
+ }
+ if (source.getDeleteItemList()!=null && source.getDeleteItemList().size()>0) {
+ JSONArray jsonArray = JSONUtil.parseArray(source.getDeleteItemList());
+ Integer[] deleteItemIds = new Integer[source.getDeleteItemList().size()];
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ deleteItemIds[i] = Integer.parseInt(obj.get("itemId").toString());
+ }
+ jsonObject.set("deleteItemIds",deleteItemIds);
+ }else {
+ jsonObject.set("deleteItemIds",new JSONArray());
+ }
+ array.add(jsonObject);
+ boolean b = tsgService.updateObject(array);
+ if (b) {
+ return ResponseData.ok();
+ } else {
+ return ResponseData.error();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResponseData.error();
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/example/nis/controller/UrlController.java b/src/main/java/com/example/nis/controller/UrlController.java
new file mode 100644
index 0000000..e0e3c67
--- /dev/null
+++ b/src/main/java/com/example/nis/controller/UrlController.java
@@ -0,0 +1,150 @@
+package com.example.nis.controller;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.example.nis.common.ResponseData;
+import com.example.nis.common.TsgServiceImpl;
+import com.example.nis.domain.IpObject;
+import com.example.nis.domain.KeywordsObject;
+import com.example.nis.domain.KeywordsSource;
+import com.example.nis.util.Constant;
+import com.example.nis.util.ToTsgSystemUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Slf4j
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/v1/url")
+public class UrlController {
+
+ private final TsgServiceImpl tsgService;
+
+ @GetMapping
+ public ResponseData get(KeywordsObject object) {
+ try {
+ if (object !=null) {
+ Integer[] itemIds = null;
+ if (StringUtils.isNotEmpty(object.getItemIds())) {
+ String[] split = object.getItemIds().split(",");
+ itemIds = new Integer[split.length];
+ for (int i =0;i<split.length;i++) {
+ itemIds[i] = Integer.parseInt(split[i]);
+ }
+ }
+ JSONArray itemList = tsgService.getItemList(ToTsgSystemUtil.urlObjectId, "url", object.getItemId(), itemIds, null, null, object.getKeywords());
+ List<KeywordsObject> list = new ArrayList<>();
+ if (itemList!=null && itemList.size()>0) {
+ for (int i = 0;i<itemList.size();i++) {
+ JSONObject jsonObject = itemList.getJSONObject(i);
+ KeywordsObject urlObject = new KeywordsObject();
+ urlObject.setItemId(Integer.parseInt(jsonObject.get(Constant.TSG_ITEM_ID).toString()));
+ List<String> list1 = JSONUtil.toList(jsonObject.get(Constant.TSG_POLICY_KEYWORDARRAY).toString(), String.class);
+ if (list1!=null && list1.size()>0) {
+ List<String> newKeyword = new ArrayList<>();
+ newKeyword.add(list1.get(0).substring(1));
+ urlObject.setKeywordArray(newKeyword);
+ }
+ list.add(urlObject);
+ }
+ }
+ return ResponseData.ok(list);
+ }else {
+ return ResponseData.error();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResponseData.error();
+ }
+ }
+
+ @PutMapping
+ public ResponseData put(@RequestBody KeywordsSource source) {
+ try {
+ JSONArray array =new JSONArray();
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.set(Constant.TSG_OBJECT_ID,ToTsgSystemUtil.urlObjectId);
+ jsonObject.set(Constant.TSG_OBJECT_TYPE,Constant.TSG_URL_OBJECT);
+ jsonObject.set(Constant.TSG_OBJECT_NAME,ToTsgSystemUtil.urlObjectName);
+ jsonObject.set(Constant.TSG_IS_BUILTIN,0);
+ jsonObject.set(Constant.TSG_IS_EXCLUSION,0);
+ jsonObject.set(Constant.TSG_IS_VALID,1);
+ if (source.getAddItemList()!=null && source.getAddItemList().size()>0) {
+ for (KeywordsObject obj :source.getAddItemList()) {
+ if (obj.getKeywordArray().size()>1) {
+ log.error("KeywordArray的长度只能为1");
+ return ResponseData.error("KeywordArray的长度只能为1");
+ }
+ updateKeywordArray(obj);
+ }
+ JSONArray jsonArray = JSONUtil.parseArray(source.getAddItemList());
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ obj.set("isHexbin",0);
+ obj.set("exprType",0);
+ obj.set(Constant.TSG_IS_BUILTIN,0);
+ }
+ jsonObject.set("addItemList",jsonArray);
+ }else {
+ jsonObject.set("addItemList",new JSONArray());
+ }
+ if (source.getUpdateItemList()!=null && source.getUpdateItemList().size()>0) {
+ for (KeywordsObject obj :source.getUpdateItemList()) {
+ if (obj.getKeywordArray().size()>1) {
+ log.error("KeywordArray的长度只能为1");
+ return ResponseData.error("KeywordArray的长度只能为1");
+ }
+ updateKeywordArray(obj);
+ }
+ JSONArray jsonArray = JSONUtil.parseArray(source.getUpdateItemList());
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ obj.set("isHexbin",0);
+ obj.set("exprType",0);
+ obj.set(Constant.TSG_IS_BUILTIN,0);
+ }
+ jsonObject.set("updateItemList",jsonArray);
+ }else {
+ jsonObject.set("updateItemList",new JSONArray());
+ }
+ if (source.getDeleteItemList()!=null && source.getDeleteItemList().size()>0) {
+ JSONArray jsonArray = JSONUtil.parseArray(source.getDeleteItemList());
+ Integer[] deleteItemIds = new Integer[source.getDeleteItemList().size()];
+ for (int i =0;i<jsonArray.size();i++) {
+ JSONObject obj = jsonArray.getJSONObject(i);
+ deleteItemIds[i] = Integer.parseInt(obj.get("itemId").toString());
+ }
+ jsonObject.set("deleteItemIds",deleteItemIds);
+ }else {
+ jsonObject.set("deleteItemIds",new JSONArray());
+ }
+ array.add(jsonObject);
+ boolean b = tsgService.updateObject(array);
+ if (b) {
+ return ResponseData.ok();
+ } else {
+ return ResponseData.error();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResponseData.error();
+ }
+ }
+
+ private void updateKeywordArray(KeywordsObject obj) {
+ List<String> newKeyword = new ArrayList<>();
+ List<String> keywordArray = obj.getKeywordArray();
+ if (keywordArray!=null && keywordArray.size()>0) {
+ for (String str: keywordArray){
+ newKeyword.add("$"+str);
+ }
+ obj.setKeywordArray(newKeyword);
+ }
+ }
+}
diff --git a/src/main/java/com/example/nis/domain/IpObject.java b/src/main/java/com/example/nis/domain/IpObject.java
new file mode 100644
index 0000000..c488f26
--- /dev/null
+++ b/src/main/java/com/example/nis/domain/IpObject.java
@@ -0,0 +1,19 @@
+package com.example.nis.domain;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class IpObject implements Serializable {
+
+
+ private Integer itemId;
+ @JsonIgnore
+ private String itemIds;
+ private String ip;
+ private String port;
+
+
+}
diff --git a/src/main/java/com/example/nis/domain/IpSource.java b/src/main/java/com/example/nis/domain/IpSource.java
new file mode 100644
index 0000000..0da5928
--- /dev/null
+++ b/src/main/java/com/example/nis/domain/IpSource.java
@@ -0,0 +1,14 @@
+package com.example.nis.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class IpSource implements Serializable {
+
+ private List<IpObject> addItemList;
+ private List<IpObject> updateItemList;
+ private List<IpObject> deleteItemList;
+}
diff --git a/src/main/java/com/example/nis/domain/KeywordsObject.java b/src/main/java/com/example/nis/domain/KeywordsObject.java
new file mode 100644
index 0000000..02fa798
--- /dev/null
+++ b/src/main/java/com/example/nis/domain/KeywordsObject.java
@@ -0,0 +1,18 @@
+package com.example.nis.domain;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class KeywordsObject implements Serializable {
+
+ private Integer itemId;
+ @JsonIgnore
+ private String itemIds;
+ @JsonIgnore
+ private String keywords;
+ private List<String> keywordArray;
+}
diff --git a/src/main/java/com/example/nis/domain/KeywordsSource.java b/src/main/java/com/example/nis/domain/KeywordsSource.java
new file mode 100644
index 0000000..f17f196
--- /dev/null
+++ b/src/main/java/com/example/nis/domain/KeywordsSource.java
@@ -0,0 +1,15 @@
+package com.example.nis.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class KeywordsSource implements Serializable {
+
+
+ private List<KeywordsObject> addItemList;
+ private List<KeywordsObject> updateItemList;
+ private List<KeywordsObject> deleteItemList;
+}
diff --git a/src/main/java/com/example/nis/util/Constant.java b/src/main/java/com/example/nis/util/Constant.java
new file mode 100644
index 0000000..2f5b6c1
--- /dev/null
+++ b/src/main/java/com/example/nis/util/Constant.java
@@ -0,0 +1,157 @@
+package com.example.nis.util;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * 常量
+ *
+ * @author Mark [email protected]
+ */
+@Component
+public class Constant {
+ /**
+ * 超级管理员ID
+ */
+ public static final int SUPER_ADMIN = 1;
+
+
+ /**
+ * TSG 通用字段名称
+ */
+ public static String TSG_SUCCESS_CODE = "200";
+ public static String TSG_CODE = "code";
+ public static String TSG_DATA = "data";
+ public static String TSG_LIST = "list";
+ public static String TSG_ADD = "add";
+ public static String TSG_UPDATE = "update";
+ public static String TSG_PAGE_NO = "pageNo";
+ public static String TSG_PAGE_SIZE = "pageSize";
+ public static String TSG_APPLICATION_JSON = "application/json;charset=UTF-8";
+ public static String TSG_OP_ACTION = "opAction";
+ public static String TSG_RETURN_DATA = "returnData";
+ public static String TSG_TSG_SECURITY = "tsg_security";
+ public static String TSG_POLICY_ACTION_DENY = "deny";
+ public static String TSG_POLICY_ACTION_MONITOR = "monitor";
+ public static String TSG_POLICY_ACTION_REDIRECT = "redirect";
+ public static String TSG_POLICY_ACTION_RST = "reset";
+ public static String TSG_POLICY_ACTION_DROP = "drop";
+ public static String TSG_POLICY_ACTION_ALLOW = "allow";
+ public static String TSG_OBJECT_IDS = "objectIds";
+ public static String TSG_REFUSE_CODE = "refuseCode";
+ public static String TSG_POLICY_IDS = "policyIds";
+ public static String TSG_IS_VALID = "isValid";
+ public static String TSG_APP_NAME = "appName";
+ public static String TSG_APP_IDS = "appIds";
+ public static String TSG_IS_INITIALIZE = "isInitialize";
+
+ /**
+ * TSG 策略相关字段名称
+ */
+ public static String TSG_POLICY_LIST = "policyList";
+ public static String TSG_POLICY_ID = "policyId";
+ public static String TSG_POLICY_TYPE = "policyType";
+ public static String TSG_POLICY_NAME = "policyName";
+ public static String TSG_POLICY_DESC = "policyDesc";
+ public static String TSG_POLICY_ACTION = "action";
+ public static String TSG_POLICY_DO_BLACKLIST = "doBlacklist";
+ public static String TSG_POLICY_DO_LOG = "doLog";
+ public static String TSG_POLICY_EFFECTIVE_RANGE = "effectiveRange";
+ public static String TSG_POLICY_TAG_SETS = "tag_sets";
+ public static String TSG_POLICY_USER_REGION = "userRegion";
+ public static String TSG_POLICY_SOURCE = "source";
+ public static String TSG_POLICY_DESTINATION = "destination";
+ public static String TSG_POLICY_FILTER_LIST = "filterList";
+ public static String TSG_POLICY_FILTER = "filter";
+ public static String TSG_POLICY_PROTOCOL_FIELD = "protocolField";
+ public static String TSG_POLICY_APP_ID_OBJECTS = "appIdObjects";
+ public static String TSG_POLICY_APP_SELECTOR_OBJECTS = "appSelectorObjects";
+ public static String TSG_POLICY_PROTOCOL = "protocol";
+ public static String TSG_POLICY_METHOD = "method";
+ public static String TSG_POLICY_TRAFFIC_FORWARD = "traffic_forward";
+ public static String TSG_POLICY_ENABLE = "enable";
+ public static String TSG_POLICY_ADDRTYPE = "addrType";
+ public static String TSG_POLICY_QTYPE = "qtype";
+ public static String TSG_POLICY_ATYPE = "atype";
+ public static String TSG_POLICY_A = "A";
+ public static String TSG_POLICY_AAAA = "AAAA";
+ public static String TSG_POLICY_VALUE = "value";
+ public static String TSG_POLICY_MIN = "min";
+ public static String TSG_POLICY_MAX = "max";
+ public static String TSG_POLICY_TTL = "ttl";
+ public static String TSG_POLICY_ANSWER = "answer";
+ public static String TSG_POLICY_RESOLUTION = "resolution";
+ public static String TSG_POLICY_KEYWORDARRAY = "keywordArray";
+ public static String TSG_POLICY_ADDITEMLIST = "addItemList";
+ public static String TSG_POLICY_APPIDOBJECTLIST = "appIdObjectList";
+ public static String TSG_VSYS_ID="vsysId";
+
+ /**
+ * TSG 对象相关字段名称
+ */
+ public static String TSG_OBJECT_LIST = "objectList";
+ public static String TSG_OBJECT_TYPE = "objectType";
+ public static String TSG_OBJECT_SUB_TYPE = "objectSubType";
+ public static String TSG_SUB_OBJECT_IDS = "subObjectIds";
+ public static String TSG_OBJECT_NAME = "objectName";
+ public static String TSG_OBJECT_DESC = "objectDesc";
+ public static String TSG_IS_EXCLUSION = "isExclusion";
+ public static String TSG_GEO_LOCATION = "geo_location";
+ public static String TSG_IS_BUILTIN = "isBuiltin";
+
+ /**
+ * TSG 单元相关字段名称
+ */
+ public static String TSG_ITEM_TYPE = "itemType";
+ public static String TSG_OBJECT_ID = "objectId";
+ public static String TSG_ITEM_LIST = "itemList";
+ public static String TSG_ITEM_ID = "itemId";
+ public static String TSG_ITEM_NAME = "itemName";
+ public static String TSG_ITEM_DESC = "itemDesc";
+ public static String TSG_ITEM_IDS = "itemIds";
+ public static String TSG_ITEM_ISSESSION = "isSession";
+ public static String TSG_ITEM_ENDPOINT = "endpoint";
+ public static String TSG_ITEM_PORT = "port";
+ public static String TSG_ITEM_IP = "ip";
+ public static String TSG_ITEM_KEYWORDS = "keywords";
+
+ /**
+ * TSG 对象类型常量
+ */
+ public static String TSG_IP_ADDR_OBJECT = "ip";
+ public static String TSG_FQDN_OBJECT = "fqdn";
+ public static String TSG_SUBSCRIBERID_OBJECT = "subscriberid";
+ public static String TSG_HTTP_SIGNATURE_OBJECT = "http_signature";
+ public static String TSG_KEYWORDS_OBJECT = "keywords";
+ public static String TSG_URL_OBJECT = "url";
+ public static String TSG_FQDN_CATEGORY_OBJECT = "fqdn_category";
+ public static String TSG_ACCOUNT_OBJECT = "account";
+
+ /**
+ * TSG 协议字段常量
+ */
+ public static String TSG_FIELD_HTTP_URL = "TSG_FIELD_HTTP_URL";
+ public static String TSG_FIELD_HTTP_HOST = "TSG_FIELD_HTTP_HOST";
+ public static String TSG_FIELD_FTP_CONTENT = "TSG_FIELD_FTP_CONTENT";
+ public static String TSG_FIELD_MAIL_SUBJECT = "TSG_FIELD_MAIL_SUBJECT";
+ public static String TSG_FIELD_MAIL_CONTENT = "TSG_FIELD_MAIL_CONTENT";
+ public static String TSG_FIELD_MAIL_ATT_NAME = "TSG_FIELD_MAIL_ATT_NAME";
+ public static String TSG_FIELD_HTTP_REQ_CONTENT = "TSG_FIELD_HTTP_REQ_CONTENT";
+ public static String TSG_FIELD_HTTP_RES_CONTENT = "TSG_FIELD_HTTP_RES_CONTENT";
+ public static String TSG_FIELD_HTTP_RES_BODY = "TSG_FIELD_HTTP_RES_BODY";
+ public static String TSG_FIELD_HTTP_REQ_BODY = "TSG_FIELD_HTTP_REQ_BODY";
+ public static String TSG_FIELD_HTTP_RES_HDR = "TSG_FIELD_HTTP_RES_HDR";
+ public static String TSG_FIELD_DNS_QNAME = "TSG_FIELD_DNS_QNAME";
+ public static String TSG_SECURITY_SOURCE_LOCATION = "TSG_SECURITY_SOURCE_LOCATION";
+ public static String TSG_SECURITY_DESTINATION_LOCATION = "TSG_SECURITY_DESTINATION_LOCATION";
+ public static String TSG_SECURITY_DESTINATION_ADDR = "TSG_SECURITY_DESTINATION_ADDR";
+ public static String TSG_SECURITY_SOURCE_ADDR = "TSG_SECURITY_SOURCE_ADDR";
+ public static String TSG_FIELD_MAIL_ACCOUNT = "TSG_FIELD_MAIL_ACCOUNT";
+ public static String TSG_FIELD_SSL_SNI = "TSG_FIELD_SSL_SNI";
+ public static String TSG_FIELD_SSL_CN = "TSG_FIELD_SSL_CN";
+ public static String TSG_FIELD_SSL_SAN = "TSG_FIELD_SSL_SAN";
+
+
+
+
+
+}
diff --git a/src/main/java/com/example/nis/util/ToTsgSystemUtil.java b/src/main/java/com/example/nis/util/ToTsgSystemUtil.java
new file mode 100644
index 0000000..ef464d1
--- /dev/null
+++ b/src/main/java/com/example/nis/util/ToTsgSystemUtil.java
@@ -0,0 +1,110 @@
+package com.example.nis.util;
+
+import cn.hutool.http.HttpRequest;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+@Component
+public class ToTsgSystemUtil {
+
+ public static Integer ipObjectId;
+ public static Integer urlObjectId;
+ public static Integer fqdnObjectId;
+ @Value("${tsg.system.ipObjectId}")
+ public void setIpObjectId(Integer objectId) {
+ ipObjectId = objectId;
+ }
+ @Value("${tsg.system.urlObjectId}")
+ public void setUrlObjectId(Integer objectId) {
+ urlObjectId = objectId;
+ }
+ @Value("${tsg.system.fqdnObjectId}")
+ public void setFqdnObjectId(Integer objectId) {
+ fqdnObjectId = objectId;
+ }
+ public static String ipObjectName;
+ public static String urlObjectName;
+ public static String fqdnObjectName;
+ @Value("${tsg.system.ipObjectName}")
+ public void setIpObjectName(String objectName) {
+ ipObjectName = objectName;
+ }
+ @Value("${tsg.system.urlObjectName}")
+ public void setUrlObjectName(String objectName) {
+ urlObjectName = objectName;
+ }
+ @Value("${tsg.system.fqdnObjectName}")
+ public void setFqdnObjectName(String objectName) {
+ fqdnObjectName = objectName;
+ }
+
+ public static String TSG_URL;
+ private static String TSG_USERNAME;
+ private static String TSG_PASSWORD;
+ private static Integer httpTimeOut;
+ @Value("${tsg.system.httpTimeOut}")
+ public void setTsgUrl(Integer timeOut) {
+ httpTimeOut = timeOut;
+ }
+ @Value("${tsg.system.url}")
+ public void setTsgUrl(String url) {
+ TSG_URL = url;
+ }
+ @Value("${tsg.system.username}")
+ private void setTsgUsername(String username) {
+ TSG_USERNAME = username;
+ }
+ @Value("${tsg.system.password}")
+ private void setTsgPassword(String password) {
+ TSG_PASSWORD = password;
+ }
+
+
+
+
+ /**
+ * 发送登录请求 获取 token
+ * @return
+ * @throws Exception
+ */
+ public static String sendLoginRequest() throws Exception {
+ String token = "";
+ Map<String, Object> map = new HashMap<>();
+ map.put("username",TSG_USERNAME);
+ map.put("password",TSG_PASSWORD);
+ try {
+ long start = System.currentTimeMillis();
+ log.info("【TSG】 获取token开始");
+ String response = HttpRequest.post(TSG_URL + "v1/user/login")
+ .form(map)
+ .timeout(httpTimeOut)
+ .execute().body();
+ long end = System.currentTimeMillis();
+ log.info("【TSG】 获取token结束,用时:"+(end-start));
+ if (StringUtils.isNotBlank(response)) {
+ JSONObject jsonObject = JSONUtil.parseObj(response);
+ if ("200".equals(jsonObject.get("code").toString())) {
+ token = JSONUtil.parseObj(jsonObject.get("data")).get("token").toString();
+ }else {
+ log.error("获取TSG系统token失败!Response:{}", response);
+ }
+ } else {
+ log.error("获取TSG系统token失败!Response:{}", response);
+ }
+ } catch (Exception e) {
+ log.error("获取TSG系统token失败!", e);
+ throw e;
+ }
+ return token;
+ }
+
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
new file mode 100644
index 0000000..e96a0e3
--- /dev/null
+++ b/src/main/resources/application.yml
@@ -0,0 +1,25 @@
+server:
+ port: 9999
+
+spring:
+ application:
+ name: FJ-Transform-Project
+
+
+# TSG 账号
+tsg:
+ system:
+ url: http://192.168.45.51:8080/
+ username: admin
+ password: aSdvVT7Fg81kJBuT7T7T7g==
+ # http 超时时间
+ httpTimeOut: 3600000
+ ipObjectId: 157
+ ipObjectName: sg-test
+ urlObjectId: 158
+ urlObjectName: sg-test
+ fqdnObjectId: 159
+ fqdnObjectName: sg-test
+
+
+
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
new file mode 100644
index 0000000..6d9e712
--- /dev/null
+++ b/src/main/resources/log4j.properties
@@ -0,0 +1,7 @@
+###set log levels###
+log4j.rootLogger=debug, stdout
+###output to the console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n \ No newline at end of file
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..a29e7bb
--- /dev/null
+++ b/src/main/resources/logback-spring.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="true" scanPeriod="60 seconds" debug="false">
+ <springProperty scope="context" name="springAppName" source="spring.application.name"/>
+ <property name="log.path" value="log/${springAppName}"/>
+ <property name="log.maxHistory" value="15"/>
+ <property name="log.colorPattern"
+ value="%magenta(%d{yyyy-MM-dd HH:mm:ss}) %highlight(%-5level) %boldCyan(${springAppName:-}) %yellow(%thread) %green(%logger) %msg%n"/>
+ <property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5level ${springAppName:-} %thread %logger %msg%n"/>
+
+ <!--输出到控制台-->
+ <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>${log.colorPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <!--输出到文件-->
+ <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>${log.path}/info/info.%d{yyyy-MM-dd}.log</fileNamePattern>
+ <MaxHistory>${log.maxHistory}</MaxHistory>
+ </rollingPolicy>
+ <encoder>
+ <pattern>${log.pattern}</pattern>
+ </encoder>
+ <filter class="ch.qos.logback.classic.filter.LevelFilter">
+ <level>INFO</level>
+ <onMatch>ACCEPT</onMatch>
+ <onMismatch>DENY</onMismatch>
+ </filter>
+ </appender>
+
+ <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>${log.path}/error/error.%d{yyyy-MM-dd}.log</fileNamePattern>
+ </rollingPolicy>
+ <encoder>
+ <pattern>${log.pattern}</pattern>
+ </encoder>
+ <filter class="ch.qos.logback.classic.filter.LevelFilter">
+ <level>ERROR</level>
+ <onMatch>ACCEPT</onMatch>
+ <onMismatch>DENY</onMismatch>
+ </filter>
+ </appender>
+ <root level="info">
+ <appender-ref ref="console"/>
+ <appender-ref ref="file_info"/>
+ <appender-ref ref="file_error"/>
+ </root>
+
+ <!--<root level="debug">
+ <appender-ref ref="file_info"/>
+ <appender-ref ref="file_error"/>
+ </root>-->
+</configuration>
diff --git a/src/test/java/com/example/nis/FjTransformApiApplicationTests.java b/src/test/java/com/example/nis/FjTransformApiApplicationTests.java
new file mode 100644
index 0000000..915590c
--- /dev/null
+++ b/src/test/java/com/example/nis/FjTransformApiApplicationTests.java
@@ -0,0 +1,13 @@
+package com.example.nis;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class FjTransformApiApplicationTests {
+
+ @Test
+ void contextLoads() {
+ }
+
+}