diff --git a/pom.xml b/pom.xml index aa8eadcb7a4e42098ca10438fbaac96c47926509..93984973f155ac486b2e019f3be26c1596d673cc 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,13 @@ <version>2.4.5</version> </dependency> + <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core --> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-core</artifactId> + <version>5.4.6</version> + </dependency> + <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> diff --git a/service/pom.xml b/service/pom.xml index f4f5f0bd9d1f6840cce8496214e3362d65957119..739865d8e768072e2229f7e6d4929c0312e136cc 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -88,6 +88,12 @@ <artifactId>dozer-core</artifactId> </dependency> + <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core --> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-core</artifactId> + </dependency> + </dependencies> diff --git a/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/config/ApplicationConfig.java b/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/config/ApplicationConfig.java index 07e2ac3a0afe9f4d54e91063bc96271039025437..578ab2ce6c0309ddeb91a6dfe2611c60d5bbce7b 100644 --- a/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/config/ApplicationConfig.java +++ b/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/config/ApplicationConfig.java @@ -7,6 +7,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.security.crypto.argon2.Argon2PasswordEncoder; import org.springframework.transaction.annotation.EnableTransactionManagement; @@ -24,4 +25,17 @@ public class ApplicationConfig { return mapperBuilder.build(); } + @Bean + public Argon2PasswordEncoder argon2Encoder() { + /* + Recommended parameters: + - hash and salt - each at least 16 + - parallellism - twice the core count + - memory - at least 4 GB + - iterations - adjustable + Note: adjust memory and iterations to hit response time: 0.5-1 sec + */ + int cores = Runtime.getRuntime().availableProcessors(); + return new Argon2PasswordEncoder(32, 32, cores*2, 3906250, 1); + } } diff --git a/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/Argon2Service.java b/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/Argon2Service.java new file mode 100644 index 0000000000000000000000000000000000000000..a07a660ede415607035223af305fedbad76bfa62 --- /dev/null +++ b/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/Argon2Service.java @@ -0,0 +1,5 @@ +package cz.muni.fi.pa165.icehockeymanager.services; + +public interface Argon2Service { + +} diff --git a/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/Argon2ServiceImpl.java b/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/Argon2ServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..b77e5401ac3d645470e87d0508680acd21124a4c --- /dev/null +++ b/service/src/main/java/cz/muni/fi/pa165/icehockeymanager/services/Argon2ServiceImpl.java @@ -0,0 +1,18 @@ +package cz.muni.fi.pa165.icehockeymanager.services; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.argon2.Argon2PasswordEncoder; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +public class Argon2ServiceImpl { + private final Argon2PasswordEncoder encoder; + + @Autowired + public Argon2ServiceImpl(Argon2PasswordEncoder encoder) { + this.encoder = encoder; + } +}