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
@@ -52,6 +52,9 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
@Value("#{'${download.white_url}'.split(',')}")
private List<String> whiteUrls;
@Value("#{'${download.dev_encrypt_url}'.split(',')}")
private List<String> devEncryptUrls;
/**
* 管理员角色
*/
@@ -102,6 +105,15 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
return;
}
}
// 是否加研发密
boolean isDevEncrypt = false;
for (String devEncryptUrl : devEncryptUrls) {
if (requestUrl.contains(devEncryptUrl)) {
isDevEncrypt = true;
break;
}
}
// 判断返回值是否为文件流,否则其他接口返回值会变更成字符串,导致前端无法解析
HandlerMethod handlerMethod = (HandlerMethod) handler;
InputStream responseBody = null;
@@ -130,6 +142,8 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
boolean b1 = isBoolean(str, downloadUrl);
int scope = getScope(isDevEncrypt);
if(b){
// 预览,进行解密
decryptFile(response, file, null);
@@ -144,7 +158,6 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
isZipFile = true;
}
if (isZipFile) return;
int scope = getScope();
// 加密
encryptFile(response, fileDecrypt, scope);
} catch (Exception e) {
@@ -153,8 +166,6 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
}
}else{
// excel 判断组织域,加密
int scope = getScope();
// 加密
encryptFile(response, file, scope);
}
@@ -224,22 +235,26 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic
return b;
}
private int getScope() {
private int getScope(boolean isDevEncrypt) {
// 角色信息中存在 【系统管理员】或者 【标准管理员】即加为研发密,其他情况都是OA密
// 研发密比较高级(加密需要传参)
// 研发域 scope = 51
// 办公密 scope = 52
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
List<String> listRoleCode = Arrays.asList(sysUser.getRoleIds().split(","));
if(CollectionUtils.isEmpty(listRoleCode)){
throw new JeroBootException(ResultCommon.ERROR);
// LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
// List<String> listRoleCode = Arrays.asList(sysUser.getRoleIds().split(","));
// if(CollectionUtils.isEmpty(listRoleCode)){
// 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) {