| .. | .. |
|---|
| 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 | 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 | 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); |
|---|