Prechádzať zdrojové kódy

修正安全管理编译错误

louhr 5 rokov pred
rodič
commit
dc03f3b9aa

+ 66 - 0
kernel/src/main/java/com/lantone/qc/kernel/config/SwaggerConfigurer.java

@@ -0,0 +1,66 @@
+package com.lantone.qc.kernel.config;
+
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Parameter;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * @Description: Swagger配置类
+ * @author: gaodm
+ * @time: 2018/8/2 14:21
+ */
+@Configuration
+//@ConditionalOnProperty(prefix = "swagger", value = { "enable" }, havingValue = "true")
+@EnableSwagger2
+public class SwaggerConfigurer {
+    /**
+     * 全局参数
+     *
+     * @return
+     */
+    private List<Parameter> parameter() {
+        List<Parameter> params = new ArrayList<>();
+//        params.add(new ParameterBuilder().name("Authorization")
+//                .description("Authorization Bearer token")
+//                .modelRef(new ModelRef("string"))
+//                .parameterType("header")
+//                .required(false).build());
+        return params;
+    }
+
+
+    @Bean
+    public Docket sysApi() {
+        return new Docket(DocumentationType.SWAGGER_2)
+                .apiInfo(apiInfo())
+                .select()
+                .apis(RequestHandlerSelectors.basePackage("com.lantone.qc.kernel.web"))
+                .paths(PathSelectors.any())
+                .build().globalOperationParameters(parameter());
+        //.securitySchemes(newArrayList(oauth()))
+        // .securityContexts(newArrayList(securityContext()));
+    }
+
+    private ApiInfo apiInfo() {
+        return new ApiInfoBuilder()
+                .title("Quality Control API ")
+                .description("QC 微服务")
+                .termsOfServiceUrl("")
+//                .contact("diagbot")
+                .version("1.0")
+                .build();
+    }
+
+}

+ 5 - 49
nlp/pom.xml

@@ -17,62 +17,18 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <maven.compiler.source>1.7</maven.compiler.source>
-        <maven.compiler.target>1.7</maven.compiler.target>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
     </properties>
 
     <dependencies>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.11</version>
-            <scope>test</scope>
+            <groupId>com.lantone.qc</groupId>
+            <artifactId>public</artifactId>
+            <version>1.0</version>
         </dependency>
     </dependencies>
 
     <build>
-        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
-            <plugins>
-                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
-                <plugin>
-                    <artifactId>maven-clean-plugin</artifactId>
-                    <version>3.1.0</version>
-                </plugin>
-                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
-                <plugin>
-                    <artifactId>maven-resources-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-compiler-plugin</artifactId>
-                    <version>3.8.0</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-surefire-plugin</artifactId>
-                    <version>2.22.1</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-jar-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-install-plugin</artifactId>
-                    <version>2.5.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-deploy-plugin</artifactId>
-                    <version>2.8.2</version>
-                </plugin>
-                <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
-                <plugin>
-                    <artifactId>maven-site-plugin</artifactId>
-                    <version>3.7.1</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-project-info-reports-plugin</artifactId>
-                    <version>3.0.0</version>
-                </plugin>
-            </plugins>
-        </pluginManagement>
     </build>
 </project>

+ 2 - 2
nlp/src/main/java/com/lantone/qc/nlp/participle/cfg/DefaultConfig.java

@@ -1,8 +1,8 @@
 package com.lantone.qc.nlp.participle.cfg;
 
 import com.lantone.qc.nlp.participle.word.Segment;
-import org.diagbot.pub.utils.PropertiesUtil;
-import org.diagbot.pub.utils.security.EncrypDES;
+import com.lantone.qc.pub.util.EncrypDES;
+import com.lantone.qc.pub.util.PropertiesUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.StringUtils;

+ 73 - 0
public/src/main/java/com/lantone/qc/pub/util/EncrypDES.java

