HADOOP-11379. Fix new findbugs warnings in hadoop-auth*. Contributed by Li Lu.
This commit is contained in:
parent
5776a41da0
commit
6df457a3d7
@ -19,6 +19,7 @@
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example that uses <code>AuthenticatedURL</code>.
|
* 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("Status code: " + conn.getResponseCode() + " " + conn.getResponseMessage());
|
||||||
System.out.println();
|
System.out.println();
|
||||||
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
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();
|
String line = reader.readLine();
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
package org.apache.hadoop.security.authentication.util;
|
package org.apache.hadoop.security.authentication.util;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.classification.InterfaceStability;
|
import org.apache.hadoop.classification.InterfaceStability;
|
||||||
@ -46,6 +48,6 @@ public RandomSignerSecretProvider(long seed) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected byte[] generateNewSecret() {
|
protected byte[] generateNewSecret() {
|
||||||
return Long.toString(rand.nextLong()).getBytes();
|
return Long.toString(rand.nextLong()).getBytes(Charset.forName("UTF-8"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ public String verifyAndExtract(String signedStr) throws SignerException {
|
|||||||
protected String computeSignature(byte[] secret, String str) {
|
protected String computeSignature(byte[] secret, String str) {
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA");
|
MessageDigest md = MessageDigest.getInstance("SHA");
|
||||||
md.update(str.getBytes());
|
md.update(str.getBytes(Charset.forName("UTF-8")));
|
||||||
md.update(secret);
|
md.update(secret);
|
||||||
byte[] digest = md.digest();
|
byte[] digest = md.digest();
|
||||||
return new Base64(0).encodeToString(digest);
|
return new Base64(0).encodeToString(digest);
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.security.authentication.util;
|
package org.apache.hadoop.security.authentication.util;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
@ -36,7 +37,7 @@ public void init(Properties config, ServletContext servletContext,
|
|||||||
long tokenValidity) throws Exception {
|
long tokenValidity) throws Exception {
|
||||||
String signatureSecret = config.getProperty(
|
String signatureSecret = config.getProperty(
|
||||||
AuthenticationFilter.SIGNATURE_SECRET, null);
|
AuthenticationFilter.SIGNATURE_SECRET, null);
|
||||||
secret = signatureSecret.getBytes();
|
secret = signatureSecret.getBytes(Charset.forName("UTF-8"));
|
||||||
secrets = new byte[][]{secret};
|
secrets = new byte[][]{secret};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -369,7 +370,7 @@ private synchronized void pullFromZK(boolean isInit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte[] generateRandomSecret() {
|
private byte[] generateRandomSecret() {
|
||||||
return Long.toString(rand.nextLong()).getBytes();
|
return Long.toString(rand.nextLong()).getBytes(Charset.forName("UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -548,6 +548,8 @@ Release 2.7.0 - UNRELEASED
|
|||||||
HADOOP-11273. TestMiniKdc failure: login options not compatible with IBM
|
HADOOP-11273. TestMiniKdc failure: login options not compatible with IBM
|
||||||
JDK. (Gao Zhong Liang via wheat9)
|
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
|
Release 2.6.0 - 2014-11-18
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
Loading…
Reference in New Issue
Block a user