!51 实现预览加密的(受密码保护)office文件
* 1. 修复getCorsFile接口高危安全漏洞 * 1. 优化密码错误提示(“密码错误,请重新输入密码。”) * 1. 修复PPT重复预览bug,此bug导致ppt每次预览会执行两次转换(请求两次onlinePreview接口),在大文件尤其耗时(双倍时… * 1. 【加密office预览】优化受密码保护的office文件检查逻辑,提升旧文件格式的兼容性 * 1. 【加密office预览】优化office文件是否受密码保护判断逻辑,避免兼容性误判 * 1. 【加密office预览】优化重新输入密码提示。 * 1. 【加密office预览】优化当密码输入错误后,不是抛出异常,而是提示用户重新输入 * 1. 优化prompt提示框的输入密码提示样式 * 1. 实现基于userToken缓存加密文件,没有userToken的加密文件不缓存 * 1. 优化docker构建方案,使用分层构建方式,采用层级缓存解决构建慢发布慢等问题。从原本5分钟左右缩短至几秒 * 1. 加密文件暂时不缓存(后续基于用户token实现,基于用户缓存) * 1. 优化office文件下载逻辑,跳过重复下载(大量节约带宽与磁盘空间)。 * 1. 修复预览不同类型的加密office文件bug * 实现预览加密的(受密码保护)office文件
This commit is contained in:
@ -87,6 +87,13 @@ public class DownloadUtils {
|
||||
if (!dirFile.exists() && !dirFile.mkdirs()) {
|
||||
logger.error("创建目录【{}】失败,可能是权限不够,请检查", fileDir);
|
||||
}
|
||||
|
||||
// 文件已在本地存在,跳过文件下载
|
||||
File realFile = new File(realPath);
|
||||
if (realFile.exists()) {
|
||||
fileAttribute.setSkipDownLoad(true);
|
||||
}
|
||||
|
||||
return realPath;
|
||||
}
|
||||
|
||||
|
||||
62
server/src/main/java/cn/keking/utils/OfficeUtils.java
Normal file
62
server/src/main/java/cn/keking/utils/OfficeUtils.java
Normal file
@ -0,0 +1,62 @@
|
||||
package cn.keking.utils;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.poi.EncryptedDocumentException;
|
||||
import org.apache.poi.extractor.ExtractorFactory;
|
||||
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
/**
|
||||
* Office工具类
|
||||
*
|
||||
* @author ylyue
|
||||
* @since 2022/7/5
|
||||
*/
|
||||
public class OfficeUtils {
|
||||
|
||||
/**
|
||||
* 判断office(word,excel,ppt)文件是否受密码保护
|
||||
*
|
||||
* @param path office文件路径
|
||||
* @return 是否受密码保护
|
||||
*/
|
||||
public static boolean isPwdProtected(String path) {
|
||||
try {
|
||||
ExtractorFactory.createExtractor(new FileInputStream(path));
|
||||
} catch (EncryptedDocumentException e) {
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Throwable[] throwables = ExceptionUtils.getThrowables(e);
|
||||
for (Throwable throwable : throwables) {
|
||||
if (throwable instanceof EncryptedDocumentException) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断office文件是否可打开(兼容)
|
||||
*
|
||||
* @param path office文件路径
|
||||
* @param password 文件密码
|
||||
* @return 是否可打开(兼容)
|
||||
*/
|
||||
public static synchronized boolean isCompatible(String path, @Nullable String password) {
|
||||
try {
|
||||
Biff8EncryptionKey.setCurrentUserPassword(password);
|
||||
ExtractorFactory.createExtractor(new FileInputStream(path));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
} finally {
|
||||
Biff8EncryptionKey.setCurrentUserPassword(null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user