-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
35 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/it/gov/pagopa/atmlayer/service/model/configurations/DirManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package it.gov.pagopa.atmlayer.service.model.configurations; | ||
|
||
import io.quarkus.runtime.Shutdown; | ||
import io.quarkus.runtime.ShutdownEvent; | ||
import io.quarkus.runtime.Startup; | ||
import io.quarkus.runtime.StartupEvent; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
import lombok.Getter; | ||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.attribute.PosixFilePermission; | ||
import java.util.EnumSet; | ||
import java.util.Set; | ||
|
||
@ApplicationScoped | ||
public class DirManager { | ||
|
||
@Getter | ||
public static File decodedFilesDirectory; | ||
|
||
@Startup | ||
static void init(@Observes StartupEvent ev) throws IOException { | ||
String secureDirPath = System.getProperty("java.io.tmpdir") + "/mySecureDirectory"; | ||
decodedFilesDirectory = new File(secureDirPath); | ||
if (!decodedFilesDirectory.exists() && !decodedFilesDirectory.mkdirs()) { | ||
throw new IOException("Impossibile creare una directory sicura per il salvataggio di file temporanei."); | ||
} | ||
if (SystemUtils.IS_OS_UNIX) { | ||
Set<PosixFilePermission> dirPermissions = EnumSet.of( | ||
PosixFilePermission.OWNER_READ, | ||
PosixFilePermission.OWNER_WRITE, | ||
PosixFilePermission.OWNER_EXECUTE | ||
); | ||
java.nio.file.Files.setPosixFilePermissions(decodedFilesDirectory.toPath(), dirPermissions); | ||
} | ||
} | ||
|
||
@Shutdown | ||
static boolean shutdown(@Observes ShutdownEvent ev) { | ||
return decodedFilesDirectory.delete(); | ||
} | ||
|
||
private DirManager() { | ||
throw new IllegalStateException("Utility class DirManager should not be instantiated"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters