[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 <chengpan@apache.org>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
Cheng Pan 2022-07-18 15:15:28 +08:00
parent 77b6ee0dca
commit 47f8f9cc9a
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D
2 changed files with 4 additions and 7 deletions

View File

@ -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);
}
}
}

View File

@ -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(