@@ -0,0 +1,73 @@
+package com.lantone.qc.pub.util;
+
+import org.apache.commons.codec.binary.Base64;
+
+import javax.crypto.*;
+import javax.crypto.spec.DESKeySpec;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+
+/**
+ * @ClassName org.diagbot.pub.utils.security.EncrypDES
+ * @Description TODO
+ * @Author fyeman
+ * @Date 2019/2/22/022 14:44
+ * @Version 1.0
+ **/
+public class EncrypDES {
+    //随机加密串
+    private String key = "AUYEJHHH2019";
+    // SecretKey 负责保存对称密钥
+    private SecretKey deskey;
+    // Cipher负责完成加密或解密工作
+    private Cipher c;
+    // 该字节数组负责保存加密的结果
+    private byte[] cipherByte;
+
+    public EncrypDES() throws Exception {
+        DESKeySpec desKey = new DESKeySpec(key.getBytes("utf-8"));
+        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
+        // 生成密钥
+        deskey = keyFactory.generateSecret(desKey);
+        // 生成Cipher对象,指定其支持的DES算法
+        c = Cipher.getInstance("DES");
+    }
+
+    /**
+     * 对字符串加密
+     *
+     * @param str
+     * @return
+     * @throws InvalidKeyException
+     * @throws IllegalBlockSizeException
+     * @throws BadPaddingException
+     */
+    public String encrytor(String str) throws InvalidKeyException,
+            IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
+        // 根据密钥,对Cipher对象进行初始化,ENCRYPT_MODE表示加密模式
+        c.init(Cipher.ENCRYPT_MODE, deskey);
+        byte[] src = str.getBytes("utf-8");
+        // 加密,结果保存进cipherByte
+        cipherByte = c.doFinal(src);
+        return Base64.encodeBase64String(cipherByte);
+    }
+
+    /**
+     * 对字符串解密
+     *
+     * @param str
+     * @return
+     * @throws InvalidKeyException
+     * @throws IllegalBlockSizeException
+     * @throws BadPaddingException
+     */
+    public String decryptor(String str) throws InvalidKeyException,
+            IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
+        byte[] buff = Base64.decodeBase64(str);
+        // 根据密钥,对Cipher对象进行初始化,DECRYPT_MODE表示加密模式
+        c.init(Cipher.DECRYPT_MODE, deskey);
+        cipherByte = c.doFinal(buff);
+        return new String(cipherByte, "utf-8");
+    }
+}
+

+ 102 - 0
public/src/main/java/com/lantone/qc/pub/util/PropertiesUtil.java

@@ -0,0 +1,102 @@
+/**   
+* @Company: 杭州朗通信息技术有限公司 
+* @Department: 系统软件部 
+* @Description: 朗通智能辅助诊疗系统 
+* @Address: 浙江省杭州市西湖区西斗门路3号 天堂软件园D-7B 
+*/
+package com.lantone.qc.pub.util;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+
+
+/**
+* @Title: PropertiesUtil.java 
+* @Package com.lantone.common.util 
+* @Description: 加载文件
+* @author cm   
+* @date 2015年10月09日 下午11:03:28 
+* @version V1.0
+ */
+public class PropertiesUtil {
+	
+	private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
+
+	private static ResourceLoader resourceLoader = new DefaultResourceLoader();
+
+	private final Properties properties;
+
+	public PropertiesUtil(String... resourcesPaths) {
+		properties = loadProperties(resourcesPaths);
+	}
+
+	public Properties getProperties() {
+		return properties;
+	}
+
+	/**
+	 * 取出Property。
+	 */
+	private String getValue(String key) {
+		String systemProperty = System.getProperty(key);
+		if (systemProperty != null) {
+			return systemProperty;
+		}
+		return properties.getProperty(key);
+	}
+
+	/**
+	 * 取出String类型的Property,如果都为Null则抛出异常.
+	 */
+	public String getProperty(String key) {
+		String value = getValue(key);
+		if (value == null) {
+			throw new NoSuchElementException();
+		}
+		return value;
+	}
+
+	/**
+	 * 取出String类型的Property.如果都为Null返回Default值.
+	 */
+	public String getProperty(String key, String defaultValue) {
+		String value = getValue(key);
+		return value != null ? value : defaultValue;
+	}
+
+	/**
+	 * 载入多个文件, 文件路径使用Spring Resource格式.
+	 */
+	private Properties loadProperties(String... resourcesPaths) {
+		Properties props = new Properties();
+
+		for (String location : resourcesPaths) {
+			logger.debug("Loading properties file from path:{}", location);
+			InputStream is = null;
+			try {
+				Resource resource = resourceLoader.getResource(location);
+				is = resource.getInputStream();
+				props.load(is);
+			} catch (IOException ex) {
+				logger.error("Could not load properties from path:{}, {} ", location, ex.getMessage());
+			} finally {
+				IOUtils.closeQuietly(is);
+			}
+		}
+		return props;
+	}
+	
+	public static void main(String[] args) {
+		PropertiesUtil pl = new PropertiesUtil("classpath:/webservice.properties");
+		//System.out.println(pl.getProperty(InitConfig.HAPI_SERVER_START)); 
+	}
+}

