企業級應用常需上傳文件(郵件附件、用戶資料、合同掃描件),必須在入口處攔截惡意代碼。賽門鐵克掃描引擎 (SSE) 提供企業級防毒能力,支援 ICAP 協議,可無縫集成至 J2EE 應用服務器。
項目提供封裝好的 JAR,核心類 `VirusScanManager`,單方法暴露:
public class VirusScanManager {
public VirusScanManager(String icapUrl); // 構造函數傳入 ICAP 端點
public void processScanVirus(String fileName, String mimeType, InputStream content) throws ScanException;
}
<%@ page import="com.symantec.virus.VirusScanManager" %>
<%@ page import="java.io.*" %>
<%
String icapEndpoint = "icap://10.225.69.89:1344/avscan";
VirusScanManager vsm = new VirusScanManager(icapEndpoint);
// 示例:掃描上傳文件
Part filePart = request.getPart("uploadFile");
String fileName = filePart.getSubmittedFileName();
String mimeType = filePart.getContentType();
InputStream in = filePart.getInputStream();
try {
vsm.processScanVirus(fileName, mimeType, in);
out.print("掃描通過,無病毒。");
} catch (ScanException e) {
if (e.getCode() == ScanException.VIRUS_DETECTED) {
out.print("檢測到病毒:" + e.getVirusName() + ",文件已隔離。");
} else {
out.print("掃描服務異常:" + e.getMessage());
}
}
%>
public static void main(String[] args) {
VirusScanManager vsm = new VirusScanManager("icap://10.225.69.89:1344/avscan");
File testFile = new File("./test/eicar.com.txt"); // 標準 EICAR 測試文件
try (FileInputStream in = new FileInputStream(testFile)) {
vsm.processScanVirus("eicarTestFile.txt", "text/plain", in);
System.out.println("測試通過:未檢測到病毒 (預期應拋出異常)");
} catch (ScanException e) {
System.out.println("測試通過:檢測到 EICAR 測試病毒 - " + e.getVirusName());
} catch (Exception e) {
e.printStackTrace();
}
}
| 現象 | 原因 | 解決 |
|---|---|---|
| 連接超時 | 防火牆阻擋 1344 端口 / SSE 未啟用 ICAP | 檢查網絡通路、SSE 服務狀態、ICAP 配置 |
| 掃描異常: License Expired | 試用版到期或授權文件損壞 | 更新授權文件、重啟 SSE 服務 |
| 大文件 OOM | 一次性讀入內存 | 流式傳輸、分塊上傳、限制單文件大小 |
通過 ICAP 協議集成賽門鐵克 SSE,J2EE 應用以極低耦合成本獲得企業級防毒能力。關鍵在於:標準化協議隔離業務與掃描邏輯、異步化處理大文件、熔斷機制保障可用性。此模式同樣適用於集成其他支援 ICAP 的安全網關 (DLP、內容審核等)。