[KYUUBI #6396][FOLLOWUP] Avoid NPE

# 🔍 Description
## Issue References 🔗

This pull request fixes #6396

## Describe Your Solution 🔧

NPE will occur when kyuubiClientTicketCache is not specified. `ConcurrentHashMap` does not allow null key.

## Types of changes 🔖

- [X] 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)

## Test Plan 🧪

#### Behavior Without This Pull Request ⚰️

#### Behavior With This Pull Request 🎉

#### Related Unit Tests

---

# Checklist 📝

- [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 #6420 from wForget/hotfix2.

Closes #6396

e5d5f9d33 [wforget] address comment
fe9ecd1b1 [wforget] Avoid NPE

Authored-by: wforget <643348094@qq.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
wforget 2024-05-27 06:31:39 +00:00 committed by Cheng Pan
parent 6888874808
commit e4ecde2c1d
2 changed files with 4 additions and 1 deletions

View File

@ -930,7 +930,7 @@ public class KyuubiConnection implements SQLConnection, KyuubiLoggable {
AccessControlContext context = AccessController.getContext(); AccessControlContext context = AccessController.getContext();
return Subject.getSubject(context); return Subject.getSubject(context);
} else if (isTgtCacheAuthMode()) { } else if (isTgtCacheAuthMode()) {
String ticketCache = sessConfMap.get(AUTH_KYUUBI_CLIENT_TICKET_CACHE); String ticketCache = sessConfMap.getOrDefault(AUTH_KYUUBI_CLIENT_TICKET_CACHE, "");
return KerberosAuthenticationManager.getTgtCacheAuthentication(ticketCache).getSubject(); return KerberosAuthenticationManager.getTgtCacheAuthentication(ticketCache).getSubject();
} else { } else {
// This should never happen // This should never happen

View File

@ -17,6 +17,8 @@
package org.apache.kyuubi.jdbc.hive.auth; package org.apache.kyuubi.jdbc.hive.auth;
import static java.util.Objects.requireNonNull;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -29,6 +31,7 @@ public class KerberosAuthenticationManager {
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
public static CachingKerberosAuthentication getTgtCacheAuthentication(String ticketCache) { public static CachingKerberosAuthentication getTgtCacheAuthentication(String ticketCache) {
requireNonNull(ticketCache, "ticketCache is null");
return TGT_CACHE_AUTHENTICATION_CACHE.computeIfAbsent( return TGT_CACHE_AUTHENTICATION_CACHE.computeIfAbsent(
ticketCache, ticketCache,
key -> { key -> {