diff --git a/service/src/java/org/apache/hive/service/CookieSigner.java b/service/src/java/org/apache/hive/service/CookieSigner.java index ec741edcc2..5cfb9aeeea 100644 --- a/service/src/java/org/apache/hive/service/CookieSigner.java +++ b/service/src/java/org/apache/hive/service/CookieSigner.java @@ -20,8 +20,8 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Base64; -import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,7 +99,7 @@ private String getSignature(String str) { md.update(str.getBytes()); md.update(secretBytes); byte[] digest = md.digest(); - return new Base64(0).encodeToString(digest); + return Base64.getEncoder().encodeToString(digest); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException("Invalid SHA digest String: " + SHA_STRING + " " + ex.getMessage(), ex); diff --git a/service/src/java/org/apache/hive/service/auth/HttpAuthUtils.java b/service/src/java/org/apache/hive/service/auth/HttpAuthUtils.java index 7dc11b27f9..31985d9f33 100644 --- a/service/src/java/org/apache/hive/service/auth/HttpAuthUtils.java +++ b/service/src/java/org/apache/hive/service/auth/HttpAuthUtils.java @@ -21,6 +21,7 @@ import java.security.PrivilegedExceptionAction; import java.security.SecureRandom; import java.util.Arrays; +import java.util.Base64; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -29,7 +30,6 @@ import javax.security.auth.Subject; -import org.apache.commons.codec.binary.Base64; import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge; import org.apache.hadoop.security.UserGroupInformation; import org.apache.http.protocol.BasicHttpContext; @@ -142,13 +142,11 @@ private HttpAuthUtils() { public static final String SERVER_HTTP_URL = "SERVER_HTTP_URL"; private final String serverPrincipal; private final String serverHttpUrl; - private final Base64 base64codec; private final HttpContext httpContext; public HttpKerberosClientAction(String serverPrincipal, String serverHttpUrl) { this.serverPrincipal = serverPrincipal; this.serverHttpUrl = serverHttpUrl; - base64codec = new Base64(0); httpContext = new BasicHttpContext(); httpContext.setAttribute(SERVER_HTTP_URL, serverHttpUrl); } @@ -172,7 +170,7 @@ public String run() throws Exception { byte[] outToken = gssContext.initSecContext(inToken, 0, inToken.length); gssContext.dispose(); // Base64 encoded and stringified token for server - return new String(base64codec.encode(outToken)); + return Base64.getEncoder().encodeToString(outToken); } } } diff --git a/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java b/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java index 468ce10be5..384eb47a78 100644 --- a/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java +++ b/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java @@ -26,6 +26,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,7 +38,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.commons.codec.binary.Base64; import org.apache.hadoop.hive.common.LogUtils; import org.apache.hadoop.hive.common.io.SessionStream; import org.apache.hadoop.hive.common.metrics.common.Metrics; @@ -193,7 +193,7 @@ public void run() { // set the operation handle information in Driver, so that thrift API users // can use the operation handle they receive, to lookup query information in // Yarn ATS - String guid64 = Base64.encodeBase64URLSafeString(getHandle().getHandleIdentifier() + String guid64 = Base64.getUrlEncoder().encodeToString(getHandle().getHandleIdentifier() .toTHandleIdentifier().getGuid()).trim(); driver.setOperationId(guid64); diff --git a/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpServlet.java b/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpServlet.java index e2231c2afa..d437ec73b8 100644 --- a/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpServlet.java +++ b/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpServlet.java @@ -24,6 +24,7 @@ import java.security.PrivilegedExceptionAction; import java.security.SecureRandom; import java.util.Arrays; +import java.util.Base64; import java.util.Collections; import java.util.List; import java.util.Map; @@ -37,7 +38,6 @@ import javax.ws.rs.core.NewCookie; import com.google.common.io.ByteStreams; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.StringUtils; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; @@ -490,7 +490,7 @@ public String run() throws HttpAuthenticationException { gssContext = manager.createContext(serverCreds); // Get service ticket from the authorization header String serviceTicketBase64 = getAuthHeader(request, authType); - byte[] inToken = Base64.decodeBase64(serviceTicketBase64.getBytes()); + byte[] inToken = Base64.getDecoder().decode(serviceTicketBase64); gssContext.acceptSecContext(inToken, 0, inToken.length); // Authenticate or deny based on its context completion if (!gssContext.isEstablished()) { @@ -571,7 +571,7 @@ private String getPassword(HttpServletRequest request, String authType) String authType) throws HttpAuthenticationException { String authHeaderBase64 = getAuthHeader(request, authType); String authHeaderString = StringUtils.newStringUtf8( - Base64.decodeBase64(authHeaderBase64.getBytes())); + Base64.getDecoder().decode(authHeaderBase64)); String[] creds = authHeaderString.split(":"); return creds; }