Search in sources :

Example 26 with InvalidConfigurationException

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;
}
Also used : Properties(java.util.Properties) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException)

Aggregations

InvalidConfigurationException (io.strimzi.operator.common.InvalidConfigurationException)26 ParallelTest (io.strimzi.test.annotations.ParallelTest)10 HashMap (java.util.HashMap)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 Test (org.junit.jupiter.api.Test)8 NoImageException (io.strimzi.operator.cluster.model.NoImageException)4 UnsupportedVersionException (io.strimzi.operator.cluster.model.UnsupportedVersionException)4 Labels (io.strimzi.operator.common.model.Labels)4 KafkaVersion (io.strimzi.operator.cluster.model.KafkaVersion)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2