You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ar...@apache.org on 2016/07/04 14:51:45 UTC
svn commit: r1751300 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base:
crypto/HashCrypt.java util/UtilIO.java util/test/UtilIOTests.java
Author: arunpatidar
Date: Mon Jul 4 14:51:45 2016
New Revision: 1751300
URL: http://svn.apache.org/viewvc?rev=1751300&view=rev
Log:
Applied patch from jira issue - OFBIZ-7590 - Enforce noninstantiability to UtilIO class. Thanks Rohit Koushal for your contribution.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java?rev=1751300&r1=1751299&r2=1751300&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java Mon Jul 4 14:51:45 2016
@@ -18,8 +18,6 @@
*******************************************************************************/
package org.ofbiz.base.crypto;
-import static org.ofbiz.base.util.UtilIO.UTF8;
-
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -32,6 +30,7 @@ import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralRuntimeException;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilIO;
/**
* Utility class for doing SHA-1/MD5 One-Way Hash Encryption
@@ -55,7 +54,7 @@ public class HashCrypt {
// FIXME: should have been getBytes("UTF-8") originally
return doCompareTypePrefix(crypted, defaultCrypt, password.getBytes());
} else if (crypted.startsWith("$")) {
- return doComparePosix(crypted, defaultCrypt, password.getBytes(UTF8));
+ return doComparePosix(crypted, defaultCrypt, password.getBytes(UtilIO.getUtf8()));
} else {
// FIXME: should have been getBytes("UTF-8") originally
return doCompareBare(crypted, defaultCrypt, password.getBytes());
@@ -112,7 +111,7 @@ public class HashCrypt {
}
public static String cryptUTF8(String hashType, String salt, String value) {
- return value != null ? cryptBytes(hashType, salt, value.getBytes(UTF8)) : null;
+ return value != null ? cryptBytes(hashType, salt, value.getBytes(UtilIO.getUtf8())) : null;
}
public static String cryptValue(String hashType, String salt, String value) {
@@ -135,7 +134,7 @@ public class HashCrypt {
private static String getCryptedBytes(String hashType, String salt, byte[] bytes) {
try {
MessageDigest messagedigest = MessageDigest.getInstance(hashType);
- messagedigest.update(salt.getBytes(UTF8));
+ messagedigest.update(salt.getBytes(UtilIO.getUtf8()));
messagedigest.update(bytes);
return Base64.encodeBase64URLSafeString(messagedigest.digest()).replace('+', '.');
} catch (NoSuchAlgorithmException e) {
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java?rev=1751300&r1=1751299&r2=1751300&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java Mon Jul 4 14:51:45 2016
@@ -35,9 +35,10 @@ import java.nio.charset.Charset;
import org.apache.commons.io.IOUtils;
public final class UtilIO {
- public static final Charset UTF8 = Charset.forName("UTF-8");
+ private static final Charset UTF8 = Charset.forName("UTF-8");
public static final String module = UtilIO.class.getName();
+ private UtilIO () {}
/** Copy an InputStream to an OutputStream, optionally closing either
* the input or the output.
*
@@ -315,4 +316,8 @@ public final class UtilIO {
writer.write(value.substring(r));
writer.close();
}
+
+ public static Charset getUtf8() {
+ return UTF8;
+ }
}
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java?rev=1751300&r1=1751299&r2=1751300&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java Mon Jul 4 14:51:45 2016
@@ -80,13 +80,13 @@ public class UtilIOTests extends Generic
private static void readStringTest_1(String label, String wanted, byte[] toRead) throws IOException {
assertEquals("readString bytes default:" + label, wanted, UtilIO.readString(toRead));
assertEquals("readString bytes UTF-8:" + label, wanted, UtilIO.readString(toRead, "UTF-8"));
- assertEquals("readString bytes UTF8:" + label, wanted, UtilIO.readString(toRead, UtilIO.UTF8));
+ assertEquals("readString bytes UTF8:" + label, wanted, UtilIO.readString(toRead, UtilIO.getUtf8()));
assertEquals("readString bytes offset/length default:" + label, wanted, UtilIO.readString(toRead, 0, toRead.length));
assertEquals("readString bytes offset/length UTF-8:" + label, wanted, UtilIO.readString(toRead, 0, toRead.length, "UTF-8"));
- assertEquals("readString bytes offset/length UTF8:" + label, wanted, UtilIO.readString(toRead, 0, toRead.length, UtilIO.UTF8));
+ assertEquals("readString bytes offset/length UTF8:" + label, wanted, UtilIO.readString(toRead, 0, toRead.length, UtilIO.getUtf8()));
assertEquals("readString stream default:" + label, wanted, UtilIO.readString(new ByteArrayInputStream(toRead)));
assertEquals("readString stream UTF-8:" + label, wanted, UtilIO.readString(new ByteArrayInputStream(toRead), "UTF-8"));
- assertEquals("readString stream UTF8:" + label, wanted, UtilIO.readString(new ByteArrayInputStream(toRead), UtilIO.UTF8));
+ assertEquals("readString stream UTF8:" + label, wanted, UtilIO.readString(new ByteArrayInputStream(toRead), UtilIO.getUtf8()));
}
public void testWriteString() throws Exception {
@@ -115,7 +115,7 @@ public class UtilIOTests extends Generic
UtilIO.writeString(baos, "UTF-8", toWrite);
assertEquals("writeString UTF-8:" + label, wanted, baos.toByteArray());
baos = new ByteArrayOutputStream();
- UtilIO.writeString(baos, UtilIO.UTF8, toWrite);
+ UtilIO.writeString(baos, UtilIO.getUtf8(), toWrite);
assertEquals("writeString UTF8:" + label, wanted, baos.toByteArray());
}
}