|
|
@ -25,6 +25,7 @@ import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.security.auth.login.AppConfigurationEntry;
|
|
|
|
import javax.security.auth.login.AppConfigurationEntry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.kafka.clients.CommonClientConfigs;
|
|
|
|
import org.apache.kafka.clients.admin.AdminClientConfig;
|
|
|
|
import org.apache.kafka.clients.admin.AdminClientConfig;
|
|
|
|
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
|
|
|
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
|
|
|
import org.apache.kafka.clients.producer.ProducerConfig;
|
|
|
|
import org.apache.kafka.clients.producer.ProducerConfig;
|
|
|
@ -106,6 +107,7 @@ class KafkaAutoConfigurationTests {
|
|
|
|
"spring.kafka.consumer.properties.fiz.buz=fix.fox", "spring.kafka.consumer.fetch-min-size=1KB",
|
|
|
|
"spring.kafka.consumer.properties.fiz.buz=fix.fox", "spring.kafka.consumer.fetch-min-size=1KB",
|
|
|
|
"spring.kafka.consumer.group-id=bar", "spring.kafka.consumer.heartbeat-interval=234",
|
|
|
|
"spring.kafka.consumer.group-id=bar", "spring.kafka.consumer.heartbeat-interval=234",
|
|
|
|
"spring.kafka.consumer.isolation-level = read-committed",
|
|
|
|
"spring.kafka.consumer.isolation-level = read-committed",
|
|
|
|
|
|
|
|
"spring.kafka.consumer.security.protocol = SSL",
|
|
|
|
"spring.kafka.consumer.key-deserializer = org.apache.kafka.common.serialization.LongDeserializer",
|
|
|
|
"spring.kafka.consumer.key-deserializer = org.apache.kafka.common.serialization.LongDeserializer",
|
|
|
|
"spring.kafka.consumer.value-deserializer = org.apache.kafka.common.serialization.IntegerDeserializer")
|
|
|
|
"spring.kafka.consumer.value-deserializer = org.apache.kafka.common.serialization.IntegerDeserializer")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
@ -137,6 +139,7 @@ class KafkaAutoConfigurationTests {
|
|
|
|
assertThat(configs.get(ConsumerConfig.ISOLATION_LEVEL_CONFIG)).isEqualTo("read_committed");
|
|
|
|
assertThat(configs.get(ConsumerConfig.ISOLATION_LEVEL_CONFIG)).isEqualTo("read_committed");
|
|
|
|
assertThat(configs.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG))
|
|
|
|
.isEqualTo(LongDeserializer.class);
|
|
|
|
.isEqualTo(LongDeserializer.class);
|
|
|
|
|
|
|
|
assertThat(configs.get(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG)).isEqualTo("SSL");
|
|
|
|
assertThat(configs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG))
|
|
|
|
.isEqualTo(IntegerDeserializer.class);
|
|
|
|
.isEqualTo(IntegerDeserializer.class);
|
|
|
|
assertThat(configs.get(ConsumerConfig.MAX_POLL_RECORDS_CONFIG)).isEqualTo(42);
|
|
|
|
assertThat(configs.get(ConsumerConfig.MAX_POLL_RECORDS_CONFIG)).isEqualTo(42);
|
|
|
@ -156,7 +159,7 @@ class KafkaAutoConfigurationTests {
|
|
|
|
"spring.kafka.producer.buffer-memory=4KB", "spring.kafka.producer.compression-type=gzip",
|
|
|
|
"spring.kafka.producer.buffer-memory=4KB", "spring.kafka.producer.compression-type=gzip",
|
|
|
|
"spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.LongSerializer",
|
|
|
|
"spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.LongSerializer",
|
|
|
|
"spring.kafka.producer.retries=2", "spring.kafka.producer.properties.fiz.buz=fix.fox",
|
|
|
|
"spring.kafka.producer.retries=2", "spring.kafka.producer.properties.fiz.buz=fix.fox",
|
|
|
|
"spring.kafka.producer.ssl.key-password=p4",
|
|
|
|
"spring.kafka.producer.security.protocol=SSL", "spring.kafka.producer.ssl.key-password=p4",
|
|
|
|
"spring.kafka.producer.ssl.key-store-location=classpath:ksLocP",
|
|
|
|
"spring.kafka.producer.ssl.key-store-location=classpath:ksLocP",
|
|
|
|
"spring.kafka.producer.ssl.key-store-password=p5", "spring.kafka.producer.ssl.key-store-type=PKCS12",
|
|
|
|
"spring.kafka.producer.ssl.key-store-password=p5", "spring.kafka.producer.ssl.key-store-type=PKCS12",
|
|
|
|
"spring.kafka.producer.ssl.trust-store-location=classpath:tsLocP",
|
|
|
|
"spring.kafka.producer.ssl.trust-store-location=classpath:tsLocP",
|
|
|
@ -177,6 +180,7 @@ class KafkaAutoConfigurationTests {
|
|
|
|
assertThat(configs.get(ProducerConfig.BUFFER_MEMORY_CONFIG)).isEqualTo(4096L);
|
|
|
|
assertThat(configs.get(ProducerConfig.BUFFER_MEMORY_CONFIG)).isEqualTo(4096L);
|
|
|
|
assertThat(configs.get(ProducerConfig.COMPRESSION_TYPE_CONFIG)).isEqualTo("gzip");
|
|
|
|
assertThat(configs.get(ProducerConfig.COMPRESSION_TYPE_CONFIG)).isEqualTo("gzip");
|
|
|
|
assertThat(configs.get(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG)).isEqualTo(LongSerializer.class);
|
|
|
|
assertThat(configs.get(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG)).isEqualTo(LongSerializer.class);
|
|
|
|
|
|
|
|
assertThat(configs.get(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG)).isEqualTo("SSL");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p4");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p4");
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
.endsWith(File.separator + "ksLocP");
|
|
|
|
.endsWith(File.separator + "ksLocP");
|
|
|
@ -202,7 +206,7 @@ class KafkaAutoConfigurationTests {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner
|
|
|
|
.withPropertyValues("spring.kafka.clientId=cid", "spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
|
|
|
|
.withPropertyValues("spring.kafka.clientId=cid", "spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
|
|
|
|
"spring.kafka.admin.fail-fast=true", "spring.kafka.admin.properties.fiz.buz=fix.fox",
|
|
|
|
"spring.kafka.admin.fail-fast=true", "spring.kafka.admin.properties.fiz.buz=fix.fox",
|
|
|
|
"spring.kafka.admin.ssl.key-password=p4",
|
|
|
|
"spring.kafka.admin.security.protocol=SSL", "spring.kafka.admin.ssl.key-password=p4",
|
|
|
|
"spring.kafka.admin.ssl.key-store-location=classpath:ksLocP",
|
|
|
|
"spring.kafka.admin.ssl.key-store-location=classpath:ksLocP",
|
|
|
|
"spring.kafka.admin.ssl.key-store-password=p5", "spring.kafka.admin.ssl.key-store-type=PKCS12",
|
|
|
|
"spring.kafka.admin.ssl.key-store-password=p5", "spring.kafka.admin.ssl.key-store-type=PKCS12",
|
|
|
|
"spring.kafka.admin.ssl.trust-store-location=classpath:tsLocP",
|
|
|
|
"spring.kafka.admin.ssl.trust-store-location=classpath:tsLocP",
|
|
|
@ -214,6 +218,7 @@ class KafkaAutoConfigurationTests {
|
|
|
|
// common
|
|
|
|
// common
|
|
|
|
assertThat(configs.get(AdminClientConfig.CLIENT_ID_CONFIG)).isEqualTo("cid");
|
|
|
|
assertThat(configs.get(AdminClientConfig.CLIENT_ID_CONFIG)).isEqualTo("cid");
|
|
|
|
// admin
|
|
|
|
// admin
|
|
|
|
|
|
|
|
assertThat(configs.get(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG)).isEqualTo("SSL");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p4");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p4");
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
.endsWith(File.separator + "ksLocP");
|
|
|
|
.endsWith(File.separator + "ksLocP");
|
|
|
@ -240,7 +245,7 @@ class KafkaAutoConfigurationTests {
|
|
|
|
"spring.kafka.streams.auto-startup=false", "spring.kafka.streams.cache-max-size-buffering=1KB",
|
|
|
|
"spring.kafka.streams.auto-startup=false", "spring.kafka.streams.cache-max-size-buffering=1KB",
|
|
|
|
"spring.kafka.streams.client-id=override", "spring.kafka.streams.properties.fiz.buz=fix.fox",
|
|
|
|
"spring.kafka.streams.client-id=override", "spring.kafka.streams.properties.fiz.buz=fix.fox",
|
|
|
|
"spring.kafka.streams.replication-factor=2", "spring.kafka.streams.state-dir=/tmp/state",
|
|
|
|
"spring.kafka.streams.replication-factor=2", "spring.kafka.streams.state-dir=/tmp/state",
|
|
|
|
"spring.kafka.streams.ssl.key-password=p7",
|
|
|
|
"spring.kafka.streams.security.protocol=SSL", "spring.kafka.streams.ssl.key-password=p7",
|
|
|
|
"spring.kafka.streams.ssl.key-store-location=classpath:ksLocP",
|
|
|
|
"spring.kafka.streams.ssl.key-store-location=classpath:ksLocP",
|
|
|
|
"spring.kafka.streams.ssl.key-store-password=p8", "spring.kafka.streams.ssl.key-store-type=PKCS12",
|
|
|
|
"spring.kafka.streams.ssl.key-store-password=p8", "spring.kafka.streams.ssl.key-store-type=PKCS12",
|
|
|
|
"spring.kafka.streams.ssl.trust-store-location=classpath:tsLocP",
|
|
|
|
"spring.kafka.streams.ssl.trust-store-location=classpath:tsLocP",
|
|
|
@ -255,6 +260,7 @@ class KafkaAutoConfigurationTests {
|
|
|
|
assertThat(configs.get(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG)).isEqualTo(1024);
|
|
|
|
assertThat(configs.get(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG)).isEqualTo(1024);
|
|
|
|
assertThat(configs.get(StreamsConfig.CLIENT_ID_CONFIG)).isEqualTo("override");
|
|
|
|
assertThat(configs.get(StreamsConfig.CLIENT_ID_CONFIG)).isEqualTo("override");
|
|
|
|
assertThat(configs.get(StreamsConfig.REPLICATION_FACTOR_CONFIG)).isEqualTo(2);
|
|
|
|
assertThat(configs.get(StreamsConfig.REPLICATION_FACTOR_CONFIG)).isEqualTo(2);
|
|
|
|
|
|
|
|
assertThat(configs.get(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG)).isEqualTo("SSL");
|
|
|
|
assertThat(configs.get(StreamsConfig.STATE_DIR_CONFIG)).isEqualTo("/tmp/state");
|
|
|
|
assertThat(configs.get(StreamsConfig.STATE_DIR_CONFIG)).isEqualTo("/tmp/state");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p7");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p7");
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
@ -569,6 +575,20 @@ class KafkaAutoConfigurationTests {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void specificSecurityProtocolOverridesCommonSecurityProtocol() {
|
|
|
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.kafka.security.protocol=SSL",
|
|
|
|
|
|
|
|
"spring.kafka.admin.security.protocol=PLAINTEXT").run((context) -> {
|
|
|
|
|
|
|
|
DefaultKafkaProducerFactory<?, ?> producerFactory = context
|
|
|
|
|
|
|
|
.getBean(DefaultKafkaProducerFactory.class);
|
|
|
|
|
|
|
|
Map<String, Object> producerConfigs = producerFactory.getConfigurationProperties();
|
|
|
|
|
|
|
|
assertThat(producerConfigs.get(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG)).isEqualTo("SSL");
|
|
|
|
|
|
|
|
KafkaAdmin admin = context.getBean(KafkaAdmin.class);
|
|
|
|
|
|
|
|
Map<String, Object> configs = admin.getConfig();
|
|
|
|
|
|
|
|
assertThat(configs.get(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG)).isEqualTo("PLAINTEXT");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
static class MessageConverterConfiguration {
|
|
|
|
static class MessageConverterConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|