static void addKerberosJaasConf(Configuration configuration, Properties props) {
    //based on this https://kafka.apache.org/documentation/#security_jaas_client
    props.setProperty("security.protocol", "SASL_PLAINTEXT");
    props.setProperty("sasl.mechanism", "GSSAPI");
    props.setProperty("sasl.kerberos.service.name", "kafka");

    //Construct the principal/keytab
    String principalHost = HiveConf.getVar(configuration, HiveConf.ConfVars.HIVE_SERVER2_KERBEROS_PRINCIPAL);
    String keyTab = HiveConf.getVar(configuration, HiveConf.ConfVars.HIVE_SERVER2_KERBEROS_KEYTAB);
    // back to use LLAP keys if HS2 conf are not set or visible for the Task.
    if (principalHost == null || principalHost.isEmpty() || keyTab == null || keyTab.isEmpty()) {
      keyTab = HiveConf.getVar(configuration, HiveConf.ConfVars.LLAP_FS_KERBEROS_KEYTAB_FILE);
      principalHost = HiveConf.getVar(configuration, HiveConf.ConfVars.LLAP_FS_KERBEROS_PRINCIPAL);
    }

    String principal;
    try {
      principal = SecurityUtil.getServerPrincipal(principalHost, "0.0.0.0");
    } catch (IOException e) {
      log.error("Can not construct kerberos principal", e);
      throw new RuntimeException(e);
    }
    String jaasConf = String.format(JAAS_TEMPLATE, keyTab, principal);
    props.setProperty("sasl.jaas.config", jaasConf);

    if (configuration instanceof JobConf) {
      Credentials creds = ((JobConf) configuration).getCredentials();
      Token<?> token = creds.getToken(KAFKA_DELEGATION_TOKEN_KEY);

      if (token != null) {
        log.info("Kafka delegation token has been found: {}", token);
        props.setProperty("sasl.mechanism", "SCRAM-SHA-256");

        jaasConf = String.format(JAAS_TEMPLATE_SCRAM, new String(token.getIdentifier()),
            Base64.getEncoder().encodeToString(token.getPassword()), token.getService());
        props.setProperty("sasl.jaas.config", jaasConf);
      }
    }
    log.info("Kafka client running with following JAAS = [{}]", jaasConf);
  }
Helper method that add Kerberos Jaas configs to the properties.
@param configuration Hive config containing kerberos key and principal
@param props properties to be populated
kafka-handler/src/java/org/apache/hadoop/hive/kafka/KafkaUtils.java