You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by cs...@apache.org on 2024/05/24 09:14:16 UTC

(kyuubi) branch branch-1.9 updated: [KYUUBI #6396] Add caching for KerberosAuthentication using ticketCache key

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

csy pushed a commit to branch branch-1.9
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/branch-1.9 by this push:
     new 89ea49f20 [KYUUBI #6396] Add caching for KerberosAuthentication using ticketCache key
89ea49f20 is described below

commit 89ea49f2035cc7d2978265bc2a5686a1816ea320
Author: senmiaoliu <se...@trip.com>
AuthorDate: Thu May 23 11:16:19 2024 +0800

    [KYUUBI #6396] Add caching for KerberosAuthentication using ticketCache key
    
    This pull request fixes #6396
    
    By using a cache to store CachingKerberosAuthentication objects keyed by the ticket cache path, we ensure that each unique ticket cache path generates a distinct authentication object.
    
    - [ ] Bugfix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing functionality to change)
    
    ---
    
    - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)
    
    **Be nice. Be informative.**
    
    Closes #6401 from lsm1/branch-kyuubi-6396.
    
    Closes #6396
    
    bb8f738e1 [senmiaoliu] fix kyuubiClientTicketCache
    
    Authored-by: senmiaoliu <se...@trip.com>
    Signed-off-by: Shaoyun Chen <cs...@apache.org>
    (cherry picked from commit 4285abc3ae44e15465587e1afdf82cd003c5654a)
---
 .../jdbc/hive/auth/KerberosAuthenticationManager.java   | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java
index 3df9aa836..6a639c7d6 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java
@@ -22,18 +22,19 @@ import java.util.concurrent.ConcurrentHashMap;
 
 public class KerberosAuthenticationManager {
 
-  private static CachingKerberosAuthentication GLOBAL_TGT_CACHE_AUTHENTICATION;
+  private static final Map<String, CachingKerberosAuthentication> TGT_CACHE_AUTHENTICATION_CACHE =
+      new ConcurrentHashMap<>();
 
   private static final Map<String, CachingKerberosAuthentication> KEYTAB_AUTHENTICATION_CACHE =
       new ConcurrentHashMap<>();
 
-  public static synchronized CachingKerberosAuthentication getTgtCacheAuthentication(
-      String ticketCache) {
-    if (GLOBAL_TGT_CACHE_AUTHENTICATION == null) {
-      KerberosAuthentication tgtCacheAuth = new KerberosAuthentication(ticketCache);
-      GLOBAL_TGT_CACHE_AUTHENTICATION = new CachingKerberosAuthentication(tgtCacheAuth);
-    }
-    return GLOBAL_TGT_CACHE_AUTHENTICATION;
+  public static CachingKerberosAuthentication getTgtCacheAuthentication(String ticketCache) {
+    return TGT_CACHE_AUTHENTICATION_CACHE.computeIfAbsent(
+        ticketCache,
+        key -> {
+          KerberosAuthentication tgtCacheAuth = new KerberosAuthentication(ticketCache);
+          return new CachingKerberosAuthentication(tgtCacheAuth);
+        });
   }
 
   public static CachingKerberosAuthentication getKeytabAuthentication(