From 47f8f9cc9a8e6c557af91be5fbbb40549b5b108f Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Mon, 18 Jul 2022 15:15:28 +0800 Subject: [PATCH] [KYUUBI #3092] Replace apache commons Base64 w/ JDK ### _Why are the changes needed?_ Minor code clean-up, prefer to use the JDK-provided tools. ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #3092 from pan3793/base64. Closes #3092 8e8f2278 [Cheng Pan] Replace apache commons Base64 w/ JDK Authored-by: Cheng Pan Signed-off-by: Cheng Pan --- .../org/apache/kyuubi/jdbc/hive/auth/HttpAuthUtils.java | 6 ++---- .../org/apache/kyuubi/server/http/util/CookieSigner.scala | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/HttpAuthUtils.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/HttpAuthUtils.java index 09ce3bab4..ea69055f9 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/HttpAuthUtils.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/HttpAuthUtils.java @@ -18,8 +18,8 @@ package org.apache.kyuubi.jdbc.hive.auth; import java.security.PrivilegedExceptionAction; +import java.util.Base64; import javax.security.auth.Subject; -import org.apache.commons.codec.binary.Base64; import org.apache.hadoop.security.UserGroupInformation; import org.ietf.jgss.GSSContext; import org.ietf.jgss.GSSManager; @@ -58,11 +58,9 @@ public final class HttpAuthUtils { */ public static class HttpKerberosClientAction implements PrivilegedExceptionAction { private final String serverPrincipal; - private final Base64 base64codec; public HttpKerberosClientAction(String serverPrincipal) { this.serverPrincipal = serverPrincipal; - base64codec = new Base64(0); } @Override @@ -84,7 +82,7 @@ public final class HttpAuthUtils { 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/kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/util/CookieSigner.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/util/CookieSigner.scala index 0c4bca1a7..d4c8b2e8b 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/util/CookieSigner.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/util/CookieSigner.scala @@ -18,8 +18,7 @@ package org.apache.kyuubi.server.http.util import java.security.{MessageDigest, NoSuchAlgorithmException} - -import org.apache.commons.codec.binary.Base64 +import java.util.Base64 import org.apache.kyuubi.Logging @@ -78,7 +77,7 @@ class CookieSigner(secret: Array[Byte]) extends Logging { md.update(str.getBytes) md.update(secretBytes) val digest = md.digest - new Base64(0).encodeToString(digest) + Base64.getEncoder.encodeToString(digest) } catch { case ex: NoSuchAlgorithmException => throw new RuntimeException(