H5离线包下载安全改造
This commit is contained in:
parent
8b9367e5cd
commit
8279e4cbd4
@ -0,0 +1,109 @@
|
|||||||
|
package com.sf.common.utils.openssl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.CipherInputStream;
|
||||||
|
import javax.crypto.CipherOutputStream;
|
||||||
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
public class AES256Util {
|
||||||
|
private static final String ALGORITHM = "AES/ECB/PKCS5Padding";
|
||||||
|
|
||||||
|
public static Cipher initAESCipher(String key, int cipherMode) throws Exception {
|
||||||
|
Cipher cipher = Cipher.getInstance(ALGORITHM);
|
||||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||||
|
cipher.init(cipherMode, secretKeySpec);
|
||||||
|
|
||||||
|
return cipher;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密文件
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static InputStream encryptFile(String key, InputStream inputStream) throws Exception {
|
||||||
|
Cipher cipher = initAESCipher(key, Cipher.ENCRYPT_MODE);
|
||||||
|
CipherInputStream cipherInputStream = new CipherInputStream(inputStream, cipher);
|
||||||
|
|
||||||
|
return cipherInputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密文件
|
||||||
|
*
|
||||||
|
* @param encryptedFile
|
||||||
|
* @param sourceFile
|
||||||
|
*/
|
||||||
|
public static String decryptFile(String key, File encryptedFile, File sourceFile) {
|
||||||
|
InputStream inputStream = null;
|
||||||
|
OutputStream outputStream = null;
|
||||||
|
CipherOutputStream cipherOutputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = new FileInputStream(encryptedFile);
|
||||||
|
outputStream = new FileOutputStream(sourceFile);
|
||||||
|
Cipher cipher = initAESCipher(key, Cipher.DECRYPT_MODE);
|
||||||
|
cipherOutputStream = new CipherOutputStream(outputStream, cipher);
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int n = -1;
|
||||||
|
int count = 0;
|
||||||
|
while ((n = inputStream.read(buffer)) != -1) {
|
||||||
|
count += n;
|
||||||
|
cipherOutputStream.write(buffer, 0, n);
|
||||||
|
cipherOutputStream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
return e.getLocalizedMessage();
|
||||||
|
}
|
||||||
|
if (cipherOutputStream != null) {
|
||||||
|
try {
|
||||||
|
cipherOutputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return e.getLocalizedMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (outputStream != null) {
|
||||||
|
try {
|
||||||
|
outputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return e.getLocalizedMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return e.getLocalizedMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static void main(String[] args) throws Exception {
|
||||||
|
// File sourceFile = new File("/Users/a1234/Downloads/dist.zip");
|
||||||
|
// InputStream encryptInputStream = encryptFile("efghijklmnopqrstuvwxyz0123456789", new FileInputStream(sourceFile));
|
||||||
|
// OutputStream outputStream = new FileOutputStream(new File("/Users/a1234/Downloads/x.zip"));
|
||||||
|
// byte[] buffer = new byte[1024];
|
||||||
|
// int n = -1;
|
||||||
|
// int count = 0;
|
||||||
|
// while ((n = encryptInputStream.read(buffer)) != -1) {
|
||||||
|
// count += n;
|
||||||
|
// outputStream.write(buffer, 0, n);
|
||||||
|
// }
|
||||||
|
// outputStream.flush();
|
||||||
|
// System.out.println(count);
|
||||||
|
//
|
||||||
|
// decryptFile("efghijklmnopqrstuvwxyz0123456789", new File("/Users/a1234/Downloads/x.zip"), new File("/Users/a1234/Downloads/y.zip"));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,15 @@
|
|||||||
package com.sf.system.deployment.controller;
|
package com.sf.system.deployment.controller;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.sf.common.enums.RequestHeaderEnums;
|
import com.sf.common.enums.RequestHeaderEnums;
|
||||||
import com.sf.common.utils.StringUtils;
|
|
||||||
import com.sf.common.utils.http.RequestUtils;
|
import com.sf.common.utils.http.RequestUtils;
|
||||||
import com.sf.system.deployment.domain.rqs.ModuleListByCoreRequest;
|
import com.sf.system.deployment.domain.rqs.ModuleListByCoreRequest;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.util.FileCopyUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
@ -28,14 +29,13 @@ import com.sf.common.core.page.TableDataInfo;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* H5模块包Controller
|
* H5模块包Controller
|
||||||
*
|
*
|
||||||
* @author ztzh
|
* @author ztzh
|
||||||
* @date 2024-04-22
|
* @date 2024-04-22
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/deployment/module")
|
@RequestMapping("/deployment/module")
|
||||||
public class DeploymentModuleListController extends BaseController
|
public class DeploymentModuleListController extends BaseController {
|
||||||
{
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IDeploymentModuleListService deploymentModuleListService;
|
private IDeploymentModuleListService deploymentModuleListService;
|
||||||
|
|
||||||
@ -44,19 +44,18 @@ public class DeploymentModuleListController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('deployment:module:list')")
|
@PreAuthorize("@ss.hasPermi('deployment:module:list')")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(DeploymentModuleList deploymentModuleList)
|
public TableDataInfo list(DeploymentModuleList deploymentModuleList) {
|
||||||
{
|
|
||||||
deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode()));
|
deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode()));
|
||||||
startPage();
|
startPage();
|
||||||
List<DeploymentModuleList> list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList);
|
List<DeploymentModuleList> list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询H5模块包列表
|
* 查询H5模块包列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/qurey/list")
|
@GetMapping("/qurey/list")
|
||||||
public AjaxResult queryByCore(ModuleListByCoreRequest request)
|
public AjaxResult queryByCore(ModuleListByCoreRequest request) {
|
||||||
{
|
|
||||||
DeploymentModuleList deploymentModuleList = new DeploymentModuleList();
|
DeploymentModuleList deploymentModuleList = new DeploymentModuleList();
|
||||||
deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode()));
|
deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode()));
|
||||||
deploymentModuleList.setSysType(request.getSysType());
|
deploymentModuleList.setSysType(request.getSysType());
|
||||||
@ -64,14 +63,36 @@ public class DeploymentModuleListController extends BaseController
|
|||||||
return success(list);
|
return success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询模块包列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/qurey/file")
|
||||||
|
public AjaxResult queryByCore(ModuleListByCoreRequest request, HttpServletResponse response) {
|
||||||
|
DeploymentModuleList deploymentModuleList = new DeploymentModuleList();
|
||||||
|
deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode()));
|
||||||
|
deploymentModuleList.setSysType(request.getSysType());
|
||||||
|
deploymentModuleList.setModuleType(request.getModuleType());
|
||||||
|
List<DeploymentModuleList> list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList);
|
||||||
|
if (list.isEmpty() && null == list.get(0)) {
|
||||||
|
throw new SecurityException("无可用模块包");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
InputStream inputStream = new URL(list.get(0).getModuleUrl()).openStream();
|
||||||
|
FileCopyUtils.copy(inputStream, response.getOutputStream());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return success(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出H5模块包列表
|
* 导出H5模块包列表
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('deployment:module:export')")
|
@PreAuthorize("@ss.hasPermi('deployment:module:export')")
|
||||||
@Log(title = "H5模块包", businessType = BusinessType.EXPORT)
|
@Log(title = "H5模块包", businessType = BusinessType.EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(HttpServletResponse response, DeploymentModuleList deploymentModuleList)
|
public void export(HttpServletResponse response, DeploymentModuleList deploymentModuleList) {
|
||||||
{
|
|
||||||
List<DeploymentModuleList> list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList);
|
List<DeploymentModuleList> list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList);
|
||||||
ExcelUtil<DeploymentModuleList> util = new ExcelUtil<DeploymentModuleList>(DeploymentModuleList.class);
|
ExcelUtil<DeploymentModuleList> util = new ExcelUtil<DeploymentModuleList>(DeploymentModuleList.class);
|
||||||
util.exportExcel(response, list, "H5模块包数据");
|
util.exportExcel(response, list, "H5模块包数据");
|
||||||
@ -82,8 +103,7 @@ public class DeploymentModuleListController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('deployment:module:query')")
|
@PreAuthorize("@ss.hasPermi('deployment:module:query')")
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||||
{
|
|
||||||
return success(deploymentModuleListService.selectDeploymentModuleListById(id));
|
return success(deploymentModuleListService.selectDeploymentModuleListById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,8 +113,7 @@ public class DeploymentModuleListController extends BaseController
|
|||||||
@PreAuthorize("@ss.hasPermi('deployment:module:add')")
|
@PreAuthorize("@ss.hasPermi('deployment:module:add')")
|
||||||
@Log(title = "H5模块包", businessType = BusinessType.INSERT)
|
@Log(title = "H5模块包", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody DeploymentModuleList deploymentModuleList)
|
public AjaxResult add(@RequestBody DeploymentModuleList deploymentModuleList) {
|
||||||
{
|
|
||||||
deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode()));
|
deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode()));
|
||||||
return toAjax(deploymentModuleListService.insertDeploymentModuleList(deploymentModuleList));
|
return toAjax(deploymentModuleListService.insertDeploymentModuleList(deploymentModuleList));
|
||||||
}
|
}
|
||||||
@ -105,8 +124,7 @@ public class DeploymentModuleListController extends BaseController
|
|||||||
@PreAuthorize("@ss.hasPermi('deployment:module:edit')")
|
@PreAuthorize("@ss.hasPermi('deployment:module:edit')")
|
||||||
@Log(title = "H5模块包", businessType = BusinessType.UPDATE)
|
@Log(title = "H5模块包", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody DeploymentModuleList deploymentModuleList)
|
public AjaxResult edit(@RequestBody DeploymentModuleList deploymentModuleList) {
|
||||||
{
|
|
||||||
return toAjax(deploymentModuleListService.updateDeploymentModuleList(deploymentModuleList));
|
return toAjax(deploymentModuleListService.updateDeploymentModuleList(deploymentModuleList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,9 +133,8 @@ public class DeploymentModuleListController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@PreAuthorize("@ss.hasPermi('deployment:module:remove')")
|
@PreAuthorize("@ss.hasPermi('deployment:module:remove')")
|
||||||
@Log(title = "H5模块包", businessType = BusinessType.DELETE)
|
@Log(title = "H5模块包", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public AjaxResult remove(@PathVariable Long[] ids)
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||||
{
|
|
||||||
return toAjax(deploymentModuleListService.deleteDeploymentModuleListByIds(ids));
|
return toAjax(deploymentModuleListService.deleteDeploymentModuleListByIds(ids));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,7 @@ public class ModuleListByCoreRequest {
|
|||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String sysType;
|
private String sysType;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String moduleType;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user