| .. | .. |
|---|
| 7 | 7 | import java.io.InputStream; |
|---|
| 8 | 8 | import java.net.URL; |
|---|
| 9 | 9 | import java.nio.charset.StandardCharsets; |
|---|
| 10 | +import java.nio.file.Files; |
|---|
| 11 | +import java.nio.file.LinkOption; |
|---|
| 12 | +import java.nio.file.attribute.GroupPrincipal; |
|---|
| 13 | +import java.nio.file.attribute.PosixFileAttributeView; |
|---|
| 14 | +import java.nio.file.attribute.PosixFileAttributes; |
|---|
| 15 | +import java.nio.file.attribute.PosixFilePermission; |
|---|
| 16 | +import java.nio.file.attribute.UserPrincipal; |
|---|
| 17 | +import java.nio.file.attribute.UserPrincipalLookupService; |
|---|
| 10 | 18 | import java.security.NoSuchAlgorithmException; |
|---|
| 11 | 19 | import java.time.LocalDate; |
|---|
| 12 | 20 | import java.time.ZoneId; |
|---|
| 21 | +import java.util.HashSet; |
|---|
| 22 | +import java.util.Set; |
|---|
| 13 | 23 | |
|---|
| 14 | 24 | import org.apache.commons.codec.digest.DigestUtils; |
|---|
| 15 | 25 | import org.apache.commons.io.FileUtils; |
|---|
| .. | .. |
|---|
| 68 | 78 | try { |
|---|
| 69 | 79 | storeFile(descriptor.getAbsolutePath()); |
|---|
| 70 | 80 | } catch (Exception e) { |
|---|
| 71 | | - writeKoFile(descriptor.getAbsolutePath(), "Errore duranto la memorizzazione del file nello store\n" + e.getMessage()); |
|---|
| 81 | + writeKoFile(descriptor.getAbsolutePath(), "Errore durante la memorizzazione del file nello store\n" + e.getMessage()); |
|---|
| 72 | 82 | } |
|---|
| 73 | 83 | } else { |
|---|
| 74 | 84 | logger.debug("Il file non ha passato le verifiche"); |
|---|
| .. | .. |
|---|
| 260 | 270 | String json = mapper.writeValueAsString(uploadedFileDescriptorOk); |
|---|
| 261 | 271 | logger.debug("Scrittura json di ok:\n{}", json); |
|---|
| 262 | 272 | FileUtils.writeStringToFile(okFile, json, StandardCharsets.UTF_8); |
|---|
| 273 | + set777(okFile); |
|---|
| 263 | 274 | } catch (IOException e) { |
|---|
| 264 | 275 | throw new RuntimeException("Errore nella scrittura del file di OK", e); |
|---|
| 265 | 276 | } |
|---|
| .. | .. |
|---|
| 275 | 286 | } |
|---|
| 276 | 287 | } |
|---|
| 277 | 288 | |
|---|
| 278 | | - public void writeKoFile( String cloudFileDescriptorPath, String errorMessage ) { |
|---|
| 289 | + public void writeKoFile( String cloudFileDescriptorPath, String errorMessage ) { |
|---|
| 279 | 290 | logger.debug("Si e' verificato il seguente errore nella verifica tramite {}: {}", cloudFileDescriptorPath, errorMessage); |
|---|
| 280 | 291 | |
|---|
| 281 | 292 | File fileDescriptor = new File(cloudFileDescriptorPath); |
|---|
| .. | .. |
|---|
| 283 | 294 | |
|---|
| 284 | 295 | try { |
|---|
| 285 | 296 | FileUtils.writeStringToFile(koFile, errorMessage, StandardCharsets.UTF_8); |
|---|
| 297 | + set777(koFile); |
|---|
| 286 | 298 | } catch (IOException e) { |
|---|
| 287 | 299 | throw new RuntimeException("Errore nella scrittura del file di KO", e); |
|---|
| 288 | 300 | } |
|---|
| .. | .. |
|---|
| 330 | 342 | |
|---|
| 331 | 343 | return sb.toString(); |
|---|
| 332 | 344 | } |
|---|
| 345 | + |
|---|
| 346 | + private void set777( File file ) throws IOException { |
|---|
| 347 | + logger.debug("Setto il permessi a 777"); |
|---|
| 348 | + try { |
|---|
| 349 | + Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); |
|---|
| 350 | + |
|---|
| 351 | + //add owners permission |
|---|
| 352 | + perms.add(PosixFilePermission.OWNER_READ); |
|---|
| 353 | + perms.add(PosixFilePermission.OWNER_WRITE); |
|---|
| 354 | + perms.add(PosixFilePermission.OWNER_EXECUTE); |
|---|
| 355 | + //add group permissions |
|---|
| 356 | + perms.add(PosixFilePermission.GROUP_READ); |
|---|
| 357 | + perms.add(PosixFilePermission.GROUP_WRITE); |
|---|
| 358 | + perms.add(PosixFilePermission.GROUP_EXECUTE); |
|---|
| 359 | + //add others permissions |
|---|
| 360 | + perms.add(PosixFilePermission.OTHERS_READ); |
|---|
| 361 | + perms.add(PosixFilePermission.OTHERS_WRITE); |
|---|
| 362 | + perms.add(PosixFilePermission.OTHERS_EXECUTE); |
|---|
| 363 | + |
|---|
| 364 | + Files.setPosixFilePermissions(file.toPath(), perms); |
|---|
| 365 | + logger.debug("Permessi settati"); |
|---|
| 366 | + } catch (IOException ioe) { |
|---|
| 367 | + logger.error("Errore nel settaggio dei permessi", ioe); |
|---|
| 368 | + throw new IOException("Errore nel settaggio dei permessi", ioe); |
|---|
| 369 | + } |
|---|
| 370 | + } |
|---|
| 333 | 371 | } |
|---|