gaurav-narula commented on code in PR #22880:
URL: https://github.com/apache/kafka/pull/22880#discussion_r3646194306
##########
clients/src/main/java/org/apache/kafka/common/security/authenticator/SaslServerAuthenticator.java:
##########
@@ -139,6 +139,9 @@ private enum SaslState {
private AuthenticationException pendingException = null;
private SaslServer saslServer;
private String saslMechanism;
+ // The authenticated principal is connection-scoped. Cache it after the
first build since principal() is invoked
Review Comment:
Would help to add a line about thread-safety
We only expect this field to be mutated by the Processor thread for the
first request on the connection
##########
clients/src/test/java/org/apache/kafka/common/security/authenticator/SaslAuthenticatorTest.java:
##########
@@ -2773,4 +2799,25 @@ public KafkaPrincipal deserialize(byte[] bytes) {
return null;
}
}
+
+ public static class CountingKafkaPrincipalBuilder implements
KafkaPrincipalBuilder {
+ private static final AtomicInteger BUILD_COUNT = new AtomicInteger();
Review Comment:
I don't think this requires an AtomicInteger. Please consider using a
non-final static integer
##########
clients/src/test/java/org/apache/kafka/common/security/authenticator/SaslAuthenticatorTest.java:
##########
@@ -217,6 +217,32 @@ public void testValidSaslPlainOverPlaintext() throws
Exception {
checkAuthenticationAndReauthentication(securityProtocol, node);
}
+ @Test
+ public void testPrincipalBuiltOncePerAuthentication() throws Exception {
+ String node = "0";
+ time = new MockTime();
+ SecurityProtocol securityProtocol = SecurityProtocol.SASL_PLAINTEXT;
+ configureMechanisms("PLAIN", Collections.singletonList("PLAIN"));
+
saslServerConfigs.put(BrokerSecurityConfigs.PRINCIPAL_BUILDER_CLASS_CONFIG,
+ CountingKafkaPrincipalBuilder.class);
+ CountingKafkaPrincipalBuilder.BUILD_COUNT.set(0);
Review Comment:
I think it would be better to reset the value in `setup()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]