Skip to content

Commit 3acb194

Browse files
committed
Fix SaslAuthenticator failure caused by apache/pulsar#19295
1 parent 9513f8f commit 3acb194

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

kafka-impl/src/main/java/io/streamnative/pulsar/handlers/kop/security/PlainSaslServer.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import java.nio.charset.StandardCharsets;
2323
import java.util.Arrays;
2424
import java.util.Set;
25+
import java.util.concurrent.ExecutionException;
26+
import java.util.concurrent.TimeUnit;
27+
import java.util.concurrent.TimeoutException;
2528
import javax.naming.AuthenticationException;
2629
import javax.security.sasl.SaslException;
2730
import javax.security.sasl.SaslServer;
@@ -79,8 +82,10 @@ public byte[] evaluateResponse(byte[] response) throws SaslException {
7982
}
8083

8184
try {
82-
final AuthenticationState authState = authenticationProvider.newAuthState(
83-
AuthData.of(saslAuth.getAuthData().getBytes(StandardCharsets.UTF_8)), null, null);
85+
final AuthData authData = AuthData.of(saslAuth.getAuthData().getBytes(StandardCharsets.UTF_8));
86+
final AuthenticationState authState = authenticationProvider.newAuthState(authData, null, null);
87+
// TODO: Use the request.timeout.ms config from the Kafka client as the timeout
88+
authState.authenticateAsync(authData).get(10, TimeUnit.SECONDS);
8489
final String role = authState.getAuthRole();
8590
if (StringUtils.isEmpty(role)) {
8691
throw new AuthenticationException("Role cannot be empty.");
@@ -109,7 +114,7 @@ public byte[] evaluateResponse(byte[] response) throws SaslException {
109114
}
110115
complete = true;
111116
return new byte[0];
112-
} catch (AuthenticationException e) {
117+
} catch (AuthenticationException | ExecutionException | InterruptedException | TimeoutException e) {
113118
throw new SaslException(e.getMessage());
114119
}
115120
}

0 commit comments

Comments
 (0)