|
@@ -18,6 +18,7 @@ import io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider;
|
|
|
import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
|
|
|
import io.confluent.kafka.schemaregistry.client.SchemaMetadata;
|
|
|
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
|
|
|
+import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig;
|
|
|
import io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException;
|
|
|
import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider;
|
|
|
import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema;
|
|
@@ -32,6 +33,7 @@ import java.util.concurrent.Callable;
|
|
|
import javax.annotation.Nullable;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
+import org.apache.kafka.common.config.SslConfigs;
|
|
|
|
|
|
|
|
|
public class SchemaRegistrySerde implements BuiltInSerde {
|
|
@@ -72,7 +74,20 @@ public class SchemaRegistrySerde implements BuiltInSerde {
|
|
|
.orElse(null),
|
|
|
serdeProperties.getProperty("password", String.class)
|
|
|
.or(() -> kafkaClusterProperties.getProperty("schemaRegistryAuth.password", String.class))
|
|
|
- .orElse(null)
|
|
|
+ .orElse(null),
|
|
|
+
|
|
|
+ serdeProperties.getProperty("keystoreLocation", String.class)
|
|
|
+ .or(() -> kafkaClusterProperties.getProperty("schemaRegistrySSL.keystoreLocation", String.class))
|
|
|
+ .orElse(null),
|
|
|
+ serdeProperties.getProperty("keystorePassword", String.class)
|
|
|
+ .or(() -> kafkaClusterProperties.getProperty("schemaRegistrySSL.keystorePassword", String.class))
|
|
|
+ .orElse(null),
|
|
|
+ serdeProperties.getProperty("truststoreLocation", String.class)
|
|
|
+ .or(() -> kafkaClusterProperties.getProperty("schemaRegistrySSL.truststoreLocation", String.class))
|
|
|
+ .orElse(null),
|
|
|
+ serdeProperties.getProperty("truststorePassword", String.class)
|
|
|
+ .or(() -> kafkaClusterProperties.getProperty("schemaRegistrySSL.truststorePassword", String.class))
|
|
|
+ .orElse(null)
|
|
|
),
|
|
|
serdeProperties.getProperty("keySchemaNameTemplate", String.class)
|
|
|
.or(() -> kafkaClusterProperties.getProperty("keySchemaNameTemplate", String.class))
|
|
@@ -98,7 +113,12 @@ public class SchemaRegistrySerde implements BuiltInSerde {
|
|
|
|
|
|
private static SchemaRegistryClient createSchemaRegistryClient(List<String> urls,
|
|
|
@Nullable String username,
|
|
|
- @Nullable String password) {
|
|
|
+ @Nullable String password,
|
|
|
+ @Nullable String keyStoreLocation,
|
|
|
+ @Nullable String keyStorePassword,
|
|
|
+ @Nullable String trustStoreLocation,
|
|
|
+ @Nullable String trustStorePassword
|
|
|
+ ) {
|
|
|
Map<String, String> configs = new HashMap<>();
|
|
|
if (username != null && password != null) {
|
|
|
configs.put(BASIC_AUTH_CREDENTIALS_SOURCE, "USER_INFO");
|
|
@@ -110,6 +130,24 @@ public class SchemaRegistrySerde implements BuiltInSerde {
|
|
|
throw new ValidationException(
|
|
|
"You specified password but do not specified username");
|
|
|
}
|
|
|
+
|
|
|
+ // We require at least a truststore. The logic is done similar to SchemaRegistryService.securedWebClientOnTLS
|
|
|
+ if (trustStoreLocation != null && trustStorePassword != null) {
|
|
|
+ configs.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG,
|
|
|
+ trustStoreLocation);
|
|
|
+ configs.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG,
|
|
|
+ trustStorePassword);
|
|
|
+
|
|
|
+ if (keyStoreLocation != null) {
|
|
|
+ configs.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG,
|
|
|
+ keyStoreLocation);
|
|
|
+ configs.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG,
|
|
|
+ keyStorePassword);
|
|
|
+ configs.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SslConfigs.SSL_KEY_PASSWORD_CONFIG,
|
|
|
+ keyStorePassword);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return new CachedSchemaRegistryClient(
|
|
|
urls,
|
|
|
1_000,
|