You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2022/07/18 07:15:36 UTC

[incubator-kyuubi] branch master updated: [KYUUBI #3092] Replace apache commons Base64 w/ JDK

This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 47f8f9cc9 [KYUUBI #3092] Replace apache commons Base64 w/ JDK
47f8f9cc9 is described below

commit 47f8f9cc9a8e6c557af91be5fbbb40549b5b108f
Author: Cheng Pan <ch...@apache.org>
AuthorDate: Mon Jul 18 15:15:28 2022 +0800

    [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 <ch...@apache.org>
    Signed-off-by: Cheng Pan <ch...@apache.org>
---
 .../main/java/org/apache/kyuubi/jdbc/hive/auth/HttpAuthUtils.java   | 6 ++----
 .../scala/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<String> {
     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(