HADOOP-11379. Fix new findbugs warnings in hadoop-auth*. Contributed by Li Lu.

This commit is contained in:
Haohui Mai 2014-12-09 13:08:51 -08:00
parent e8e86e3ec7
commit b68d51e898
6 changed files with 15 additions and 5 deletions

View File

@ -19,6 +19,7 @@
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
/**
* Example that uses <code>AuthenticatedURL</code>.
@ -39,7 +40,9 @@ public static void main(String[] args) {
System.out.println("Status code: " + conn.getResponseCode() + " " + conn.getResponseMessage());
System.out.println();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
BufferedReader reader = new BufferedReader(
new InputStreamReader(
conn.getInputStream(), Charset.forName("UTF-8")));
String line = reader.readLine();
while (line != null) {
System.out.println(line);

View File

@ -14,6 +14,8 @@
package org.apache.hadoop.security.authentication.util;
import com.google.common.annotations.VisibleForTesting;
import java.nio.charset.Charset;
import java.util.Random;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
@ -46,6 +48,6 @@ public RandomSignerSecretProvider(long seed) {
@Override
protected byte[] generateNewSecret() {
return Long.toString(rand.nextLong()).getBytes();
return Long.toString(rand.nextLong()).getBytes(Charset.forName("UTF-8"));
}
}

View File

@ -15,6 +15,7 @@
import org.apache.commons.codec.binary.Base64;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -86,7 +87,7 @@ public String verifyAndExtract(String signedStr) throws SignerException {
protected String computeSignature(byte[] secret, String str) {
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(str.getBytes());
md.update(str.getBytes(Charset.forName("UTF-8")));
md.update(secret);
byte[] digest = md.digest();
return new Base64(0).encodeToString(digest);

View File

@ -13,6 +13,7 @@
*/
package org.apache.hadoop.security.authentication.util;
import java.nio.charset.Charset;
import java.util.Properties;
import javax.servlet.ServletContext;
import org.apache.hadoop.classification.InterfaceAudience;
@ -36,7 +37,7 @@ public void init(Properties config, ServletContext servletContext,
long tokenValidity) throws Exception {
String signatureSecret = config.getProperty(
AuthenticationFilter.SIGNATURE_SECRET, null);
secret = signatureSecret.getBytes();
secret = signatureSecret.getBytes(Charset.forName("UTF-8"));
secrets = new byte[][]{secret};
}

View File

@ -15,6 +15,7 @@
import com.google.common.annotations.VisibleForTesting;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -369,7 +370,7 @@ private synchronized void pullFromZK(boolean isInit) {
}
private byte[] generateRandomSecret() {
return Long.toString(rand.nextLong()).getBytes();
return Long.toString(rand.nextLong()).getBytes(Charset.forName("UTF-8"));
}
/**

View File

@ -182,6 +182,8 @@ Release 2.7.0 - UNRELEASED
HADOOP-11273. TestMiniKdc failure: login options not compatible with IBM
JDK. (Gao Zhong Liang via wheat9)
HADOOP-11379. Fix new findbugs warnings in hadoop-auth*. (Li Lu via wheat9)
Release 2.6.0 - 2014-11-18
INCOMPATIBLE CHANGES