blog.csdn.net_wulantian_article_details_42418231.png最近工作当中用到kerberos,了解了一下,设计的还是非常巧妙的。本来想自己写,但里面太绕了,直接附上一篇写的比较不错的博客(地址:https://blog.csdn.net/wulantian/article/details/42418231)
如果链接失效可以直接看下图
自己搭建kerberos
这块容我改天有空的时候,弄过再写
接入kerberos
- kafka
Properties props = new Properties();
props.put("bootstrap.servers", ConfUtil.get("brokers"));
props.put("group.id", "test");
props.put("client.id", "test");
props.put("fetch.max.bytes", 1024);// 为了便于测试,这里设置一次fetch 请求取得的数据最大值为1KB,默认是5MB
props.put("enable.auto.commit", false);// 设置手动提交偏移量
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
if ("open".equals(ConfUtil.get("krb5.switch"))) {
System.setProperty("java.security.auth.login.config", ConfUtil.get("jaas.conf.path"));
System.setProperty("java.security.krb5.conf", ConfUtil.get("krb5.conf.path"));
System.setProperty("javax.security.auth.useSubjectCredsOnly", "true");
System.setProperty("sun.security.krb5.debug", "false");
props.put("security.protocol", "SASL_PLAINTEXT");
//properties.put(SECURITY_PROTOCOL, "SASL_PLAINTEXT");
//properties.put("sasl.mechanism", "GSSAPI");
System.out.println("安全认证开启,设置认证参数,files" + ConfUtil.get("jaas.conf.path") + " " + ConfUtil.get("krb5.conf.path"));
}
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
...
其他的都一样
网友评论