You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2016/07/07 20:31:48 UTC

[3/3] shiro git commit: SHIRO-483 always use English locale in ProvidedHashFormat

SHIRO-483 always use English locale in ProvidedHashFormat

One of the provided hash values is 'SHIRO1' which causes a problem with Turkish locales, because of the letter 'i'
http://www.i18nguy.com/unicode/turkish-i18n.html


Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/5b59da34
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/5b59da34
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/5b59da34

Branch: refs/heads/master
Commit: 5b59da340aad44c098b138db55efd043e18123d7
Parents: 2d0db71
Author: Brian Demers <bd...@apache.org>
Authored: Thu Jul 7 16:25:56 2016 -0400
Committer: Brian Demers <bd...@apache.org>
Committed: Thu Jul 7 16:25:56 2016 -0400

----------------------------------------------------------------------
 .../credential/DefaultPasswordServiceTest.groovy  | 18 ++++++++++++++++++
 .../crypto/hash/format/ProvidedHashFormat.java    |  6 +++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/shiro/blob/5b59da34/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy b/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy
index 7b600bc..5365e75 100644
--- a/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy
+++ b/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy
@@ -153,4 +153,22 @@ class DefaultPasswordServiceTest {
         assertTrue service.passwordsMatch("12345", formatted)
     }
 
+    @Test
+    void testTurkishLocal() {
+
+        Locale locale = Locale.getDefault();
+
+        // tr_TR
+        Locale.setDefault(new Locale("tr", "TR"));
+
+        try {
+            PasswordService passwordService = new DefaultPasswordService();
+            String password = "333";
+            String enc = passwordService.encryptPassword(password);
+            assertTrue(passwordService.passwordsMatch(password, enc));
+        }
+        finally {
+            Locale.setDefault(locale);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/shiro/blob/5b59da34/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/format/ProvidedHashFormat.java
----------------------------------------------------------------------
diff --git a/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/format/ProvidedHashFormat.java b/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/format/ProvidedHashFormat.java
index bfd90a5..3813123 100644
--- a/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/format/ProvidedHashFormat.java
+++ b/crypto/hash/src/main/java/org/apache/shiro/crypto/hash/format/ProvidedHashFormat.java
@@ -18,6 +18,8 @@
  */
 package org.apache.shiro.crypto.hash.format;
 
+import java.util.Locale;
+
 /**
  * An enum representing Shiro's default provided {@link HashFormat} implementations.
  *
@@ -55,7 +57,9 @@ public enum ProvidedHashFormat {
             return null;
         }
         try {
-            return valueOf(id.toUpperCase());
+            // Use English Locale, some Locales handle uppercase/lower differently. i.e. Turkish and upper case 'i'
+            // is not 'I'. And 'SHIRO1' would be 'SH\u0130RO1'
+            return valueOf(id.toUpperCase(Locale.ENGLISH));
         } catch (IllegalArgumentException ignored) {
             return null;
         }