Virenscanner für Inhalte
Virenscanner für Inhalte
Standardmäßig ist die Implementierung des Virenscanners für Inhalte oder die Antiviren-Software nicht im Lieferumfang von
Codebeamer enthalten. Mithilfe von
Datei-Upload-Listener können Sie eine integrierte Programmierschnittstelle für den Virenscan implementieren.
Beispielimplementierung: ClamAVFileUploadListener
Das folgende Beispiel zeigt, wie Sie die
FileUploadListener-API verwenden, um hochgeladene Dateien mit dem Antiviren-Programm
ClamAV auf Viren zu scannen.
Anforderungen
Der
ClamAV-Virenscanner muss auf dem Server installiert sein, auf dem
Codebeamer ausgeführt wird. Detaillierte Anweisungen finden Sie unter
Installing ClamAV.
Implementierungsrichtlinien
Ein vollständiges Implementierungsbeispiel finden Sie unter
Add virus scanner FileUploadListener auf GitHub. Verwenden Sie als Referenz die folgende Java-Schnittstelle:
package com.intland.customization;
import java.nio.file.Path;
import org.springframework.stereotype.Component;
import com.intland.codebeamer.event.FileUploadEventData;
import com.intland.codebeamer.event.FileUploadListener;
import com.intland.codebeamer.event.util.VetoException;
import xyz.capybara.clamav.ClamavClient;
import xyz.capybara.clamav.ClamavException;
import xyz.capybara.clamav.commands.scan.result.ScanResult;
@Component
public class ClamavFileUploadListener implements FileUploadListener {
private final ClamavClient clamavClient;
public ClamavFileUploadListener() {
this.clamavClient = new ClamavClient("127.0.0.1");
}
@Override
public void fileUploaded(FileUploadEventData event) throws VetoException {
try {
Path filePath = event.getSource().toPath();
ScanResult scanResult = clamavClient.scan(filePath);
if (scanResult instanceof ScanResult.VirusFound virusFound) {
throw new VetoException("Virus found during scan: " + virusFound.getFoundViruses());
}
} catch (ClamavException ex) {
throw new VetoException(ex);
}
}
}