Skip to content

Commit

Permalink
fix: undo Sonar vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmarcoplutino committed Nov 22, 2024
1 parent 5522095 commit 61f5f1c
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,21 @@ private File createPdfFileContract(

private File createPdfFileAttachment(String attachmentTemplatePath, Onboarding onboarding)
throws IOException {
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
String uniqueId = UUID.randomUUID().toString();
String filePrefix = "allegato_interoperabilita_" + timestamp + "_" + uniqueId;

// Usa una directory temporanea dedicata
Path tempDir = Files.createTempDirectory("secureTempDir");

// Crea il file temporaneo nella directory sicura
Path attachmentPdfFile = Files.createTempFile(tempDir, filePrefix, ".pdf");
final String builder =
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))
+ "_"
+ UUID.randomUUID()
+ "_allegato_interoperabilita.";

// Leggi il contenuto del template del contratto
// Read the content of the contract template file.
String attachmentTemplateText = azureBlobClient.getFileAsText(attachmentTemplatePath);

// Prepara i dati comuni per il documento PDF
// Create a temporary PDF file to store the contract.
Path attachmentPdfFile = Files.createTempFile(builder, ".pdf");
// Prepare common data for the contract document.
Map<String, Object> data = setUpAttachmentData(onboarding);

log.debug("data Map for PDF: {}", data);

// Scrivi i dati nel file PDF
fillPDFAsFile(attachmentPdfFile, attachmentTemplateText, data);

// Restituisci il file temporaneo
return attachmentPdfFile.toFile();
}

Expand Down

0 comments on commit 61f5f1c

Please sign in to comment.