Skip to content

Commit 262f07b

Browse files
committed
minor: added comment for using subject
1 parent 0f0560b commit 262f07b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

fluss-common/src/main/java/org/apache/fluss/security/auth/sasl/authenticator/SaslClientAuthenticator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ public String protocol() {
8282
@Override
8383
public byte[] authenticate(byte[] data) throws AuthenticationException {
8484
try {
85+
// Use Subject.doAs to bind the login subject to the current AccessControlContext.
86+
// This is required for Kerberos (GSSAPI) authentication because:
87+
// - GssKrb5Client.evaluateChallenge() -> GSSContextImpl.initSecContext()
88+
// retrieves the Subject via Subject.getSubject(AccessController.getContext())
89+
// to obtain Kerberos credentials (TGT and service tickets).
90+
// - Without Subject.doAs, GSSAPI cannot find the credentials and authentication fails.
8591
return Subject.doAs(
8692
loginManager.subject(),
8793
(PrivilegedExceptionAction<byte[]>) () -> saslClient.evaluateChallenge(data));

fluss-common/src/main/java/org/apache/fluss/security/auth/sasl/authenticator/SaslServerAuthenticator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ public void matchProtocol(String protocol) {
139139
@Override
140140
public byte[] evaluateResponse(byte[] token) throws AuthenticationException {
141141
try {
142+
// Use Subject.doAs to bind the login subject to the current AccessControlContext.
143+
// This is required for Kerberos (GSSAPI) authentication because:
144+
// - GssKrb5Server.evaluateResponse() -> GSSContextImpl.acceptSecContext()
145+
// retrieves the Subject via Subject.getSubject(AccessController.getContext())
146+
// to obtain server credentials from the keytab for validating client service tickets.
147+
// - Without Subject.doAs, GSSAPI cannot find the credentials and authentication fails.
142148
return Subject.doAs(
143149
loginManager.subject(),
144150
(PrivilegedExceptionAction<byte[]>) () -> saslServer.evaluateResponse(token));

0 commit comments

Comments
 (0)