Kafka Client配置JAAS(用户密码)的几种方式 实测记录

tech2025-10-23  3

实现用户密码登录的三种方式

 如果是写一个方法测试是否连接上,使用第一种方式;第二种方式会把文件缓存,必须重启程序才会生效。

 

1  直接输入用户密码

   每次可以根据输入的用户密码进行登录

props.put("sasl.mechanism", "PLAIN"); props.put("security.protocol", "SASL_PLAINTEXT"); props.put("sasl.jaas.config","org.apache.kafka.common.security.plain.PlainLoginModule required username=\"producer\" password=\"prod-test\";");

2  加载配置文件

   修改文件后,要重启程序

props.put("sasl.mechanism", "PLAIN"); props.put("security.protocol", "SASL_PLAINTEXT"); System.setProperty("java.security.auth.login.config", "‪E:\desktop\kafka_client_jaas.conf");

 

3 加入到程序启动参数中

java -jar -Djava.security.auth.login.config=D:/kafka_client_jaas.conf xxxx.jar //指定绝对路径

 

最新回复(0)