Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ SaslClient createSaslClient() {
String[] mechs = {mechanism};
log.debug("Creating SaslClient: client={};service={};serviceHostname={};mechs={}",
clientPrincipalName, servicePrincipal, host, Arrays.toString(mechs));
return Sasl.createSaslClient(mechs, clientPrincipalName, servicePrincipal, host, configs, callbackHandler);
SaslClient retvalSaslClient = Sasl.createSaslClient(mechs, clientPrincipalName, servicePrincipal, host, configs, callbackHandler);
Comment thread
rondagostino marked this conversation as resolved.
if (retvalSaslClient == null) {
throw new SaslAuthenticationException("Failed to create SaslClient with mechanism " + mechanism);
}
return retvalSaslClient;
});
} catch (PrivilegedActionException e) {
throw new SaslAuthenticationException("Failed to create SaslClient with mechanism " + mechanism, e.getCause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,11 @@ private void createSaslServer(String mechanism) throws IOException {
try {
saslServer = Subject.doAs(subject, (PrivilegedExceptionAction<SaslServer>) () ->
Sasl.createSaslServer(saslMechanism, "kafka", serverAddress().getHostName(), configs, callbackHandler));
if (saslServer == null) {
throw new SaslException("Kafka Server failed to create a SaslServer to interact with a client during session authentication with server mechanism " + saslMechanism);
}
} catch (PrivilegedActionException e) {
throw new SaslException("Kafka Server failed to create a SaslServer to interact with a client during session authentication", e.getCause());
throw new SaslException("Kafka Server failed to create a SaslServer to interact with a client during session authentication with server mechanism " + saslMechanism, e.getCause());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,9 +1236,18 @@ public void testInvalidMechanism() throws Exception {
saslClientConfigs.put(SaslConfigs.SASL_MECHANISM, "INVALID");

server = createEchoServer(securityProtocol);
createAndCheckClientConnectionFailure(securityProtocol, node);
server.verifyAuthenticationMetrics(0, 1);
server.verifyReauthenticationMetrics(0, 0);
try {
createAndCheckClientConnectionFailure(securityProtocol, node);
fail("Did not generate exception prior to creating channel");
} catch (IOException expected) {
server.verifyAuthenticationMetrics(0, 0);
server.verifyReauthenticationMetrics(0, 0);
Throwable underlyingCause = expected.getCause().getCause().getCause();
assertEquals(SaslAuthenticationException.class, underlyingCause.getClass());
assertEquals("Failed to create SaslClient with mechanism INVALID", underlyingCause.getMessage());
} finally {
closeClientConnectionIfNecessary();
}
}

/**
Expand Down