Skip to content

Commit 60fb663

Browse files
author
EmmanuelDuru
committed
Upgrade ES 2 (SSL)
1 parent eae2dd6 commit 60fb663

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

elasticsearch-mapping/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
<groupId>org.elasticsearch</groupId>
1717
<artifactId>elasticsearch</artifactId>
1818
</dependency>
19+
<dependency>
20+
<groupId>com.floragunn</groupId>
21+
<artifactId>search-guard-ssl</artifactId>
22+
<version>${search-guard.version}</version>
23+
</dependency>
1924
<dependency>
2025
<groupId>net.java.dev.jna</groupId>
2126
<artifactId>jna</artifactId>

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/ElasticSearchClient.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import org.springframework.beans.factory.annotation.Value;
2222
import org.springframework.stereotype.Component;
2323

24+
import com.floragunn.searchguard.ssl.SearchGuardSSLPlugin;
25+
import com.floragunn.searchguard.ssl.util.SSLConfigConstants;
26+
2427
/**
2528
* Prepare the node to work with elastic search.
2629
*
@@ -39,15 +42,31 @@ public class ElasticSearchClient {
3942
private String clusterName;
4043
private boolean resetData = false;
4144
private Client client;
45+
private boolean transportSSL = false;
46+
private String keystore = null;
47+
private String truststore = null;
48+
private String keystorePassword = null;
49+
private String truststorePassword = null;
4250

4351
@PostConstruct
4452
public void initialize() {
4553
if (this.isClient && this.isTransportClient) {
4654
// when these both option are set, we use a transport client
47-
Settings settings = Settings.settingsBuilder()
48-
.put("cluster.name", this.clusterName)
49-
.build();
50-
TransportClient transportClient = TransportClient.builder().settings(settings).build();
55+
Settings.Builder settingsBuilder = Settings.settingsBuilder()
56+
.put("cluster.name", this.clusterName);
57+
if (transportSSL) {
58+
settingsBuilder = settingsBuilder
59+
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_FILEPATH, this.keystore)
60+
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_TRUSTSTORE_FILEPATH, this.truststore)
61+
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_PASSWORD, this.keystorePassword)
62+
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_TRUSTSTORE_PASSWORD, this.truststorePassword);
63+
}
64+
Settings settings = settingsBuilder.build();
65+
TransportClient.Builder transportClientBuilder = TransportClient.builder().settings(settings);
66+
if (transportSSL) {
67+
transportClientBuilder = transportClientBuilder.addPlugin(SearchGuardSSLPlugin.class);
68+
}
69+
TransportClient transportClient = transportClientBuilder.build();
5170
for (InetSocketTransportAddress add : adresses) {
5271
transportClient.addTransportAddress(add);
5372
}
@@ -137,4 +156,32 @@ public void setHosts(final String hosts) {
137156
public void setResetData(final boolean resetData) {
138157
this.resetData = resetData;
139158
}
159+
160+
@Value("#{elasticsearchConfig['searchguard.ssl.transport.enabled']}")
161+
public void setTransportSSL(Boolean transportSSL) {
162+
if (transportSSL != null) {
163+
this.transportSSL = transportSSL.booleanValue();
164+
}
165+
}
166+
167+
@Value("#{elasticsearchConfig['searchguard.ssl.transport.keystore_filepath']}")
168+
public void setKeystore(final String keystore) {
169+
this.keystore = keystore;
170+
}
171+
172+
@Value("#{elasticsearchConfig['searchguard.ssl.transport.truststore_filepath']}")
173+
public void setTruststore(final String truststore) {
174+
this.truststore = truststore;
175+
}
176+
177+
@Value("#{elasticsearchConfig['searchguard.ssl.transport.keystore_password']}")
178+
public void setKeystorePassword(final String password) {
179+
this.keystorePassword = password;
180+
}
181+
182+
@Value("#{elasticsearchConfig['searchguard.ssl.transport.truststore_password']}")
183+
public void setTruststorePassword(final String password) {
184+
this.truststorePassword = password;
185+
}
186+
140187
}

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
<properties>
1313
<elasticsearch.version>2.4.6</elasticsearch.version>
14+
<search-guard.version>2.4.6.21</search-guard.version>
15+
1416
<jackson.version>2.9.3</jackson.version>
1517
<spring.version>4.3.2.RELEASE</spring.version>
1618
<commons-lang.version>3.5</commons-lang.version>

0 commit comments

Comments
 (0)