From b28a3e4cc629f1ca9b66a700aa7c9f8f6958c4f1 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 21 Jun 2023 15:56:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(lic):=20lic=E9=AA=8C=E8=AF=81=E6=85=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../license/DefaultLicenseService.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/dataease/commons/license/DefaultLicenseService.java b/backend/src/main/java/io/dataease/commons/license/DefaultLicenseService.java index 3c7a62879c..bc54c5968f 100644 --- a/backend/src/main/java/io/dataease/commons/license/DefaultLicenseService.java +++ b/backend/src/main/java/io/dataease/commons/license/DefaultLicenseService.java @@ -1,10 +1,11 @@ package io.dataease.commons.license; import com.google.gson.Gson; -import io.dataease.plugins.common.base.domain.License; import io.dataease.commons.exception.DEException; import io.dataease.commons.utils.LogUtil; +import io.dataease.plugins.common.base.domain.License; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -12,6 +13,7 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Service public class DefaultLicenseService { @@ -22,13 +24,21 @@ public class DefaultLicenseService { private static final String validatorUtil = "/usr/bin/validator"; private static final String product = "DataEase"; + @Value("${dataease.use_process_lic:false}") + private boolean useProcessLic; + public F2CLicenseResponse validateLicense(String product, String licenseKey) { List command = new ArrayList(); StringBuilder result = new StringBuilder(); command.add(validatorUtil); command.add(licenseKey); try { - execCommand(result, command); + if (useProcessLic) { + execCommand(result, command); + } else { + runtimeExecCommand(result, command); + } + LogUtil.info("read lic content is : " + result.toString()); F2CLicenseResponse f2CLicenseResponse = new Gson().fromJson(result.toString(), F2CLicenseResponse.class); if (f2CLicenseResponse.getStatus() != F2CLicenseResponse.Status.valid) { @@ -47,6 +57,16 @@ public class DefaultLicenseService { } } + private static int runtimeExecCommand(StringBuilder result, List command) throws Exception { + Process proc = Runtime.getRuntime().exec(command.stream().collect(Collectors.joining(" "))); + BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream(), "utf-8")); + String line = null; + while ((line = reader.readLine()) != null) { + result.append(line).append("\n"); + } + return proc.waitFor(); + } + private static int execCommand(StringBuilder result, List command) throws Exception { ProcessBuilder builder = new ProcessBuilder();