Skip to content

Commit

Permalink
add support for relative keystore/truststore paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin-w151 committed Sep 8, 2020
1 parent 51f6c17 commit 34ab806
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/main/java/at/esque/kafka/handlers/ConfigHandler.java
Expand Up @@ -182,17 +182,35 @@ public Map<String, String> getSslProperties(ClusterConfig config) {
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL");
}
if (StringUtils.isNotEmpty(config.getKeyStoreLocation())) {
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, config.getKeyStoreLocation());
}
if (StringUtils.isNotEmpty(config.getKeyStorePassword())) {
props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, config.getKeyStorePassword());
String keyStoreLocation = getJksStoreLocation(config.getIdentifier(), config.getKeyStoreLocation());
if (keyStoreLocation != null) {
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, keyStoreLocation);
if (StringUtils.isNotEmpty(config.getKeyStorePassword())) {
props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, config.getKeyStorePassword());
}
}
}
if (StringUtils.isNotEmpty(config.getTrustStoreLocation())) {
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, config.getTrustStoreLocation());
}
if (StringUtils.isNotEmpty(config.getTrustStorePassword())) {
props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, config.getTrustStorePassword());
String trustStoreLocation = getJksStoreLocation(config.getIdentifier(), config.getTrustStoreLocation());
if (trustStoreLocation != null) {
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, trustStoreLocation);
if (StringUtils.isNotEmpty(config.getTrustStorePassword())) {
props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, config.getTrustStorePassword());
}
}
}
return props;
}

private String getJksStoreLocation(String clusterIdentification, String location) {
File jksStore = new File(location);
if (jksStore.exists() && jksStore.isFile()) {
return location;
}
jksStore = new File(String.format(CONFIG_DIRECTORY, clusterIdentification), location);
if (jksStore.exists() && jksStore.isFile()) {
return jksStore.getAbsolutePath();
}
return null;
}
}

0 comments on commit 34ab806

Please sign in to comment.