简体   繁体   English

如何添加用户身份验证配置

[英]How to add user authentication configs

I am confused how to add authentication credentials progrmatically.我很困惑如何以编程方式添加身份验证凭据。 Not sure if SECURITY_PROVIDERS_CONFIG is where I set these values.不确定 SECURITY_PROVIDERS_CONFIG 是否是我设置这些值的地方。 Was also going through the constants and I could see many configs have _DOC and I am curious what does it mean.也在检查常量,我可以看到许多配置都有 _DOC,我很好奇它是什么意思。 For example SECURITY_PROVIDERS_CONFIG and SECURITY_PROVIDERS_DOC.例如 SECURITY_PROVIDERS_CONFIG 和 SECURITY_PROVIDERS_DOC。

Here is my config class:这是我的配置 class:

@Configuration
public class KafkaProducerConfig {
    @Value(value = "${spring.kafka.bootstrap-servers}")
    private String bootstrapAddress;

    @Bean
    public ProducerFactory<String, String> producerFactory() {
        Map<String, Object> configProps = new HashMap<>();
        configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
        configProps.put(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG, CountingProducerInterceptor.class.getName());
        configProps.put(ProducerConfig.ACKS_CONFIG, "all");
        configProps.put(ProducerConfig.ENABLE_IDEMPOTENCE_DOC, "true");
        configProps.put(ProducerConfig.RETRIES_CONFIG, 3);
        //configProps.put(ProducerConfig.SECURITY_PROVIDERS_CONFIG, "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"username\" password=\"pa$$wrd\"");
        configProps.put(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, 5);
        configProps.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, 10000);
        configProps.put(ProducerConfig.RETRY_BACKOFF_MS_CONFIG, 3000);
        configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
        return new DefaultKafkaProducerFactory<>(configProps);
    }

    @Bean
    public KafkaTemplate<String, String> kafkaTemplate() {
        return new KafkaTemplate<>(producerFactory());
    }
}

I have commented out the property that I am confused.我已经注释掉了我感到困惑的属性。 Not sure if this ishow you pass username and password.不确定这是否显示您传递用户名和密码。 Thanks in advance.提前致谢。

It is not necessary to have an authentication for you Kafka server.没有必要为您的 Kafka 服务器进行身份验证。 Consider that you can containerize your Kafka instance in your server and you are not forced to expose your ports out of your physical server and your applications will communicate internally (eg: using your docker.network inside the server).考虑到您可以将您的 Kafka 实例容器化在您的服务器中,并且您不会被迫将您的端口暴露在您的物理服务器之外并且您的应用程序将在内部进行通信(例如:在服务器内部使用您的 docker.network)。

But if you wish to implement an authentication for your Kafka server, It is also possible to have both SSL or Plain authentication!!但是,如果您希望为您的 Kafka 服务器实施身份验证,也可以同时拥有 SSL 或普通身份验证!

Here I found an useful answer that may be useful for you too:在这里,我找到了一个可能对您也有用的有用答案:

kafka Authentication卡夫卡认证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM