|
8 | 8 | import io.strimzi.api.kafka.model.common.GenericSecretSource; |
9 | 9 | import io.strimzi.api.kafka.model.common.PasswordSecretSource; |
10 | 10 | import io.strimzi.api.kafka.model.common.authentication.KafkaClientAuthentication; |
| 11 | +import io.strimzi.api.kafka.model.common.authentication.KafkaClientAuthenticationCustom; |
11 | 12 | import io.strimzi.api.kafka.model.common.authentication.KafkaClientAuthenticationOAuth; |
12 | 13 | import io.strimzi.api.kafka.model.common.authentication.KafkaClientAuthenticationPlain; |
13 | 14 | import io.strimzi.api.kafka.model.common.authentication.KafkaClientAuthenticationScram; |
|
24 | 25 | import java.io.StringWriter; |
25 | 26 | import java.util.ArrayList; |
26 | 27 | import java.util.List; |
| 28 | +import java.util.Map; |
27 | 29 | import java.util.stream.Collectors; |
28 | 30 |
|
29 | 31 | import static io.strimzi.operator.cluster.model.KafkaConnectCluster.OAUTH_SECRETS_BASE_VOLUME_MOUNT; |
|
36 | 38 | * configuration file. This class is using the builder pattern to make it easy to test the different parts etc. To |
37 | 39 | * generate the configuration file, it is using the PrintWriter. |
38 | 40 | */ |
| 41 | +@SuppressWarnings("checkstyle:CyclomaticComplexity") |
39 | 42 | public class KafkaConnectConfigurationBuilder { |
40 | 43 | // the volume mounted secret file template includes: <volume_mount>/<secret_name>/<secret_key> |
41 | 44 | private static final String PLACEHOLDER_VOLUME_MOUNTED_SECRET_TEMPLATE_CONFIG_PROVIDER_DIR = "${strimzidir:%s%s:%s}"; |
@@ -148,8 +151,28 @@ public KafkaConnectConfigurationBuilder withAuthentication(KafkaClientAuthentica |
148 | 151 | writer.println("admin.ssl.keystore.certificate.chain=" + certConfigProviderValue); |
149 | 152 | writer.println("admin.ssl.keystore.key=" + keyConfigProviderValue); |
150 | 153 | writer.println("admin.ssl.keystore.type=PEM"); |
151 | | - // otherwise SASL or OAuth is going to be used for authentication |
152 | | - } else { |
| 154 | + } else if (authentication instanceof KafkaClientAuthenticationCustom customAuth) { // Configure custom authentication |
| 155 | + if (customAuth.isSasl()) { |
| 156 | + // If this authentication uses SASL, we need to update the security protocol to combine the SASL |
| 157 | + // flag with the SSL or PLAINTEXT flag. |
| 158 | + securityProtocol = securityProtocol.equals("SSL") ? "SASL_SSL" : "SASL_PLAINTEXT"; |
| 159 | + } |
| 160 | + |
| 161 | + Map<String, Object> customConfig = customAuth.getConfig(); |
| 162 | + if (customConfig == null) { |
| 163 | + customConfig = Map.of(); |
| 164 | + } |
| 165 | + |
| 166 | + KafkaClientAuthenticationCustomConfiguration config = new KafkaClientAuthenticationCustomConfiguration(reconciliation, customConfig.entrySet()); |
| 167 | + config.asOrderedProperties().asMap().forEach((key, value) -> { |
| 168 | + writer.println(String.format("%s=%s", key, value)); |
| 169 | + writer.println(String.format("producer.%s=%s", key, value)); |
| 170 | + writer.println(String.format("consumer.%s=%s", key, value)); |
| 171 | + writer.println(String.format("admin.%s=%s", key, value)); |
| 172 | + }); |
| 173 | + |
| 174 | + writer.println(); |
| 175 | + } else { // otherwise SASL or OAuth is going to be used for authentication |
153 | 176 | securityProtocol = securityProtocol.equals("SSL") ? "SASL_SSL" : "SASL_PLAINTEXT"; |
154 | 177 | String saslMechanism = null; |
155 | 178 | StringBuilder jaasConfig = new StringBuilder(); |
@@ -232,6 +255,7 @@ public KafkaConnectConfigurationBuilder withAuthentication(KafkaClientAuthentica |
232 | 255 | writer.println(); |
233 | 256 | } |
234 | 257 | } |
| 258 | + |
235 | 259 | return this; |
236 | 260 | } |
237 | 261 |
|
|
0 commit comments