Skip to content

Commit ec96d17

Browse files
committed
add workaround for property
1 parent 070c027 commit ec96d17

File tree

2 files changed

+90
-83
lines changed

2 files changed

+90
-83
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ KAFKA_MAX_BLOCK_MS=10000
7171

7272
A full list of available configurations can be found in the [official kafka docs](https://kafka.apache.org/documentation/#producerconfigs).
7373

74+
75+
| :warning: WARNING |
76+
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
77+
| Because some environments have difficulties with empty string variables, a workaround for `SSL_ENDPOINT_IDENTIFICATION_ALGORITHM` was implemented. To disable the host name verification set the value to `disabled`. The module will transfer the value to an empty string when creating the kafka client. |
78+
7479
### Kafka client using secure connection
7580
As mentioned above the kafka client can be configured by passing parameters to the start command. To make kafka open a SSL/TLS secured connection you can add the following parameters:
7681

src/main/java/com/github/snuk87/keycloak/kafka/KafkaProducerConfig.java

Lines changed: 85 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,100 +2,102 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5-
65
import org.keycloak.Config.Scope;
76

87
public class KafkaProducerConfig {
98

10-
// https://kafka.apache.org/documentation/#producerconfigs
9+
// https://kafka.apache.org/documentation/#producerconfigs
1110

12-
public static Map<String, Object> init(Scope scope) {
13-
Map<String, Object> propertyMap = new HashMap<>();
14-
KafkaProducerProperty[] producerProperties = KafkaProducerProperty.values();
11+
public static Map<String, Object> init(Scope scope) {
12+
Map<String, Object> propertyMap = new HashMap<>();
13+
KafkaProducerProperty[] producerProperties = KafkaProducerProperty.values();
1514

16-
for (KafkaProducerProperty property : producerProperties) {
17-
String propertyEnv = System.getenv("KAFKA_" + property.name());
15+
for (KafkaProducerProperty property : producerProperties) {
16+
String propertyEnv = System.getenv("KAFKA_" + property.name());
1817

19-
if (property.getName() != null && scope.get(property.getName(), propertyEnv) != null) {
20-
propertyMap.put(property.getName(), scope.get(property.getName(), propertyEnv));
21-
}
22-
}
18+
if (property == KafkaProducerProperty.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM &&
19+
("disabled").equalsIgnoreCase(scope.get(property.getName(), propertyEnv))) {
20+
propertyMap.put(property.getName(), "");
21+
} else if (property.getName() != null && scope.get(property.getName(), propertyEnv) != null) {
22+
propertyMap.put(property.getName(), scope.get(property.getName(), propertyEnv));
23+
}
24+
}
2325

24-
return propertyMap;
25-
}
26+
return propertyMap;
27+
}
2628

27-
enum KafkaProducerProperty {
28-
ACKS("acks"), //
29-
BUFFER_MEMORY("buffer.memory"), //
30-
COMPRESSION_TYPE("compression.type"), //
31-
RETRIES("retries"), //
32-
SSL_KEY_PASSWORD("ssl.key.password"), //
33-
SSL_KEYSTORE_CERTIFICATE_CHAIN("ssl.keystore.certificate.chain"), //
34-
SSL_KEYSTORE_LOCATION("ssl.keystore.location"), //
35-
SSL_KEYSTORE_PASSWORD("ssl.keystore.password"), //
36-
SSL_TRUSTSTORE_LOCATION("ssl.truststore.location"), //
37-
SSL_TRUSTSTORE_PASSWORD("ssl.truststore.password"), //
38-
BATCH_SIZE("batch.size"), //
39-
CLIENT_DNS_LOOKUP("client.dns.lookup"), //
40-
CONNECTION_MAX_IDLE_MS("connections.max.idle.ms"), //
41-
DELIVERY_TIMEOUT_MS("delivery.timeout.ms"), //
42-
LINGER_MS("linger.ms"), //
43-
MAX_BLOCK_MS("max.block.ms"), //
44-
MAX_REQUEST_SIZE("max.request.size"), //
45-
PARTITIONER_CLASS("partitioner.class"), //
46-
RECEIVE_BUFFER_BYTES("receive.buffer.bytes"), //
47-
REQUEST_TIMEOUT_MS("request.timeout.ms"), //
48-
SASL_CLIENT_CALLBACK_HANDLER_CLASS("sasl.client.callback.handler.class"), //
49-
SASL_JAAS_CONFIG("sasl.jaas.config"), //
50-
SASL_KERBEROS_SERVICE_NAME("sasl.kerberos.service.name"), //
51-
SASL_LOGIN_CALLBACK_HANDLER_CLASS("sasl.login.callback.handler.class"), //
52-
SASL_LOGIN_CLASS("sasl.login.class"), //
53-
SASL_MECHANISM("sasl.mechanism"), //
54-
SECURITY_PROTOCOL("security.protocol"), //
55-
SEND_BUFFER_BYTES("send.buffer.bytes"), //
56-
SSL_ENABLED_PROTOCOLS("ssl.enabled.protocols"), //
57-
SSL_KEYSTORE_TYPE("ssl.keystore.type"), //
58-
SSL_PROTOCOL("ssl.protocol"), //
59-
SSL_PROVIDER("ssl.provider"), //
60-
SSL_TRUSTSTORE_TYPE("ssl.truststore.type"), //
61-
ENABLE_IDEMPOTENCE("enable.idempotence"), //
62-
INTERCEPTOR_CLASS("interceptor.classes"), //
63-
MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION("max.in.flight.requests.per.connection"), //
64-
METADATA_MAX_AGE_MS("metadata.max.age.ms"), //
65-
METADATA_MAX_IDLE_MS("metadata.max.idle.ms"), //
66-
METRIC_REPORTERS("metric.reporters"), //
67-
METRIC_NUM_SAMPLES("metrics.num.samples"), //
68-
METRICS_RECORDING_LEVEL("metrics.recording.level"), //
69-
METRICS_SAMPLE_WINDOW_MS("metrics.sample.window.ms"), //
70-
RECONNECT_BACKOFF_MAX_MS("reconnect.backoff.max.ms"), //
71-
RECONNECT_BACKOFF_MS("reconnect.backoff.ms"), //
72-
RETRY_BACKOFF_MS("retry.backoff.ms"), //
73-
SASL_KERBEROS_KINIT_CMD("sasl.kerberos.kinit.cmd"), //
74-
SASL_KERBEROS_MIN_TIME_BEFORE_RELOGIN("sasl.kerberos.min.time.before.relogin"), //
75-
SASL_KERBEROS_TICKET_RENEW_JITTER("sasl.kerberos.ticket.renew.jitter"), //
76-
SASL_KERBEROS_TICKET_RENEW_WINDOW_FACTOR("sasl.kerberos.ticket.renew.window.factor"), //
77-
SASL_LOGIN_REFRESH_BUFFER_SECONDS("sasl.login.refresh.buffer.seconds"), //
78-
SASL_LOGIN_REFRESH_MIN_PERIOD_SECONDS("sasl.login.refresh.min.period.seconds"), //
79-
SASL_LOGIN_REFRESH_WINDOW_FACTOR("sasl.login.refresh.window.factor"), //
80-
SASL_LOGIN_REFRESH_WINDOW_JITTER("sasl.login.refresh.window.jitter"), //
81-
SECURITY_PROVIDERS("security.providers"), //
82-
SSL_CIPHER_SUITES("ssl.cipher.suites"), //
83-
SSL_ENDPOINT_IDENTIFICATION_ALGORITHM("ssl.endpoint.identification.algorithm"), //
84-
SSL_KEYMANAGER_ALGORITHM("ssl.keymanager.algorithm"), //
85-
SSL_SECURE_RANDOM_IMPLEMENTATION("ssl.secure.random.implementation"), //
86-
SSL_TRUSTMANAGER_ALGORITHM("ssl.trustmanager.algorithm"), //
87-
TRANSACTION_TIMEOUT_MS("transaction.timeout.ms"), //
88-
TRANSACTION_ID("transactional.id");
29+
enum KafkaProducerProperty {
30+
ACKS("acks"), //
31+
BUFFER_MEMORY("buffer.memory"), //
32+
COMPRESSION_TYPE("compression.type"), //
33+
RETRIES("retries"), //
34+
SSL_KEY_PASSWORD("ssl.key.password"), //
35+
SSL_KEYSTORE_CERTIFICATE_CHAIN("ssl.keystore.certificate.chain"), //
36+
SSL_KEYSTORE_LOCATION("ssl.keystore.location"), //
37+
SSL_KEYSTORE_PASSWORD("ssl.keystore.password"), //
38+
SSL_TRUSTSTORE_LOCATION("ssl.truststore.location"), //
39+
SSL_TRUSTSTORE_PASSWORD("ssl.truststore.password"), //
40+
BATCH_SIZE("batch.size"), //
41+
CLIENT_DNS_LOOKUP("client.dns.lookup"), //
42+
CONNECTION_MAX_IDLE_MS("connections.max.idle.ms"), //
43+
DELIVERY_TIMEOUT_MS("delivery.timeout.ms"), //
44+
LINGER_MS("linger.ms"), //
45+
MAX_BLOCK_MS("max.block.ms"), //
46+
MAX_REQUEST_SIZE("max.request.size"), //
47+
PARTITIONER_CLASS("partitioner.class"), //
48+
RECEIVE_BUFFER_BYTES("receive.buffer.bytes"), //
49+
REQUEST_TIMEOUT_MS("request.timeout.ms"), //
50+
SASL_CLIENT_CALLBACK_HANDLER_CLASS("sasl.client.callback.handler.class"), //
51+
SASL_JAAS_CONFIG("sasl.jaas.config"), //
52+
SASL_KERBEROS_SERVICE_NAME("sasl.kerberos.service.name"), //
53+
SASL_LOGIN_CALLBACK_HANDLER_CLASS("sasl.login.callback.handler.class"), //
54+
SASL_LOGIN_CLASS("sasl.login.class"), //
55+
SASL_MECHANISM("sasl.mechanism"), //
56+
SECURITY_PROTOCOL("security.protocol"), //
57+
SEND_BUFFER_BYTES("send.buffer.bytes"), //
58+
SSL_ENABLED_PROTOCOLS("ssl.enabled.protocols"), //
59+
SSL_KEYSTORE_TYPE("ssl.keystore.type"), //
60+
SSL_PROTOCOL("ssl.protocol"), //
61+
SSL_PROVIDER("ssl.provider"), //
62+
SSL_TRUSTSTORE_TYPE("ssl.truststore.type"), //
63+
ENABLE_IDEMPOTENCE("enable.idempotence"), //
64+
INTERCEPTOR_CLASS("interceptor.classes"), //
65+
MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION("max.in.flight.requests.per.connection"), //
66+
METADATA_MAX_AGE_MS("metadata.max.age.ms"), //
67+
METADATA_MAX_IDLE_MS("metadata.max.idle.ms"), //
68+
METRIC_REPORTERS("metric.reporters"), //
69+
METRIC_NUM_SAMPLES("metrics.num.samples"), //
70+
METRICS_RECORDING_LEVEL("metrics.recording.level"), //
71+
METRICS_SAMPLE_WINDOW_MS("metrics.sample.window.ms"), //
72+
RECONNECT_BACKOFF_MAX_MS("reconnect.backoff.max.ms"), //
73+
RECONNECT_BACKOFF_MS("reconnect.backoff.ms"), //
74+
RETRY_BACKOFF_MS("retry.backoff.ms"), //
75+
SASL_KERBEROS_KINIT_CMD("sasl.kerberos.kinit.cmd"), //
76+
SASL_KERBEROS_MIN_TIME_BEFORE_RELOGIN("sasl.kerberos.min.time.before.relogin"), //
77+
SASL_KERBEROS_TICKET_RENEW_JITTER("sasl.kerberos.ticket.renew.jitter"), //
78+
SASL_KERBEROS_TICKET_RENEW_WINDOW_FACTOR("sasl.kerberos.ticket.renew.window.factor"), //
79+
SASL_LOGIN_REFRESH_BUFFER_SECONDS("sasl.login.refresh.buffer.seconds"), //
80+
SASL_LOGIN_REFRESH_MIN_PERIOD_SECONDS("sasl.login.refresh.min.period.seconds"), //
81+
SASL_LOGIN_REFRESH_WINDOW_FACTOR("sasl.login.refresh.window.factor"), //
82+
SASL_LOGIN_REFRESH_WINDOW_JITTER("sasl.login.refresh.window.jitter"), //
83+
SECURITY_PROVIDERS("security.providers"), //
84+
SSL_CIPHER_SUITES("ssl.cipher.suites"), //
85+
SSL_ENDPOINT_IDENTIFICATION_ALGORITHM("ssl.endpoint.identification.algorithm"), //
86+
SSL_KEYMANAGER_ALGORITHM("ssl.keymanager.algorithm"), //
87+
SSL_SECURE_RANDOM_IMPLEMENTATION("ssl.secure.random.implementation"), //
88+
SSL_TRUSTMANAGER_ALGORITHM("ssl.trustmanager.algorithm"), //
89+
TRANSACTION_TIMEOUT_MS("transaction.timeout.ms"), //
90+
TRANSACTION_ID("transactional.id");
8991

90-
private String name;
92+
private String name;
9193

92-
private KafkaProducerProperty(String name) {
93-
this.name = name;
94-
}
94+
private KafkaProducerProperty(String name) {
95+
this.name = name;
96+
}
9597

96-
public String getName() {
97-
return name;
98-
}
99-
}
98+
public String getName() {
99+
return name;
100+
}
101+
}
100102

101103
}

0 commit comments

Comments
 (0)