MINOR: Refactor on DelegationTokenManager follow up with KAFKA-18711 (#20579)

Follow-up PR of KAFKA-18711. The motivation and reason for this change
are outlined in [1].

[1] - https://github.com/apache/kafka/pull/20475#discussion_r2375608168

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Maros Orsak 2025-09-24 20:25:44 +02:00 committed by GitHub
parent ac63ce9789
commit 563338c0e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -64,7 +64,6 @@ import org.apache.kafka.security.DelegationTokenManager
import org.apache.kafka.server.{ApiVersionManager, ClientMetricsManager, ProcessRole}
import org.apache.kafka.server.authorizer._
import org.apache.kafka.server.common.{GroupVersion, RequestLocal, ShareVersion, StreamsVersion, TransactionVersion}
import org.apache.kafka.server.config.DelegationTokenManagerConfigs
import org.apache.kafka.server.share.context.ShareFetchContext
import org.apache.kafka.server.share.{ErroneousAndValidPartitionData, SharePartitionKey}
import org.apache.kafka.server.share.acknowledge.ShareAcknowledgementBatch
@ -2314,7 +2313,7 @@ class KafkaApis(val requestChannel: RequestChannel,
if (!allowTokenRequests(request))
sendResponseCallback(Errors.DELEGATION_TOKEN_REQUEST_NOT_ALLOWED, Collections.emptyList)
else if (!new DelegationTokenManagerConfigs(config).tokenAuthEnabled)
else if (!tokenManager.isEnabled)
sendResponseCallback(Errors.DELEGATION_TOKEN_AUTH_DISABLED, Collections.emptyList)
else {
val requestPrincipal = request.context.principal

View File

@ -104,6 +104,10 @@ public class DelegationTokenManager {
.toList();
}
public boolean isEnabled() {
return secretKey != null;
}
public static boolean filterToken(
KafkaPrincipal requesterPrincipal,
Optional<List<KafkaPrincipal>> owners,