title: How to pass user name and password to KafkaConsumer?
body: <p>I can't find how to pass user name and password to KafkaConsumer. I use SASL PLAINTEXT to authenticate client on Kafka server.</p>
  
  <p>I tried to find this info on <a href="https://kafka.apache.org/documentation/#consumerconfigs" rel="nofollow noreferrer">https://kafka.apache.org/documentation/#consumerconfigs</a>
  but a result was negative.</p>
  
  <p>I found some example where an author used params "username" and "password". I tried to do this:</p>
  
  <pre><code>props.put("bootstrap.servers", uri.getHost() + ":" + uri.getPort());
  if (!groupidName.isBlank())
      props.put("group.id", groupidName);
  props.put("enable.auto.commit", "false");
  props.put("auto.offset.reset", groupidName.isBlank() ? "latest" : "earliest");
  props.put("session.timeout.ms", "30000");
  props.put("max.poll.records", "1");
  props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
  props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
  if (kafkaConnector.getConfig().getUserName() != null &amp;&amp; kafkaConnector.getConfig().getPassword() != null)
  {
      props.put("security.protocol","SASL_PLAINTEXT");
      props.put("sasl.mechanism","PLAIN");
      props.put("username",kafkaConnector.getConfig().getUserName());
      props.put("password",kafkaConnector.getConfig().getPassword());
  }
  </code></pre>
  
  <p>but i got the exception "Failed to construct kafka consumer".</p>
  
  <p>If someone knows how to pass user name and password to consumer configuration, please help.</p>