You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lp...@apache.org on 2024/01/03 18:42:26 UTC

(shiro) branch main updated: bugfix(crypto): DefaultPasswordService takes HashService default hash algorithm into account when encrypting passwords

This is an automated email from the ASF dual-hosted git repository.

lprimak pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shiro.git


The following commit(s) were added to refs/heads/main by this push:
     new d442c3deb bugfix(crypto): DefaultPasswordService takes HashService default hash algorithm into account when encrypting passwords
     new 78fca2fa8 Merge pull request #1263 from lprimak/add-default-hash-service-method
d442c3deb is described below

commit d442c3debb86f091bc5e7ca8f2732b7439713f29
Author: lprimak <le...@flowlogix.com>
AuthorDate: Wed Jan 3 11:17:20 2024 -0500

    bugfix(crypto): DefaultPasswordService takes HashService default hash algorithm into account when encrypting passwords
---
 .../org/apache/shiro/authc/credential/DefaultPasswordService.java   | 4 +++-
 .../main/java/org/apache/shiro/crypto/hash/DefaultHashService.java  | 1 +
 .../src/main/java/org/apache/shiro/crypto/hash/HashService.java     | 6 ++++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java b/core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java
index 73fd34136..8ec5d9fe3 100644
--- a/core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java
+++ b/core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java
@@ -141,7 +141,9 @@ public class DefaultPasswordService implements HashingPasswordService {
     }
 
     protected HashRequest createHashRequest(ByteSource plaintext) {
-        return new HashRequest.Builder().setSource(plaintext).build();
+        return new HashRequest.Builder().setSource(plaintext)
+                .setAlgorithmName(getHashService().getDefaultAlgorithmName())
+                .build();
     }
 
     protected ByteSource createByteSource(Object o) {
diff --git a/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/DefaultHashService.java b/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/DefaultHashService.java
index 4879424c6..2f73cdfec 100644
--- a/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/DefaultHashService.java
+++ b/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/DefaultHashService.java
@@ -108,6 +108,7 @@ public class DefaultHashService implements ConfigurableHashService {
         this.defaultAlgorithmName = name;
     }
 
+    @Override
     public String getDefaultAlgorithmName() {
         return this.defaultAlgorithmName;
     }
diff --git a/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/HashService.java b/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/HashService.java
index 30e4e9807..4a7a4ad54 100644
--- a/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/HashService.java
+++ b/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/HashService.java
@@ -74,4 +74,10 @@ public interface HashService {
      * @see Hash#getSalt()
      */
     Hash computeHash(HashRequest request);
+
+    /**
+     * @return Default algorithm name for this hash service
+     * @since 2.0
+     */
+    String getDefaultAlgorithmName();
 }