+ 27 - 49
security/pom.xml

@@ -17,62 +17,40 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <maven.compiler.source>1.7</maven.compiler.source>
-        <maven.compiler.target>1.7</maven.compiler.target>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
     </properties>
 
     <dependencies>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.11</version>
-            <scope>test</scope>
+            <groupId>com.lantone.qc</groupId>
+            <artifactId>public</artifactId>
+            <version>1.0</version>
+        </dependency>
+
+        <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>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>1.3.2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-logging</artifactId>
         </dependency>
     </dependencies>
 
     <build>
-        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
-            <plugins>
-                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
-                <plugin>
-                    <artifactId>maven-clean-plugin</artifactId>
-                    <version>3.1.0</version>
-                </plugin>
-                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
-                <plugin>
-                    <artifactId>maven-resources-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-compiler-plugin</artifactId>
-                    <version>3.8.0</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-surefire-plugin</artifactId>
-                    <version>2.22.1</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-jar-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-install-plugin</artifactId>
-                    <version>2.5.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-deploy-plugin</artifactId>
-                    <version>2.8.2</version>
-                </plugin>
-                <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
-                <plugin>
-                    <artifactId>maven-site-plugin</artifactId>
-                    <version>3.7.1</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-project-info-reports-plugin</artifactId>
-                    <version>3.0.0</version>
-                </plugin>
-            </plugins>
-        </pluginManagement>
+        
     </build>
 </project>

+ 5 - 5
security/src/main/java/com/lantone/qc/security/aop/SecurityAop.java

@@ -1,9 +1,9 @@
 package com.lantone.qc.security.aop;
 
