Search in sources :

Example 6 with SaslAuthenticationException

use of org.apache.kafka.common.errors.SaslAuthenticationException in project apache-kafka-on-k8s by banzaicloud.

the class ClientAuthenticationFailureTest method testAdminClientWithInvalidCredentials.

@Test
public void testAdminClientWithInvalidCredentials() {
    Map<String, Object> props = new HashMap<>(saslClientConfigs);
    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:" + server.port());
    try (AdminClient client = AdminClient.create(props)) {
        DescribeTopicsResult result = client.describeTopics(Collections.singleton("test"));
        result.all().get();
        fail("Expected an authentication error!");
    } catch (Exception e) {
        assertTrue("Expected SaslAuthenticationException, got " + e.getCause().getClass(), e.getCause() instanceof SaslAuthenticationException);
    }
}
Also used : HashMap(java.util.HashMap) DescribeTopicsResult(org.apache.kafka.clients.admin.DescribeTopicsResult) SaslAuthenticationException(org.apache.kafka.common.errors.SaslAuthenticationException) SaslAuthenticationException(org.apache.kafka.common.errors.SaslAuthenticationException) AdminClient(org.apache.kafka.clients.admin.AdminClient) Test(org.junit.Test)

Example 7 with SaslAuthenticationException

use of org.apache.kafka.common.errors.SaslAuthenticationException in project apache-kafka-on-k8s by banzaicloud.

the class ClientAuthenticationFailureTest method testTransactionalProducerWithInvalidCredentials.

@Test
public void testTransactionalProducerWithInvalidCredentials() throws Exception {
    Map<String, Object> props = new HashMap<>(saslClientConfigs);
    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:" + server.port());
    props.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "txclient-1");
    props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true");
    StringSerializer serializer = new StringSerializer();
    try (KafkaProducer<String, String> producer = new KafkaProducer<>(props, serializer, serializer)) {
        producer.initTransactions();
        fail("Expected an authentication error!");
    } catch (SaslAuthenticationException e) {
    // expected exception
    }
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) HashMap(java.util.HashMap) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) SaslAuthenticationException(org.apache.kafka.common.errors.SaslAuthenticationException) Test(org.junit.Test)

Example 8 with SaslAuthenticationException

use of org.apache.kafka.common.errors.SaslAuthenticationException in project apache-kafka-on-k8s by banzaicloud.

the class SaslAuthenticatorTest method createAndCheckClientAuthenticationFailure.

private void createAndCheckClientAuthenticationFailure(SecurityProtocol securityProtocol, String node, String mechanism, String expectedErrorMessage) throws Exception {
    ChannelState finalState = createAndCheckClientConnectionFailure(securityProtocol, node);
    Exception exception = finalState.exception();
    assertTrue("Invalid exception class " + exception.getClass(), exception instanceof SaslAuthenticationException);
    if (expectedErrorMessage == null)
        expectedErrorMessage = "Authentication failed due to invalid credentials with SASL mechanism " + mechanism;
    assertEquals(expectedErrorMessage, exception.getMessage());
}
Also used : ChannelState(org.apache.kafka.common.network.ChannelState) SaslAuthenticationException(org.apache.kafka.common.errors.SaslAuthenticationException) KafkaException(org.apache.kafka.common.KafkaException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SaslAuthenticationException(org.apache.kafka.common.errors.SaslAuthenticationException) IOException(java.io.IOException)

Aggregations

SaslAuthenticationException (org.apache.kafka.common.errors.SaslAuthenticationException)8 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 SaslException (javax.security.sasl.SaslException)3 IOException (java.io.IOException)2 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)2 IllegalSaslStateException (org.apache.kafka.common.errors.IllegalSaslStateException)2 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ByteBuffer (java.nio.ByteBuffer)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NameCallback (javax.security.auth.callback.NameCallback)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 AdminClient (org.apache.kafka.clients.admin.AdminClient)1 DescribeTopicsResult (org.apache.kafka.clients.admin.DescribeTopicsResult)1 KafkaConsumer (org.apache.kafka.clients.consumer.KafkaConsumer)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 KafkaException (org.apache.kafka.common.KafkaException)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1