use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi-kafka-operator by strimzi.
the class Session method adminClientProperties.
Properties adminClientProperties() {
Properties kafkaClientProps = new Properties();
kafkaClientProps.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, config.get(Config.KAFKA_BOOTSTRAP_SERVERS));
kafkaClientProps.setProperty(StreamsConfig.APPLICATION_ID_CONFIG, config.get(Config.APPLICATION_ID));
String securityProtocol = config.get(Config.SECURITY_PROTOCOL);
boolean tlsEnabled = Boolean.parseBoolean(config.get(Config.TLS_ENABLED));
if (tlsEnabled && !securityProtocol.isEmpty()) {
if (!securityProtocol.equals("SSL") && !securityProtocol.equals("SASL_SSL")) {
throw new InvalidConfigurationException("TLS is enabled but the security protocol does not match SSL or SASL_SSL");
}
}
if (!securityProtocol.isEmpty()) {
kafkaClientProps.setProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, securityProtocol);
} else if (tlsEnabled) {
kafkaClientProps.setProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, "SSL");
} else {
kafkaClientProps.setProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, "PLAINTEXT");
}
if (securityProtocol.equals("SASL_SSL") || securityProtocol.equals("SSL") || tlsEnabled) {
kafkaClientProps.setProperty(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, config.get(Config.TLS_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM));
if (!config.get(Config.TLS_TRUSTSTORE_LOCATION).isEmpty()) {
kafkaClientProps.setProperty(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, config.get(Config.TLS_TRUSTSTORE_LOCATION));
}
if (!config.get(Config.TLS_TRUSTSTORE_PASSWORD).isEmpty()) {
if (config.get(Config.TLS_TRUSTSTORE_LOCATION).isEmpty()) {
throw new InvalidConfigurationException("TLS_TRUSTSTORE_PASSWORD was supplied but TLS_TRUSTSTORE_LOCATION was not supplied");
}
kafkaClientProps.setProperty(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, config.get(Config.TLS_TRUSTSTORE_PASSWORD));
}
if (!config.get(Config.TLS_KEYSTORE_LOCATION).isEmpty() && !config.get(Config.TLS_KEYSTORE_PASSWORD).isEmpty()) {
kafkaClientProps.setProperty(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, config.get(Config.TLS_KEYSTORE_LOCATION));
kafkaClientProps.setProperty(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, config.get(Config.TLS_KEYSTORE_PASSWORD));
}
}
if (Boolean.parseBoolean(config.get(Config.SASL_ENABLED))) {
setSaslConfigs(kafkaClientProps);
}
return kafkaClientProps;
}
Aggregations