-import com.lantone.exception.CommonErrorCode;
-import com.lantone.exception.CommonException;
-import com.lantone.util.TokenUtil;
-import com.lantone.vo.TokenVO;
+import com.lantone.qc.pub.model.vo.TokenVO;
+import com.lantone.qc.security.exception.CommonErrorCode;
+import com.lantone.qc.security.exception.CommonException;
+import com.lantone.qc.security.util.TokenUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.Aspect;
@@ -23,7 +23,7 @@ import org.springframework.stereotype.Component;
 @ConditionalOnProperty(prefix = "mysecurity", value = { "enable" }, havingValue = "true")
 public class SecurityAop {
 
-    @Pointcut("@annotation(com.lantone.aop.Security)")
+    @Pointcut("@annotation(com.lantone.qc.security.aop.Security)")
     public void securityPointCut() {
 
     }

+ 27 - 0
security/src/main/java/com/lantone/qc/security/config/ScheduleTask.java

@@ -0,0 +1,27 @@
+package com.lantone.qc.security.config;
+
+import com.lantone.qc.security.util.TokenUtil;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * @description: 定时器
+ * @author: zhoutg
+ * @time: 2019/11/19 13:52
+ */
+@Component
+@Configuration      //1.主要用于标记配置类,兼备Component的效果。
+@EnableScheduling   // 2.开启定时任务
+@ConditionalOnProperty(prefix = "mysecurity", value = { "enable" }, havingValue = "true")
+public class ScheduleTask {
+
+    // 添加定时任务,每天12点执行
+    @Scheduled(cron = "0 59 23 * * ?")
+    public void configureTasks() {
+        // 有效时间天数 -1
+        TokenUtil.dealDay();
+    }
+}

+ 52 - 0
security/src/main/java/com/lantone/qc/security/config/SecurityConfigurer.java

@@ -0,0 +1,52 @@
+package com.lantone.qc.security.config;
+
+
+import com.lantone.qc.security.exception.CommonErrorCode;
+import com.lantone.qc.security.exception.CommonException;
+import com.lantone.qc.security.util.SerialNumberUtil;
+import com.lantone.qc.security.util.TokenUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
+
+import java.util.Map;
+
+/**
+ * @Description: 安全拦截启动配置
+ * @author: gaodm
+ * @time: 2019/12/24 10:41
+ */
+@Configuration
+@Order(1)
+@Slf4j
+@ConditionalOnProperty(prefix = "mysecurity", value = { "enable" }, havingValue = "true")
+public class SecurityConfigurer {
+
+    @Bean
+    public void SecurityCheck() {
+        log.info("启动安全拦截");
+        // 获取本地配置信息
+        Map<String, String> localMap = SerialNumberUtil.getAllSn();
+        // 读取配置文件到全局参数tokenMap
+        Map<String, String> tokenMap = TokenUtil.getFileContent();
+
+        System.out.println("本地配置信息:" + localMap);
+        System.out.println("文件配置信息:" + tokenMap);
+
+        // 只校验linux配置信息,windows打包如果配置不一致会报错,故屏蔽
+        if ("LINUX".equals(localMap.get("server.os"))) {
+            // 比对参数:cpu 是否一致
+            String param = "server.cpu";
+            if (!localMap.get(param).equals(tokenMap.get(param))) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "启动失败,配置信息不一致");
+            }
+            log.info("启动校验通过");
+        } else {
+            log.info("当前系统不校验配置信息");
+        }
+
+    }
+
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 193 - 0
security/src/main/java/com/lantone/qc/security/util/RSAEncrypt.java


+ 304 - 0
security/src/main/java/com/lantone/qc/security/util/SerialNumberUtil.java

