dg1cloud-core/src/main/java/db/migration/V0.1__DG1CLOUD.sql
.. .. @@ -11,6 +11,7 @@ 11 11 file_path text NOT NULL, 12 12 file_size bigint, 13 13 due_date date, 14 + secret_key character varying(1024),14 15 CONSTRAINT reg_document_pkey PRIMARY KEY (document_id) 15 16 ) 16 17 WITH ( dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadFileController.java
.. .. @@ -6,6 +6,7 @@ 6 6 7 7 import javax.servlet.ServletContext; 8 8 9 +import org.apache.logging.log4j.util.Strings;9 10 import org.slf4j.Logger; 10 11 import org.slf4j.LoggerFactory; 11 12 import org.springframework.beans.factory.annotation.Autowired; .. .. @@ -30,7 +31,9 @@ 30 31 @Autowired private RegDocumentRepository regDocumentRepository; 31 32 32 33 @RequestMapping("/downloadFile") 33 - public ResponseEntity<InputStreamResource> downloadFile(@RequestParam String fileName, @RequestParam long id) throws IOException {34 + public ResponseEntity<InputStreamResource> downloadFile(@RequestParam String fileName,35 + @RequestParam long id,36 + @RequestParam(value = "secretKey", required = false) String secretKey) throws IOException {34 37 35 38 logger.debug("Avvio download file {} con id {}, fileName, id"); 36 39 .. .. @@ -48,6 +51,22 @@ 48 51 throw new RuntimeException("Il nome del file richiesto non corrisponde con quello referenziato dall'id"); 49 52 } 50 53 54 + if ( regDocument.getSecretKey() != null ) {55 + logger.debug("E' stata specificata una secretKey. Avvio le verifiche.");56 + if ( Strings.isEmpty(secretKey) == true ) {57 + logger.error("Non e' stata inviata la secretKey");58 + throw new RuntimeException("Per scaricare il file occorre specificare la secretKey");59 + } else {60 + logger.debug("Controllo corrispondenza della secretKey");61 + if (secretKey.equals(regDocument.getSecretKey()) == false ) {62 + logger.error("La secretKey inviata non corrisponde a quella impostata in fase di richiesta salvataggio del file");63 + throw new RuntimeException("La secretKey inviata non corrisponde a quella impostata in fase di richiesta salvataggio del file");64 + } else {65 + logger.debug("SecretKey verificata correttamente");66 + }67 + }68 + }69 +51 70 File file = new File(regDocument.getFilePath()); 52 71 FileInputStream fis = new FileInputStream(file); 53 72 InputStreamResource isr = new InputStreamResource(fis); dg1cloud-core/src/main/java/it/digione/dg1cloud/model/RegDocument.java
.. .. @@ -50,6 +50,9 @@ 50 50 @Column(name="due_date") 51 51 private Date dueDate; 52 52 53 + @Column(name="secret_key")54 + private String secretKey;55 +53 56 public RegDocument() { 54 57 } 55 58 .. .. @@ -142,6 +145,14 @@ 142 145 this.dueDate = dueDate; 143 146 } 144 147 148 + public String getSecretKey() {149 + return secretKey;150 + }151 +152 + public void setSecretKey(String secretKey) {153 + this.secretKey = secretKey;154 + }155 +145 156 @Override 146 157 public String toString() { 147 158 return "RegDocument [documentId=" + documentId + ", created=" + created + ", createdBy=" + createdBy dg1cloud-core/src/main/java/it/digione/dg1cloud/pojo/UploadedFileDescriptor.java
.. .. @@ -7,6 +7,7 @@ 7 7 private String fileName; 8 8 private String sha256; 9 9 private Date dueDate; //Data nel formato ISO-8601 - es: 2018-07-27T18:25:43.511Z 10 + private String secretKey;10 11 11 12 public String getFileName() { 12 13 return fileName; .. .. @@ -26,4 +27,10 @@ 26 27 public void setDueDate(Date dueDate) { 27 28 this.dueDate = dueDate; 28 29 } 30 + public String getSecretKey() {31 + return secretKey;32 + }33 + public void setSecretKey(String secretKey) {34 + this.secretKey = secretKey;35 + }29 36 } dg1cloud-core/src/main/java/it/digione/dg1cloud/service/CloudService.java
.. .. @@ -179,6 +179,7 @@ 179 179 regDocument.setFileSize(uploadedFile.length()); 180 180 regDocument.setDueDate(uploadedFileDescriptor.getDueDate()); 181 181 regDocument.setFilePath(""); 182 + regDocument.setSecretKey(uploadedFileDescriptor.getSecretKey());182 183 183 184 regDocumentRepository.save(regDocument); 184 185 dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
.. .. @@ -6,6 +6,7 @@ 6 6 import java.net.URL; 7 7 8 8 import org.apache.commons.io.FileUtils; 9 +import org.apache.logging.log4j.util.Strings;9 10 import org.slf4j.Logger; 10 11 import org.slf4j.LoggerFactory; 11 12 import org.springframework.beans.factory.annotation.Autowired; .. .. @@ -29,6 +30,9 @@ 29 30 uriBuilder.path("/downloadFile"); 30 31 uriBuilder.queryParam("fileName", regDocument.getFileName()); 31 32 uriBuilder.queryParam("id", regDocument.getDocumentId()); 33 + if ( Strings.isEmpty(regDocument.getSecretKey()) == false ) {34 + uriBuilder.queryParam("secretKey", regDocument.getSecretKey());35 + }32 36 return uriBuilder.build().toURL(); 33 37 } 34 38