0

I am trying to connect to AWS MSK using SASL protocol in a spring boot project. I am using spring-kafka to connect. The error I am getting is

org.apache.kafka.common.KafkaException: javax.security.auth.LoginException: unable to find LoginModule class:software.amazon.msk.auth.iam.IAMLoginModule

Here are my producer config details. I am using the sample program as producer

@Bean
public ProducerFactory<String,String> getProducerFactoryAWS()
{

Thread.currentThread().setContextClassLoader(null);
Map<String,Object> configProps =  new HashMap<>();

configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"XXXX.XXXXX");
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,StringSerializer.class);
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class);
configProps.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG,"SASL_SSL");
configProps.put(Saslconfigs.SASL_MECHANISM,"AWS_MSK_IAM");
configProps.put(Saslconfigs.SASL_CLIENT_CALLBACK_HANDLER_CLASS,"com.xxxx.cto.jade.aws.sdk1.msk.JadeMskClientCallbackHandler");
configProps.put(SaslConfigs.SASL_JAAS_CONFIG,"software.amazon.msk.auth.iam.IAMLoginModule required XXXXXXXX");

return new DefaultKafkaProducerFactory<>(configProps);
}

few dependencies from pom.xml are as below


<dependency>
    <groupId>org.springframework.kafka</groupId>
    <artifactId>spring-kafka</artifactId>
    <version>2.8.9</version>
</dependency>

<dependency>
  <groupId>software.amazon.msk</groupId>
  <artifactId>aws-msk-iam-auth</artifactId>
  <version>1.1.4</version>
</dependency>

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.8.1</version>
</dependency>

I am not able to copy paste entire code due to security concerns. I have gone through unable to find LoginModule class: org.apache.kafka.common.security.plain.PlainLoginModule when the springboot app is run on docker container but not able to understand where to put that code as I am not creating producer by calling constructor in my code. I tried setting below line but still same error.

Thread.currentThread().setContextClassLoader(null);
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

1

My problem is solved after putting below line

Thread.currentThread().setContextClassLoader(this.getClass().getClassloader());

instead of

Thread.currentThread().setContextClassLoader(null);