From 6ddbf7641d06f00c3828f8453cd671ab5438a9b9 Mon Sep 17 00:00:00 2001 From: Lucas Amiaud Date: Mon, 10 Jul 2023 15:31:27 +0200 Subject: [PATCH 1/4] [maven-release-plugin] prepare for next development iteration --- plume-admin-api-log/pom.xml | 2 +- plume-admin-dependencies/pom.xml | 2 +- plume-admin-security/pom.xml | 2 +- plume-admin-ws-system/pom.xml | 2 +- plume-admin-ws/pom.xml | 2 +- pom.xml | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plume-admin-api-log/pom.xml b/plume-admin-api-log/pom.xml index 233db74..5e00da8 100644 --- a/plume-admin-api-log/pom.xml +++ b/plume-admin-api-log/pom.xml @@ -5,7 +5,7 @@ com.coreoz plume-admin-parent - 4.3.0 + 4.3.1-SNAPSHOT plume-admin-api-log diff --git a/plume-admin-dependencies/pom.xml b/plume-admin-dependencies/pom.xml index 56702c1..60afe7f 100644 --- a/plume-admin-dependencies/pom.xml +++ b/plume-admin-dependencies/pom.xml @@ -5,7 +5,7 @@ com.coreoz plume-admin-parent - 4.3.0 + 4.3.1-SNAPSHOT plume-admin-dependencies diff --git a/plume-admin-security/pom.xml b/plume-admin-security/pom.xml index 0c1753a..5aa4f40 100644 --- a/plume-admin-security/pom.xml +++ b/plume-admin-security/pom.xml @@ -5,7 +5,7 @@ com.coreoz plume-admin-parent - 4.3.0 + 4.3.1-SNAPSHOT plume-admin-security diff --git a/plume-admin-ws-system/pom.xml b/plume-admin-ws-system/pom.xml index 52a5776..4521b05 100644 --- a/plume-admin-ws-system/pom.xml +++ b/plume-admin-ws-system/pom.xml @@ -5,7 +5,7 @@ com.coreoz plume-admin-parent - 4.3.0 + 4.3.1-SNAPSHOT plume-admin-ws-system diff --git a/plume-admin-ws/pom.xml b/plume-admin-ws/pom.xml index b46cf6a..6e879b5 100644 --- a/plume-admin-ws/pom.xml +++ b/plume-admin-ws/pom.xml @@ -5,7 +5,7 @@ com.coreoz plume-admin-parent - 4.3.0 + 4.3.1-SNAPSHOT plume-admin-ws diff --git a/pom.xml b/pom.xml index ecfb404..6a39b7b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.coreoz plume-admin-parent - 4.3.0 + 4.3.1-SNAPSHOT pom Plume Admin Parent @@ -37,7 +37,7 @@ scm:git:git@github.com:Coreoz/Plume-admin.git scm:git:git@github.com:Coreoz/Plume-admin.git https://github.com/Coreoz/Plume-admin - 4.3.0 + HEAD From f978f9d54c00cc1618311c8f5c6337fc67c6e4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Fardilha?= Date: Thu, 24 Aug 2023 12:05:05 +0200 Subject: [PATCH 2/4] Throw exception before hashing when password is null --- .../services/hash/BCryptHashService.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java b/plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java index e6a2713..e378b2b 100644 --- a/plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java +++ b/plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java @@ -1,22 +1,26 @@ -package com.coreoz.plume.admin.services.hash; - -import javax.inject.Singleton; - -import org.mindrot.jbcrypt.BCrypt; - -@Singleton -public class BCryptHashService implements HashService { - - private static final int BCRYPT_SALT_ROUND = 11; - - @Override - public String hashPassword(String password) { - return BCrypt.hashpw(password, BCrypt.gensalt(BCRYPT_SALT_ROUND)); - } - - @Override - public boolean checkPassword(String candidate, String hashed) { - return BCrypt.checkpw(candidate, hashed); - } - -} \ No newline at end of file +package com.coreoz.plume.admin.services.hash; + +import javax.inject.Singleton; + +import com.google.common.base.Strings; +import org.mindrot.jbcrypt.BCrypt; + +@Singleton +public class BCryptHashService implements HashService { + + private static final int BCRYPT_SALT_ROUND = 11; + + @Override + public String hashPassword(String password) { + if (password == null) { + throw new IllegalArgumentException("Password must not be null or empty"); + } + return BCrypt.hashpw(password, BCrypt.gensalt(BCRYPT_SALT_ROUND)); + } + + @Override + public boolean checkPassword(String candidate, String hashed) { + return BCrypt.checkpw(candidate, hashed); + } + +} From c21392fb6eb140c06b0ffffcace8832f612d4391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Fardilha?= Date: Thu, 24 Aug 2023 13:30:25 +0200 Subject: [PATCH 3/4] Add unit tests for BCryptHashService --- .../services/hash/BCryptHashServiceTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 plume-admin-ws/test/java/com/coreoz/plume/admin/services/hash/BCryptHashServiceTest.java diff --git a/plume-admin-ws/test/java/com/coreoz/plume/admin/services/hash/BCryptHashServiceTest.java b/plume-admin-ws/test/java/com/coreoz/plume/admin/services/hash/BCryptHashServiceTest.java new file mode 100644 index 0000000..2b9f184 --- /dev/null +++ b/plume-admin-ws/test/java/com/coreoz/plume/admin/services/hash/BCryptHashServiceTest.java @@ -0,0 +1,29 @@ +package com.coreoz.plume.admin.services.hash; + +import org.assertj.core.api.Assertions; +import org.assertj.core.util.Strings; +import org.junit.Test; + +public class BCryptHashServiceTest { + + @Test + public void null_password_should_raise_an_error() { + BCryptHashService hashService = new BCryptHashService(); + + try { + hashService.hashPassword(null); + Assertions.fail("should raise an error"); + } catch (IllegalArgumentException e) { + // as excepted, the password should not be null + } + } + + @Test + public void non_null_password_should_be_hashed() { + BCryptHashService hashService = new BCryptHashService(); + + String hashedPassword = hashService.hashPassword("Test"); + Assertions.assertThat(Strings.isNullOrEmpty(hashedPassword)).isFalse(); + Assertions.assertThat(hashService.checkPassword("Test", hashedPassword)).isTrue(); + } +} From c88622b76a4d45798c3cd3889650092bbe9b8817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Fardilha?= Date: Thu, 24 Aug 2023 15:09:57 +0200 Subject: [PATCH 4/4] Change exception wording --- .../coreoz/plume/admin/services/hash/BCryptHashService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java b/plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java index e378b2b..c6cbdb0 100644 --- a/plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java +++ b/plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java @@ -2,7 +2,6 @@ import javax.inject.Singleton; -import com.google.common.base.Strings; import org.mindrot.jbcrypt.BCrypt; @Singleton @@ -13,7 +12,7 @@ public class BCryptHashService implements HashService { @Override public String hashPassword(String password) { if (password == null) { - throw new IllegalArgumentException("Password must not be null or empty"); + throw new IllegalArgumentException("Password must not be null"); } return BCrypt.hashpw(password, BCrypt.gensalt(BCRYPT_SALT_ROUND)); }