@@ -0,0 +1,304 @@
+package com.lantone.qc.security.util;
+
+import com.lantone.qc.security.exception.CommonErrorCode;
+import com.lantone.qc.security.exception.CommonException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+/**
+ * @description:
+ * @author: zhoutg
+ * @time: 2019/12/23 10:40
+ */
+@Component
+public class SerialNumberUtil {
+    static Logger log = LoggerFactory.getLogger(SerialNumberUtil.class);
+
+    /**
+     * 获取主板序列号
+     *
+     * @return
+     */
+    public static String getMotherboardSN() {
+        String result = "";
+        try {
+            File file = File.createTempFile("realhowto", ".vbs");
+            file.deleteOnExit();
+            FileWriter fw = new FileWriter(file);
+
+            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+                    + "Set colItems = objWMIService.ExecQuery _ \n"
+                    + "   (\"Select * from Win32_BaseBoard\") \n"
+                    + "For Each objItem in colItems \n"
+                    + "    Wscript.Echo objItem.SerialNumber \n"
+                    + "    exit for  ' do the first cpu only! \n" + "Next \n";
+
+            fw.write(vbs);
+            fw.close();
+            String path = file.getPath().replace("%20", " ");
+            Process p = Runtime.getRuntime().exec(
+                    "cscript //NoLogo " + path);
+            BufferedReader input = new BufferedReader(new InputStreamReader(
+                    p.getInputStream()));
+            String line;
+            while ((line = input.readLine()) != null) {
+                result += line;
+            }
+            input.close();
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+            log.error(e.getMessage());
+        }
+        return result.trim();
+    }
+
+    /**
+     * 获取硬盘序列号(该方法获取的是硬盘本身的序列号)
+     * @return
+     */
+    public static String getHardDiskSN() {
+        String result = "";
+        try {
+            File file = File.createTempFile("realhowto", ".vbs");
+            file.deleteOnExit();
+            FileWriter fw = new FileWriter(file);
+            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+                    + "Set colItems = objWMIService.ExecQuery _ \n"
+                    + "   (\"Select * from Win32_DiskDrive\") \n"
+                    + "For Each objItem in colItems \n"
+                    + "    Wscript.Echo objItem.SerialNumber \n"
+                    + "    exit for  ' do the first cpu only! \n" + "Next \n";
+
+            fw.write(vbs);
+            fw.close();
+            String path = file.getPath().replace("%20", " ");
+            Process p = Runtime.getRuntime().exec(
+                    "cscript //NoLogo " + path);
+            BufferedReader input = new BufferedReader(new InputStreamReader(
+                    p.getInputStream()));
+            String line;
+            while ((line = input.readLine()) != null) {
+                result += line;
+            }
+            input.close();
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        return result.trim();
+    }
+
+    /**
+     * 获取CPU序列号
+     *
+     * @return
+     */
+    public static String getCPUSerial() {
+        String result = "";
+        try {
+            File file = File.createTempFile("tmp", ".vbs");
+            file.deleteOnExit();
+            FileWriter fw = new FileWriter(file);
+            String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+                    + "Set colItems = objWMIService.ExecQuery _ \n"
+                    + "   (\"Select * from Win32_Processor\") \n"
+                    + "For Each objItem in colItems \n"
+                    + "    Wscript.Echo objItem.ProcessorId \n"
+                    + "    exit for  ' do the first cpu only! \n" + "Next \n";
+
+            // + "    exit for  \r\n" + "Next";
+            fw.write(vbs);
+            fw.close();
+            String path = file.getPath().replace("%20", " ");
+            Process p = Runtime.getRuntime().exec(
+                    "cscript //NoLogo " + path);
+            BufferedReader input = new BufferedReader(new InputStreamReader(
+                    p.getInputStream()));
+            String line;
+            while ((line = input.readLine()) != null) {
+                result += line;
+            }
+            input.close();
+            file.delete();
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        if (result.trim().length() < 1 || result == null) {
+            result = "无CPU_ID被读取";
+        }
+        return result.trim();
+    }
+
+    private static List<String> getLocalHostLANAddress() throws UnknownHostException, SocketException {
+        List<String> ips = new ArrayList<String>();
+        Enumeration<NetworkInterface> interfs = NetworkInterface.getNetworkInterfaces();
+        while (interfs.hasMoreElements()) {
+            NetworkInterface interf = interfs.nextElement();
+            Enumeration<InetAddress> addres = interf.getInetAddresses();
+            while (addres.hasMoreElements()) {
+                InetAddress in = addres.nextElement();
+                if (in instanceof Inet4Address) {
+                    System.out.println("v4:" + in.getHostAddress());
+                    if (!"127.0.0.1".equals(in.getHostAddress())) {
+                        ips.add(in.getHostAddress());
+                    }
+                }
+            }
+        }
+        return ips;
+    }
+
+    /**
+     * MAC
+     * 通过jdk自带的方法,先获取本机所有的ip,然后通过NetworkInterface获取mac地址
+     *
+     * @return
+     */
+    public static String getMac() {
+        try {
+            String resultStr = "";
+            List<String> ls = getLocalHostLANAddress();
+            for (String str : ls) {
+                InetAddress ia = InetAddress.getByName(str);// 获取本地IP对象
+                // 获得网络接口对象(即网卡),并得到mac地址,mac地址存在于一个byte数组中。
+                byte[] mac = NetworkInterface.getByInetAddress(ia)
+                        .getHardwareAddress();
+                // 下面代码是把mac地址拼装成String
+                StringBuilder sb = new StringBuilder();
+                for (int i = 0; i < mac.length; i++) {
+                    if (i != 0) {
+                        sb.append("-");
+                    }
+                    // mac[i] & 0xFF 是为了把byte转化为正整数
+                    String s = Integer.toHexString(mac[i] & 0xFF);
+                    sb.append(s.length() == 1 ? 0 + s : s);
+                }
+                // 把字符串所有小写字母改为大写成为正规的mac地址并返回
+                resultStr += sb.toString().toUpperCase() + ",";
+            }
+            return resultStr;
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        return null;
+    }
+
+    /***************************linux*********************************/
+
+    public static String executeLinuxCmd(String cmd) {
+        try {
+            System.out.println("got cmd job : " + cmd);
+            Runtime run = Runtime.getRuntime();
+            Process process;
+            process = run.exec(cmd);
+            InputStream in = process.getInputStream();
+            BufferedReader bs = new BufferedReader(new InputStreamReader(in));
+            StringBuffer out = new StringBuffer();
+            byte[] b = new byte[8192];
+            for (int n; (n = in.read(b)) != -1; ) {
+                out.append(new String(b, 0, n));
+            }
+
+            in.close();
+            process.destroy();
+            return out.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * @param cmd    命令语句
+     * @param record 要查看的字段
+     * @param symbol 分隔符
+     * @return
+     */
+    public static String getSerialNumber(String cmd, String record, String symbol) {
+        String execResult = executeLinuxCmd(cmd);
+        String[] infos = execResult.split("\n");
+
+        for (String info : infos) {
+            info = info.trim();
+            if (info.indexOf(record) != -1) {
+                info.replace(" ", "");
+                String[] sn = info.split(symbol);
+                return sn[1];
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 获取CPUID、硬盘序列号、MAC地址、主板序列号
+     *
+     * @return
+     */
+    public static Map<String, String> getAllSn() {
+        String os = System.getProperty("os.name").toUpperCase();
+        Map<String, String> snVo = new HashMap<String, String>();
+        snVo.put("server.os", os);
+        if ("LINUX".equals(os)) {
+            System.out.println("=============>for linux");
+            String cpuid = getSerialNumber("dmidecode -t processor | grep 'ID'", "ID", ":");
+            System.out.println("cpuid : " + cpuid);
+            String mainboardNumber = getSerialNumber("dmidecode |grep 'Serial Number'", "Serial Number", ":");
+            System.out.println("mainboardNumber : " + mainboardNumber);
+            String diskNumber = getSerialNumber("fdisk -l", "Disk identifier", ":");
+            System.out.println("diskNumber : " + diskNumber);
+            // String mac = getSerialNumber("ifconfig -a", "ether", " ");
+            snVo.put("server.cpu", cpuid.toUpperCase().replace(" ", ""));
+            snVo.put("server.disk", diskNumber.toUpperCase().replace(" ", ""));
+            // snVo.put("mac", mac.toUpperCase().replace(" ", ""));
+            snVo.put("server.mainboard", mainboardNumber.toUpperCase().replace(" ", ""));
+
+
+            StringBuffer sb = new StringBuffer();
+            sb.append("server.cpu=" + snVo.get("server.cpu")) // cpu信息
+                    .append("$$")
+                    .append("server.key=" + UUID.randomUUID().toString())              // key信息
+                    .append("$$")
+                    .append("server.remainday=15"); // 剩余天数
+            try {
+                snVo.put("content", RSAEncrypt.encrypt(sb.toString()));
+            } catch (Exception e) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "读取本地配置失败");
+            }
+        } else {
+            System.out.println("=============>for windows");
+            String cpuid = SerialNumberUtil.getCPUSerial();
+            String mainboard = SerialNumberUtil.getMotherboardSN();
+            String disk = SerialNumberUtil.getHardDiskSN();
+            // String mac = SerialNumberUtil.getMac();
+
+            System.out.println("CPU  SN:" + cpuid);
+            System.out.println("主板  SN:" + mainboard);
+            System.out.println("C盘   SN:" + disk);
+            //  System.out.println("MAC  SN:" + mac);
+
+            snVo.put("server.cpu", cpuid.toUpperCase().replace(" ", ""));
+            snVo.put("server.disk", disk.toUpperCase().replace(" ", ""));
+            // snVo.put("server.mac", mac.toUpperCase().replace(" ", ""));
+            snVo.put("server.mainboard", mainboard.toUpperCase().replace(" ", ""));
+        }
+        return snVo;
+    }
+
+    /**
+     * linux
+     * cpuid : dmidecode -t processor | grep 'ID'
+     * mainboard : dmidecode |grep 'Serial Number'
+     * disk : fdisk -l
+     * mac : ifconfig -a
+     *
+     * @param args
+     */
+    public static void main(String[] args) {
+        getAllSn();
+    }
+}

+ 122 - 0
security/src/main/java/com/lantone/qc/security/util/TokenUtil.java

@@ -0,0 +1,122 @@
+package com.lantone.qc.security.util;
+
+
+import com.lantone.qc.pub.model.vo.TokenVO;
+import com.lantone.qc.security.exception.CommonErrorCode;
+import com.lantone.qc.security.exception.CommonException;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * @description: token验证工具类
+ * @author: zhoutg
+ * @time: 2019/12/24 17:07
+ */
+@Slf4j
+public class TokenUtil {
+
+    // 处理文件路径
+    public static final String path = System.getProperty("user.dir") + File.separator + "license.properties";
+
+    // 文件配置信息
+    public static Map<String, String> tokenMap = new LinkedHashMap<>();
+
+    /**
+     * 读取配置文件内容到map
+     *
+     * @return
+     */
+    public static Map<String, String> getFileContent() {
+        BufferedReader br = null;
+        List<String> list = new ArrayList<>();
+        try {
+            br = new BufferedReader(
+                    new InputStreamReader(
+                            new FileInputStream(path), "UTF-8"));
+
+            String lineTxt = br.readLine();
+            String lineTxtDe = RSAEncrypt.decrypt(lineTxt);
+            String[] item = lineTxtDe.split("\\$\\$"); // $$作为分隔符
+            for (String s : item) {
+                String[] keyVal = s.split("=");
+                tokenMap.put(keyVal[0], keyVal[1]);
+            }
+            br.close();
+        } catch (Exception e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "文件信息有误");
+        } finally {
+            try {
+                br.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return tokenMap;
+    }
+
+
+    /**
+     * 有效使用天数-1
+     *
+     * @return
+     */
+    public static void dealDay() {
+        log.info("定时任务执行了!");
+        // 处理内存数据
+        Integer remainday = Integer.parseInt(tokenMap.get("server.remainday"));
+        tokenMap.put("server.remainday", (--remainday).toString());
+
+        // 处理文件内容
+        StringBuffer sb = new StringBuffer();
+        for (String key : tokenMap.keySet()) {
+            sb.append(key);
+            sb.append("=");
+            sb.append(tokenMap.get(key));
+            sb.append("$$");
+        }
+        // 删除最后2个$$
+        String line = sb.toString();
+        line = line.substring(0, line.length() - 2);
+        try {
+            BufferedWriter bw =
+                new BufferedWriter(
+                    new OutputStreamWriter(
+                            new FileOutputStream(path), "UTF-8"));
+            String enLine = RSAEncrypt.encrypt(line);
+            bw.write(enLine);
+            bw.flush();
+        } catch (Exception e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "定时任务执行失败");
+        }
+    }
+
+
+    /**
+     * 校验token:1、剩余天数是否小于0; 2、有效使用时间是否过期
+     *
+     * @param tokenVO
+     * @return
+     */
+    public static boolean verifyToken(TokenVO tokenVO) {
+        try {
+            Map<String, String> map = RSAEncrypt.convertMap(tokenVO.getToken());
+            // 剩余使用天数到期
+            if (Integer.parseInt(map.get("server.remainday")) <= 0) {
+                return false;
+            }
+            // 有效使用时间超时
+            if (Long.parseLong(map.get("server.validtime")) <= new Date().getTime()) {
+                return false;
+            }
+            // 记录日志
+            Map<String, String> tokenMap = TokenUtil.tokenMap;
+            log.info(tokenMap.get("server.provider") + "——" + tokenMap.get("server.hospital") + "调用接口了");
+        } catch (Exception e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "token失效");
+        }
+        return true;
+    }
+
+}