diff --git a/pom.xml b/pom.xml index 7948619..8306494 100644 --- a/pom.xml +++ b/pom.xml @@ -1,18 +1,38 @@ - - 4.0.0 + + + 4.0.0 + - org.springframework.boot - spring-boot-starter-parent - 3.3.4 + + org.springframework.boot + + + spring-boot-starter-parent + + + 3.3.4 + - org.rostislav - quickdrop - 0.0.1-SNAPSHOT - quickdrop - quickdrop + + org.rostislav + + + quickdrop + + + 0.0.1-SNAPSHOT + + + quickdrop + + + quickdrop + @@ -27,84 +47,164 @@ - 21 - 21 + + 21 + + + 21 + - org.springframework.boot - spring-boot-starter-data-jpa + + org.springframework.boot + + + spring-boot-starter-data-jpa + - org.springframework.boot - spring-boot-starter-security + + org.springframework.boot + + + spring-boot-starter-security + - org.springframework.boot - spring-boot-starter-thymeleaf + + org.springframework.boot + + + spring-boot-starter-thymeleaf + - org.springframework.boot - spring-boot-starter-web + + org.springframework.boot + + + spring-boot-starter-web + - org.thymeleaf.extras - thymeleaf-extras-springsecurity6 + + org.thymeleaf.extras + + + thymeleaf-extras-springsecurity6 + - org.springframework.boot - spring-boot-starter-logging + + org.springframework.boot + + + spring-boot-starter-logging + - org.springframework.boot - spring-boot-starter-test - test + + org.springframework.boot + + + spring-boot-starter-test + + + test + - junit - junit + + junit + + + junit + - org.springframework.security - spring-security-test - test + + org.springframework.security + + + spring-security-test + + + test + - org.xerial - sqlite-jdbc - 3.46.0.0 + + org.xerial + + + sqlite-jdbc + + + 3.46.0.0 + - org.hibernate - hibernate-community-dialects - 6.5.2.Final + + org.hibernate + + + hibernate-community-dialects + + + 6.5.2.Final + - org.junit.jupiter - junit-jupiter-engine - 5.10.0 - test + + org.junit.jupiter + + + junit-jupiter-engine + + + 5.10.0 + + + test + - org.junit.jupiter - junit-jupiter-api - 5.10.0 - test + + org.junit.jupiter + + + junit-jupiter-api + + + 5.10.0 + + + test + - org.springframework.boot - spring-boot-maven-plugin + + org.springframework.boot + + + spring-boot-maven-plugin + - junit - junit + + junit + + + junit + diff --git a/src/main/java/org/rostislav/quickdrop/QuickdropApplication.java b/src/main/java/org/rostislav/quickdrop/QuickdropApplication.java index a77ebdf..4a95011 100644 --- a/src/main/java/org/rostislav/quickdrop/QuickdropApplication.java +++ b/src/main/java/org/rostislav/quickdrop/QuickdropApplication.java @@ -1,5 +1,8 @@ package org.rostislav.quickdrop; +import java.nio.file.Files; +import java.nio.file.Path; + import jakarta.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,9 +11,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; -import java.nio.file.Files; -import java.nio.file.Path; - @SpringBootApplication @EnableScheduling public class QuickdropApplication { @@ -27,7 +27,8 @@ public class QuickdropApplication { try { Files.createDirectories(Path.of(fileSavePath)); logger.info("File save path created: {}", fileSavePath); - } catch (Exception e) { + } catch ( + Exception e) { logger.error("Failed to create file save path: {}", fileSavePath); } } diff --git a/src/main/java/org/rostislav/quickdrop/model/FileEntity.java b/src/main/java/org/rostislav/quickdrop/model/FileEntity.java index ab95497..c11cef3 100644 --- a/src/main/java/org/rostislav/quickdrop/model/FileEntity.java +++ b/src/main/java/org/rostislav/quickdrop/model/FileEntity.java @@ -1,9 +1,13 @@ package org.rostislav.quickdrop.model; -import jakarta.persistence.*; - import java.time.LocalDate; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.PrePersist; + @Entity public class FileEntity { @Id diff --git a/src/main/java/org/rostislav/quickdrop/repository/FileRepository.java b/src/main/java/org/rostislav/quickdrop/repository/FileRepository.java index bd089d8..053a1fc 100644 --- a/src/main/java/org/rostislav/quickdrop/repository/FileRepository.java +++ b/src/main/java/org/rostislav/quickdrop/repository/FileRepository.java @@ -1,14 +1,14 @@ package org.rostislav.quickdrop.repository; +import java.time.LocalDate; +import java.util.List; +import java.util.Optional; + import org.rostislav.quickdrop.model.FileEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import java.time.LocalDate; -import java.util.List; -import java.util.Optional; - public interface FileRepository extends JpaRepository { @Query("SELECT f FROM FileEntity f WHERE f.uuid = :uuid") Optional findByUUID(@Param("uuid") String uuid); diff --git a/src/main/java/org/rostislav/quickdrop/service/ScheduleService.java b/src/main/java/org/rostislav/quickdrop/service/ScheduleService.java index 94c9352..14b1d2d 100644 --- a/src/main/java/org/rostislav/quickdrop/service/ScheduleService.java +++ b/src/main/java/org/rostislav/quickdrop/service/ScheduleService.java @@ -1,5 +1,8 @@ package org.rostislav.quickdrop.service; +import java.time.LocalDate; +import java.util.List; + import org.rostislav.quickdrop.model.FileEntity; import org.rostislav.quickdrop.repository.FileRepository; import org.slf4j.Logger; @@ -8,9 +11,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import java.time.LocalDate; -import java.util.List; - @Service public class ScheduleService { private static final Logger logger = LoggerFactory.getLogger(ScheduleService.class); diff --git a/src/main/java/org/rostislav/quickdrop/util/FileEncryptionUtils.java b/src/main/java/org/rostislav/quickdrop/util/FileEncryptionUtils.java index d8bbd70..c50c683 100644 --- a/src/main/java/org/rostislav/quickdrop/util/FileEncryptionUtils.java +++ b/src/main/java/org/rostislav/quickdrop/util/FileEncryptionUtils.java @@ -1,9 +1,5 @@ package org.rostislav.quickdrop.util; -import javax.crypto.*; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.PBEKeySpec; -import javax.crypto.spec.SecretKeySpec; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -14,6 +10,16 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; + public class FileEncryptionUtils { private static final String ALGORITHM = "AES/CBC/PKCS5Padding"; private static final int ITERATION_COUNT = 65536; @@ -37,7 +43,6 @@ public class FileEncryptionUtils { byte[] salt = generateRandomBytes(); SecretKey secretKey = generateKeyFromPassword(password, salt); - byte[] iv = generateRandomBytes(); IvParameterSpec ivSpec = new IvParameterSpec(iv); diff --git a/src/main/resources/templates/filePassword.html b/src/main/resources/templates/filePassword.html index 237279e..1c30ed4 100644 --- a/src/main/resources/templates/filePassword.html +++ b/src/main/resources/templates/filePassword.html @@ -2,17 +2,27 @@ - Enter Password - - - + + Enter + Password + + +