From 76a6fe6a8be51bac4d6ba2edfb07f5604d73b7f2 Mon Sep 17 00:00:00 2001 From: belugabehr <12578579+belugabehr@users.noreply.github.com> Date: Thu, 2 Jan 2020 15:06:19 -0500 Subject: [PATCH] HBASE-23628: Remove Apache Commons Digest Base64 (#977) Signed-off-by: stack (cherry picked from commit 280b94434cbd63495c78ae40d33a720e406dc272) --- .../org/apache/hadoop/hbase/security/SaslUtil.java | 9 ++++----- .../FanOutOneBlockAsyncDFSOutputSaslHelper.java | 12 +++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/security/SaslUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/security/SaslUtil.java index 7091df5b882..72851b6a910 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/security/SaslUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/security/SaslUtil.java @@ -18,7 +18,7 @@ */ package org.apache.hadoop.hbase.security; -import java.nio.charset.StandardCharsets; +import java.util.Base64; import java.util.Map; import java.util.TreeMap; @@ -27,7 +27,6 @@ import javax.security.sasl.SaslClient; import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; -import org.apache.commons.codec.binary.Base64; import org.apache.hadoop.hbase.util.Bytes; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; @@ -70,15 +69,15 @@ public class SaslUtil { } static String encodeIdentifier(byte[] identifier) { - return new String(Base64.encodeBase64(identifier), StandardCharsets.UTF_8); + return Base64.getEncoder().encodeToString(identifier); } static byte[] decodeIdentifier(String identifier) { - return Base64.decodeBase64(Bytes.toBytes(identifier)); + return Base64.getDecoder().decode(Bytes.toBytes(identifier)); } static char[] encodePassword(byte[] password) { - return new String(Base64.encodeBase64(password), StandardCharsets.UTF_8).toCharArray(); + return Base64.getEncoder().encodeToString(password).toCharArray(); } /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputSaslHelper.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputSaslHelper.java index 96efe7ca3ec..c1603916ca8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputSaslHelper.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputSaslHelper.java @@ -31,6 +31,7 @@ import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; import java.util.Arrays; +import java.util.Base64; import java.util.Collections; import java.util.List; import java.util.Map; @@ -47,7 +48,6 @@ import javax.security.sasl.RealmChoiceCallback; import javax.security.sasl.Sasl; import javax.security.sasl.SaslClient; import javax.security.sasl.SaslException; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.crypto.CipherOption; @@ -77,7 +77,6 @@ import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.hbase.thirdparty.com.google.common.base.Charsets; import org.apache.hbase.thirdparty.com.google.common.base.Throwables; import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet; import org.apache.hbase.thirdparty.com.google.common.collect.Maps; @@ -666,20 +665,19 @@ public final class FanOutOneBlockAsyncDFSOutputSaslHelper { private static String getUserNameFromEncryptionKey(DataEncryptionKey encryptionKey) { return encryptionKey.keyId + NAME_DELIMITER + encryptionKey.blockPoolId + NAME_DELIMITER - + new String(Base64.encodeBase64(encryptionKey.nonce, false), Charsets.UTF_8); + + Base64.getEncoder().encodeToString(encryptionKey.nonce); } private static char[] encryptionKeyToPassword(byte[] encryptionKey) { - return new String(Base64.encodeBase64(encryptionKey, false), Charsets.UTF_8).toCharArray(); + return Base64.getEncoder().encodeToString(encryptionKey).toCharArray(); } private static String buildUsername(Token blockToken) { - return new String(Base64.encodeBase64(blockToken.getIdentifier(), false), Charsets.UTF_8); + return Base64.getEncoder().encodeToString(blockToken.getIdentifier()); } private static char[] buildClientPassword(Token blockToken) { - return new String(Base64.encodeBase64(blockToken.getPassword(), false), Charsets.UTF_8) - .toCharArray(); + return Base64.getEncoder().encodeToString(blockToken.getPassword()).toCharArray(); } private static Map createSaslPropertiesForEncryption(String encryptionAlgorithm) {