Commit b90a4ee9 authored by 赵啸非's avatar 赵啸非

添加门户license验证接口

parent 241121f8
...@@ -55,7 +55,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -55,7 +55,7 @@ public class UploadServiceImpl implements UploadService {
log.error("文件上传大小超过限制,当前文件---" + tempFile.getSize() + ",允许大小----------" + type.getMaxSize()); log.error("文件上传大小超过限制,当前文件---" + tempFile.getSize() + ",允许大小----------" + type.getMaxSize());
throw new AppException("文件上传大小超过限制!"); throw new AppException("文件上传大小超过限制!");
} }
if (null != fileName && fileName.length() > 50) { if (null != fileName && fileName.length() > 100) {
throw new AppException("文件名称过长,无法上传!"); throw new AppException("文件名称过长,无法上传!");
} }
......
...@@ -2,23 +2,36 @@ package com.mortals.xhx.module.cipher.web; ...@@ -2,23 +2,36 @@ package com.mortals.xhx.module.cipher.web;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.utils.CipherUtil; import com.mortals.xhx.common.utils.CipherUtil;
import com.mortals.xhx.common.utils.DecodeUtil; import com.mortals.xhx.common.utils.DecodeUtil;
import com.mortals.xhx.common.utils.LicenseUtil; import com.mortals.xhx.common.utils.LicenseUtil;
import com.mortals.xhx.utils.EncodeUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.nio.charset.Charset;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static com.mortals.framework.web.BaseController.VALUE_RESULT_SUCCESS;
import static com.mortals.xhx.base.framework.exception.ExceptionHandle.*;
/** /**
* 授权文件上传与检测 * 授权文件上传与检测
*
* @author: zxfei * @author: zxfei
* @date: 2024/7/10 9:54 * @date: 2024/7/10 9:54
*/ */
...@@ -36,6 +49,13 @@ public class CipherController { ...@@ -36,6 +49,13 @@ public class CipherController {
@Value("${sys.license.pub}") @Value("${sys.license.pub}")
private String pubPath; private String pubPath;
@Value("${sys.license.enable:false}")
private Boolean licenseEnable;
@Autowired
private UploadService uploadService;
/** /**
* 用户在点击,查看`授权信息`按钮时,请求check接口,进行一次授权验证(每天第一次通过其他接口访问系统时,也会验证一次 ) * 用户在点击,查看`授权信息`按钮时,请求check接口,进行一次授权验证(每天第一次通过其他接口访问系统时,也会验证一次 )
* 如果通过则返回授权信息(开始+结束时间) * 如果通过则返回授权信息(开始+结束时间)
...@@ -47,6 +67,8 @@ public class CipherController { ...@@ -47,6 +67,8 @@ public class CipherController {
@UnAuth @UnAuth
public Rest<Map<String, String>> check() { public Rest<Map<String, String>> check() {
// 验证是否通过了授权,通过了返回授权信息(开始+结束时间) // 验证是否通过了授权,通过了返回授权信息(开始+结束时间)
if (!licenseEnable) return Rest.ok();
try { try {
Map<String, String> map = LicenseUtil.loadLicense(logPath, keyPath, pubPath); Map<String, String> map = LicenseUtil.loadLicense(logPath, keyPath, pubPath);
Map<String, String> resultMap = new HashMap<>(4); Map<String, String> resultMap = new HashMap<>(4);
...@@ -58,47 +80,46 @@ public class CipherController { ...@@ -58,47 +80,46 @@ public class CipherController {
resultMap.put("endTime", DateUtil.date(endTime).toDateStr()); resultMap.put("endTime", DateUtil.date(endTime).toDateStr());
} }
String applicationInfo = CipherUtil.getApplicationInfo(); String applicationInfo = CipherUtil.getApplicationInfo();
String encryptAes = DecodeUtil.encryptBySymmetry(applicationInfo, DecodeUtil.AES_KEY, DecodeUtil.AES, true); String encryptAes = DecodeUtil.encryptBySymmetry(applicationInfo, DecodeUtil.AES_KEY, DecodeUtil.AES, true);
log.info("授权码:" + encryptAes); log.info("授权码:" + encryptAes);
return Rest.ok(resultMap); return Rest.ok(resultMap);
} catch (Exception e) { } catch (Exception e) {
log.error("检测授权异常", e); log.error("检测授权异常", e);
return Rest.fail(e.getMessage()); return Rest.fail(e.getMessage());
} }
} }
@RequestMapping(value = "upload") @RequestMapping(value = "upload")
@UnAuth @UnAuth
public String doFileUpload(MultipartFile file) { public String doFileUpload(MultipartFile file, @RequestParam(value = "prePath", defaultValue = "/file/license") String prePath) {
/* Map<String, Object> model = new HashMap<>(); Map<String, Object> model = new HashMap<>();
String jsonStr = ""; String jsonStr = "";
try { try {
// String filePath = uploadService.saveFileUpload(file, prePath, getCurUser()); String targetFilePath = uploadService.saveFileUpload(file, prePath, null);
model.put("url", filePath); String suffix = FileUtil.getSuffix(file.getOriginalFilename());
if ("zip".equalsIgnoreCase(suffix)) {
throw new AppException("文件格式不正确,请上传zip格式的文件!");
}
//解压到指定license目录
String fileEncode = EncodeUtil.getEncode(targetFilePath, true);
ZipUtil.unzip(targetFilePath, logPath, Charset.forName(fileEncode));
model.put("url", targetFilePath);
model.put("fileName", file.getOriginalFilename()); model.put("fileName", file.getOriginalFilename());
model.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); model.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
jsonStr = JSONObject.toJSONString(model); jsonStr = JSONObject.toJSONString(model);
} catch (AppException e) { } catch (AppException e) {
log.error("上传异常",e); log.error("异常", e);
model.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE); model.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
model.put(KEY_RESULT_MSG, e.getMessage()); model.put("msg", e.getMessage());
jsonStr = JSONObject.toJSONString(model); jsonStr = JSONObject.toJSONString(model);
} catch (Exception e) { } catch (Exception e) {
// doException(request, "上传文件", new HashMap<>(3), e); model.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
// model.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE); model.put(KEY_RESULT_MSG, e.getMessage());
// model.put(KEY_RESULT_MSG, "文件上传失败");
jsonStr = JSONObject.toJSONString(model); jsonStr = JSONObject.toJSONString(model);
} }
log.info("uploadResp==>{}",jsonStr); log.info("licenseUploadResp==>{}", jsonStr);
return jsonStr;*/ return jsonStr;
return "";
} }
} }
...@@ -47,6 +47,4 @@ sys: ...@@ -47,6 +47,4 @@ sys:
key: /home/license/license.key key: /home/license/license.key
pub: /home/license/license.pub pub: /home/license/license.pub
log: /home/license log: /home/license
license:
enable: false enable: false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment