feat: 下载加密变更

国标、海外 列表页下载、详情页下载、无水印下载不加密
企标:列表页下载、详情页下载、无水印下载研发密,
其他的全部OA密。
This commit is contained in:
2024-03-19 10:30:30 +08:00
parent 1ea3fd2054
commit 2a2e10a11b
6 changed files with 84 additions and 17 deletions
@@ -222,6 +222,31 @@ public class CommonController {
downloadAndView(id, response); downloadAndView(id, response);
} }
/**
* 下载不带水印不加密的文件
*
* @param id 传入文件id
* @param response
*/
@ApiOperation(value = "下载不带水印不加密的文件", notes = "下载不带水印不加密的文件")
@GetMapping(value = "/noEncryptDownloadWithoutWaterMark/{id}")
public void noEncryptDownloadWithoutWaterMark(@PathVariable String id, HttpServletResponse response) {
downloadAndView(id, response);
}
/**
* 下载不带水印研发加密的文件
*
* @param id 传入文件id
* @param response
*/
@ApiOperation(value = "下载不带水印研发加密的文件", notes = "下载不带水印研发加密的文件")
@GetMapping(value = "/devEncryptDownloadWithoutWaterMark/{id}")
public void devEncryptDownloadWithoutWaterMark(@PathVariable String id, HttpServletResponse response) {
downloadAndView(id, response);
}
/** /**
* 下载文件(不带token) * 下载文件(不带token)
* *
@@ -52,6 +52,9 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
@Value("#{'${download.white_url}'.split(',')}") @Value("#{'${download.white_url}'.split(',')}")
private List<String> whiteUrls; private List<String> whiteUrls;
@Value("#{'${download.dev_encrypt_url}'.split(',')}")
private List<String> devEncryptUrls;
/** /**
* 管理员角色 * 管理员角色
*/ */
@@ -102,6 +105,15 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
return; return;
} }
} }
// 是否加研发密
boolean isDevEncrypt = false;
for (String devEncryptUrl : devEncryptUrls) {
if (requestUrl.contains(devEncryptUrl)) {
isDevEncrypt = true;
break;
}
}
// 判断返回值是否为文件流,否则其他接口返回值会变更成字符串,导致前端无法解析 // 判断返回值是否为文件流,否则其他接口返回值会变更成字符串,导致前端无法解析
HandlerMethod handlerMethod = (HandlerMethod) handler; HandlerMethod handlerMethod = (HandlerMethod) handler;
InputStream responseBody = null; InputStream responseBody = null;
@@ -130,6 +142,8 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
boolean b1 = isBoolean(str, downloadUrl); boolean b1 = isBoolean(str, downloadUrl);
int scope = getScope(isDevEncrypt);
if(b){ if(b){
// 预览,进行解密 // 预览,进行解密
decryptFile(response, file, null); decryptFile(response, file, null);
@@ -144,7 +158,6 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
isZipFile = true; isZipFile = true;
} }
if (isZipFile) return; if (isZipFile) return;
int scope = getScope();
// 加密 // 加密
encryptFile(response, fileDecrypt, scope); encryptFile(response, fileDecrypt, scope);
} catch (Exception e) { } catch (Exception e) {
@@ -153,8 +166,6 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
} }
}else{ }else{
// excel 判断组织域,加密
int scope = getScope();
// 加密 // 加密
encryptFile(response, file, scope); encryptFile(response, file, scope);
} }
@@ -224,22 +235,26 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
return b; return b;
} }
private int getScope() { private int getScope(boolean isDevEncrypt) {
// 角色信息中存在 【系统管理员】或者 【标准管理员】即加为研发密,其他情况都是OA密 // 角色信息中存在 【系统管理员】或者 【标准管理员】即加为研发密,其他情况都是OA密
// 研发密比较高级(加密需要传参) // 研发密比较高级(加密需要传参)
// 研发域 scope = 51 // 研发域 scope = 51
// 办公密 scope = 52 // 办公密 scope = 52
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); // LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
List<String> listRoleCode = Arrays.asList(sysUser.getRoleIds().split(",")); // List<String> listRoleCode = Arrays.asList(sysUser.getRoleIds().split(","));
if(CollectionUtils.isEmpty(listRoleCode)){ // if(CollectionUtils.isEmpty(listRoleCode)){
throw new JeroBootException(ResultCommon.ERROR); // throw new JeroBootException(ResultCommon.ERROR);
// }
// int scope = scopeWork;
// long l = listRoleCode.stream().filter(o->adminRoleCode.contains(o)).count();
// if(l > 0){
// scope = scopeDev;
// }
if (isDevEncrypt) {
return scopeDev;
} else {
return scopeWork;
} }
int scope = scopeWork;
long l = listRoleCode.stream().filter(o->adminRoleCode.contains(o)).count();
if(l > 0){
scope = scopeDev;
}
return scope;
} }
private void writeResponse(HttpServletResponse response,InputStream is) { private void writeResponse(HttpServletResponse response,InputStream is) {
@@ -60,6 +60,30 @@ public class SysCommonController {
downloadAndViewWithWaterMark(id, response); downloadAndViewWithWaterMark(id, response);
} }
/**
* 无加密下载文件
*
* @param id 传入文件id
* @param request
* @param response
*/
@GetMapping(value = "/noEncryptDownload/{id}")
public void noEncryptDownload(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) {
downloadAndViewWithWaterMark(id, response);
}
/**
* 研发密下载文件
*
* @param id 传入文件id
* @param request
* @param response
*/
@GetMapping(value = "/devEncryptDownload/{id}")
public void devEncryptDownload(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) {
downloadAndViewWithWaterMark(id, response);
}
/** /**
* 预览图片 * 预览图片
* *
@@ -459,7 +459,8 @@ download:
# 文件下载、预览拦截路径,多个以逗号分隔 # 文件下载、预览拦截路径,多个以逗号分隔
download_url: /sys/common/download/ download_url: /sys/common/download/
view_url: /sys/common/view/ view_url: /sys/common/view/
white_url: /onlyOffice,/enterprise/templateDownload,/exportDataWithFile,/exportSplitInfoZip,/lawsCustomCompareInfo/exportExcel white_url: /noEncryptDownload,/overseas/exportData,/overseas/exportDataWithFile,/overseas/templateDownload,/domestic/exportData,/domestic/exportDataWithFile,/domestic/templateDownload,/onlyOffice,/enterprise/templateDownload,/exportDataWithFile,/exportSplitInfoZip,/lawsCustomCompareInfo/exportExcel
dev_encrypt_url: /devEncryptDownload, /enterprise/exportData
# 管理员角色 # 管理员角色
admin_role_code: admin,BZGLY admin_role_code: admin,BZGLY
# 加密参数 # 加密参数
@@ -431,7 +431,8 @@ download:
# 文件下载、预览拦截路径,多个以逗号分隔 # 文件下载、预览拦截路径,多个以逗号分隔
download_url: /sys/common/download/ download_url: /sys/common/download/
view_url: /sys/common/view/ view_url: /sys/common/view/
white_url: /onlyOffice,/enterprise/templateDownload,/exportDataWithFile,/exportSplitInfoZip,/lawsCustomCompareInfo/exportExcel white_url: /noEncryptDownload,/overseas/exportData,/overseas/exportDataWithFile,/overseas/templateDownload,/domestic/exportData,/domestic/exportDataWithFile,/domestic/templateDownload,/onlyOffice,/enterprise/templateDownload,/exportDataWithFile,/exportSplitInfoZip,/lawsCustomCompareInfo/exportExcel
dev_encrypt_url: /devEncryptDownload, /enterprise/exportData
# 管理员角色 # 管理员角色
admin_role_code: admin,BZGLY admin_role_code: admin,BZGLY
# 加密参数 # 加密参数
@@ -423,7 +423,8 @@ download:
# 文件下载、预览拦截路径,多个以逗号分隔 # 文件下载、预览拦截路径,多个以逗号分隔
download_url: /sys/common/download/,/laws/standard/common/downloadWithWaterMark download_url: /sys/common/download/,/laws/standard/common/downloadWithWaterMark
view_url: /sys/common/view/,/onlyOffice/downLoadFile view_url: /sys/common/view/,/onlyOffice/downLoadFile
white_url: /onlyOffice white_url: /noEncryptDownload,/overseas/exportData,/overseas/exportDataWithFile,/overseas/templateDownload,/domestic/exportData,/domestic/exportDataWithFile,/domestic/templateDownload,/onlyOffice,/enterprise/templateDownload,/exportDataWithFile,/exportSplitInfoZip,/lawsCustomCompareInfo/exportExcel
dev_encrypt_url: /devEncryptDownload, /enterprise/exportData
# 管理员角色 # 管理员角色
admin_role_code: admin,BZGLY admin_role_code: admin,BZGLY
# 加密参数 # 加密参数