Add SSL service connection support for ElasticSearch
See gh-41137
This commit is contained in:
parent
7cf9cc74a2
commit
789d30deab
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -21,6 +21,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
|
||||
/**
|
||||
* Details required to establish a connection to an Elasticsearch service.
|
||||
@ -63,6 +64,15 @@ public interface ElasticsearchConnectionDetails extends ConnectionDetails {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* SSL bundle to use.
|
||||
* @return the SSL bundle to use
|
||||
* @since 3.5.0
|
||||
*/
|
||||
default SslBundle getSslBundle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* An Elasticsearch node.
|
||||
*
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -44,12 +44,14 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails.Node;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails.Node.Protocol;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchProperties.Restclient.Ssl;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.boot.ssl.SslBundles;
|
||||
import org.springframework.boot.ssl.SslOptions;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@ -75,8 +77,8 @@ class ElasticsearchRestClientConfigurations {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(ElasticsearchConnectionDetails.class)
|
||||
PropertiesElasticsearchConnectionDetails elasticsearchConnectionDetails() {
|
||||
return new PropertiesElasticsearchConnectionDetails(this.properties);
|
||||
PropertiesElasticsearchConnectionDetails elasticsearchConnectionDetails(ObjectProvider<SslBundles> sslBundles) {
|
||||
return new PropertiesElasticsearchConnectionDetails(this.properties, sslBundles.getIfAvailable());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ -87,16 +89,16 @@ class ElasticsearchRestClientConfigurations {
|
||||
|
||||
@Bean
|
||||
RestClientBuilder elasticsearchRestClientBuilder(ElasticsearchConnectionDetails connectionDetails,
|
||||
ObjectProvider<RestClientBuilderCustomizer> builderCustomizers, ObjectProvider<SslBundles> sslBundles) {
|
||||
ObjectProvider<RestClientBuilderCustomizer> builderCustomizers) {
|
||||
RestClientBuilder builder = RestClient.builder(connectionDetails.getNodes()
|
||||
.stream()
|
||||
.map((node) -> new HttpHost(node.hostname(), node.port(), node.protocol().getScheme()))
|
||||
.toArray(HttpHost[]::new));
|
||||
builder.setHttpClientConfigCallback((httpClientBuilder) -> {
|
||||
builderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(httpClientBuilder));
|
||||
String sslBundleName = this.properties.getRestclient().getSsl().getBundle();
|
||||
if (StringUtils.hasText(sslBundleName)) {
|
||||
configureSsl(httpClientBuilder, sslBundles.getObject().getBundle(sslBundleName));
|
||||
SslBundle sslBundle = connectionDetails.getSslBundle();
|
||||
if (sslBundle != null) {
|
||||
configureSsl(httpClientBuilder, sslBundle);
|
||||
}
|
||||
return httpClientBuilder;
|
||||
});
|
||||
@ -236,8 +238,11 @@ class ElasticsearchRestClientConfigurations {
|
||||
|
||||
private final ElasticsearchProperties properties;
|
||||
|
||||
PropertiesElasticsearchConnectionDetails(ElasticsearchProperties properties) {
|
||||
private final SslBundles sslBundles;
|
||||
|
||||
PropertiesElasticsearchConnectionDetails(ElasticsearchProperties properties, SslBundles sslBundles) {
|
||||
this.properties = properties;
|
||||
this.sslBundles = sslBundles;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -260,6 +265,16 @@ class ElasticsearchRestClientConfigurations {
|
||||
return this.properties.getPathPrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SslBundle getSslBundle() {
|
||||
Ssl ssl = this.properties.getRestclient().getSsl();
|
||||
if (StringUtils.hasLength(ssl.getBundle())) {
|
||||
Assert.notNull(this.sslBundles, "SSL bundle name has been set but no SSL bundles found in context");
|
||||
return this.sslBundles.getBundle(ssl.getBundle());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Node createNode(String uri) {
|
||||
if (!(uri.startsWith("http://") || uri.startsWith("https://"))) {
|
||||
uri = "http://" + uri;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -16,15 +16,26 @@
|
||||
|
||||
package org.springframework.boot.testcontainers.service.connection.elasticsearch;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.util.List;
|
||||
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails.Node.Protocol;
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.boot.ssl.SslStoreBundle;
|
||||
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactory;
|
||||
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionSource;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.boot.testcontainers.service.connection.Ssl;
|
||||
|
||||
/**
|
||||
* {@link ContainerConnectionDetailsFactory} to create
|
||||
@ -53,15 +64,83 @@ class ElasticsearchContainerConnectionDetailsFactory
|
||||
private static final class ElasticsearchContainerConnectionDetails
|
||||
extends ContainerConnectionDetails<ElasticsearchContainer> implements ElasticsearchConnectionDetails {
|
||||
|
||||
private volatile SslBundle sslBundle;
|
||||
|
||||
private ElasticsearchContainerConnectionDetails(ContainerConnectionSource<ElasticsearchContainer> source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return "elastic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return getContainer().getEnvMap().get("ELASTIC_PASSWORD");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Node> getNodes() {
|
||||
String host = getContainer().getHost();
|
||||
Integer port = getContainer().getMappedPort(DEFAULT_PORT);
|
||||
return List.of(new Node(host, port, Protocol.HTTP, null, null));
|
||||
return List.of(new Node(host, port, (getSslBundle() != null) ? Protocol.HTTPS : Protocol.HTTP,
|
||||
getUsername(), getPassword()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SslBundle getSslBundle() {
|
||||
if (this.sslBundle != null) {
|
||||
return this.sslBundle;
|
||||
}
|
||||
SslBundle sslBundle = super.getSslBundle();
|
||||
if (sslBundle != null) {
|
||||
this.sslBundle = sslBundle;
|
||||
return sslBundle;
|
||||
}
|
||||
if (hasAnnotation(Ssl.class)) {
|
||||
byte[] caCertificate = getContainer().caCertAsBytes().orElse(null);
|
||||
if (caCertificate != null) {
|
||||
KeyStore trustStore = createTrustStore(caCertificate);
|
||||
sslBundle = createSslBundleWithTrustStore(trustStore);
|
||||
this.sslBundle = sslBundle;
|
||||
return sslBundle;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private SslBundle createSslBundleWithTrustStore(KeyStore trustStore) {
|
||||
return SslBundle.of(new SslStoreBundle() {
|
||||
@Override
|
||||
public KeyStore getKeyStore() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyStorePassword() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyStore getTrustStore() {
|
||||
return trustStore;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private KeyStore createTrustStore(byte[] caCertificate) {
|
||||
try {
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(null, null);
|
||||
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
|
||||
Certificate certificate = certFactory.generateCertificate(new ByteArrayInputStream(caCertificate));
|
||||
keyStore.setCertificateEntry("ca", certificate);
|
||||
return keyStore;
|
||||
}
|
||||
catch (KeyStoreException | CertificateException | IOException | NoSuchAlgorithmException ex) {
|
||||
throw new IllegalStateException("Failed to create keystore from CA certificate", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
plugins {
|
||||
id "java"
|
||||
id "org.springframework.boot.conventions"
|
||||
id "org.springframework.boot.docker-test"
|
||||
}
|
||||
|
||||
description = "Spring Boot Data ElasticSearch smoke test"
|
||||
|
||||
dependencies {
|
||||
dockerTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
|
||||
dockerTestImplementation(project(":spring-boot-project:spring-boot-test"))
|
||||
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support-docker"))
|
||||
dockerTestImplementation(project(":spring-boot-project:spring-boot-testcontainers"))
|
||||
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
|
||||
dockerTestImplementation("org.junit.platform:junit-platform-engine")
|
||||
dockerTestImplementation("org.junit.platform:junit-platform-launcher")
|
||||
dockerTestImplementation("org.testcontainers:junit-jupiter")
|
||||
dockerTestImplementation("org.testcontainers:elasticsearch")
|
||||
dockerTestImplementation("org.testcontainers:testcontainers")
|
||||
|
||||
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-elasticsearch"))
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package smoketest.data.elasticsearch;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.boot.testcontainers.service.connection.Ssl;
|
||||
import org.springframework.boot.testsupport.container.TestImage;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Smoke tests for Elasticsearch 8.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@DataElasticsearchTest
|
||||
class SampleElasticSearch8ApplicationTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
@Ssl
|
||||
static final ElasticsearchContainer elasticSearch = new ElasticsearchContainer(TestImage.ELASTICSEARCH_8.toString())
|
||||
.withPassword("my-custom-password");
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Autowired
|
||||
private SampleRepository exampleRepository;
|
||||
|
||||
@Test
|
||||
void testRepository() {
|
||||
SampleDocument document = new SampleDocument();
|
||||
document.setText("Look, new @DataElasticsearchTest!");
|
||||
String id = UUID.randomUUID().toString();
|
||||
document.setId(id);
|
||||
SampleDocument savedDocument = this.exampleRepository.save(document);
|
||||
SampleDocument getDocument = this.elasticsearchTemplate.get(id, SampleDocument.class);
|
||||
assertThat(getDocument).isNotNull();
|
||||
assertThat(getDocument.getId()).isNotNull();
|
||||
assertThat(getDocument.getId()).isEqualTo(savedDocument.getId());
|
||||
this.exampleRepository.deleteAll();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package smoketest.data.elasticsearch;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.boot.testsupport.container.TestImage;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Smoke tests for Elasticsearch.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@DataElasticsearchTest
|
||||
class SampleElasticSearchApplicationTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
static final ElasticsearchContainer elasticSearch = TestImage.container(ElasticsearchContainer.class);
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Autowired
|
||||
private SampleRepository exampleRepository;
|
||||
|
||||
@Test
|
||||
void testRepository() {
|
||||
SampleDocument document = new SampleDocument();
|
||||
document.setText("Look, new @DataElasticsearchTest!");
|
||||
String id = UUID.randomUUID().toString();
|
||||
document.setId(id);
|
||||
SampleDocument savedDocument = this.exampleRepository.save(document);
|
||||
SampleDocument getDocument = this.elasticsearchTemplate.get(id, SampleDocument.class);
|
||||
assertThat(getDocument).isNotNull();
|
||||
assertThat(getDocument.getId()).isNotNull();
|
||||
assertThat(getDocument.getId()).isEqualTo(savedDocument.getId());
|
||||
this.exampleRepository.deleteAll();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package smoketest.data.elasticsearch;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest;
|
||||
import org.springframework.boot.testcontainers.service.connection.PemTrustStore;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.boot.testsupport.container.TestImage;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Smoke tests for Elasticsearch with SSL.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@DataElasticsearchTest(
|
||||
properties = { "spring.elasticsearch.connection-timeout=120s", "spring.elasticsearch.socket-timeout=120s" })
|
||||
class SampleElasticSearchSslApplicationTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
@PemTrustStore(certificate = "classpath:ssl.crt")
|
||||
static final ElasticsearchContainer elasticSearch = TestImage.container(SecureElasticsearchContainer.class);
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Autowired
|
||||
private SampleRepository exampleRepository;
|
||||
|
||||
@Test
|
||||
void testRepository() {
|
||||
SampleDocument document = new SampleDocument();
|
||||
document.setText("Look, new @DataElasticsearchTest!");
|
||||
String id = UUID.randomUUID().toString();
|
||||
document.setId(id);
|
||||
SampleDocument savedDocument = this.exampleRepository.save(document);
|
||||
SampleDocument getDocument = this.elasticsearchTemplate.get(id, SampleDocument.class);
|
||||
assertThat(getDocument).isNotNull();
|
||||
assertThat(getDocument.getId()).isNotNull();
|
||||
assertThat(getDocument.getId()).isEqualTo(savedDocument.getId());
|
||||
this.exampleRepository.deleteAll();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package smoketest.data.elasticsearch;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
import org.testcontainers.utility.MountableFile;
|
||||
|
||||
/**
|
||||
* A {@link ElasticsearchContainer} for Elasticsearch with SSL configuration.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class SecureElasticsearchContainer extends ElasticsearchContainer {
|
||||
|
||||
SecureElasticsearchContainer(DockerImageName dockerImageName) {
|
||||
super(dockerImageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
// See
|
||||
// https://www.elastic.co/guide/en/elastic-stack-get-started/7.5/get-started-docker.html#get-started-docker-tls
|
||||
withEnv(Map.of("xpack.security.http.ssl.enabled", "true", "xpack.security.http.ssl.key",
|
||||
"/usr/share/elasticsearch/config/ssl.key", "xpack.security.http.ssl.certificate",
|
||||
"/usr/share/elasticsearch/config/ssl.crt", "xpack.security.transport.ssl.enabled", "true",
|
||||
"xpack.security.transport.ssl.verification_mode", "certificate", "xpack.security.transport.ssl.key",
|
||||
"/usr/share/elasticsearch/config/ssl.key", "xpack.security.transport.ssl.certificate",
|
||||
"/usr/share/elasticsearch/config/ssl.crt"));
|
||||
withCopyFileToContainer(MountableFile.forClasspathResource("/ssl.crt"),
|
||||
"/usr/share/elasticsearch/config/ssl.crt");
|
||||
withCopyFileToContainer(MountableFile.forClasspathResource("/ssl.key"),
|
||||
"/usr/share/elasticsearch/config/ssl.key");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICpjCCAY6gAwIBAgIUd1pIGeth3t+uXRwJqQgBkX6RqVwwDQYJKoZIhvcNAQEL
|
||||
BQAwDDEKMAgGA1UEAwwBKjAgFw0yNDA4MjMwOTI5MjBaGA8yMTI0MDgyMzA5Mjky
|
||||
MFowDDEKMAgGA1UEAwwBKjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
|
||||
AMvuy3afu6umnCgEBElfgboa2M1O7RWwuvA0OIWdEzxYYQmc9QUihd2l68pIu9jT
|
||||
hR+2CENL4iY2HNtELJ8kFSGgUGPGrsjLj/qqULG1/r2f18tPavMD7Hxo0AGA+yyX
|
||||
nECCfHGPJ7P88fWwoMfdp8Y4s/BW7QcC7vB9kQGjUOb4V/WUWI7c27Yxj6/nCPRr
|
||||
Gkb5YkEvsw6TPeBfZbx7kjWaYtd8eKjVHf40lu0AhXGK+lFuaLrY9VYBYoiMRtIZ
|
||||
3/EKf2gKQiIIR7tN3DUa5zi6vYvQNaUaK14yomfyynUzGPbIcMq8V+c6j3gI7jqf
|
||||
ITqaaBn5NIM0W7ox6hhr+UUCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEApgal5rth
|
||||
5y94hnwgNt0/+PuVj5vwxUIi0WgV6b1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YbGkR0hqY5bcGcI/Tm5
|
||||
ZZg8ZonNdwagmoihBFAZ+wpB
|
||||
-----END PRIVATE KEY-----
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package smoketest.data.elasticsearch;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
|
||||
/**
|
||||
* Sample document.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
@Document(indexName = "examples")
|
||||
public class SampleDocument {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String text;
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SampleDocument{" + "id='" + this.id + '\'' + ", text='" + this.text + '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package smoketest.data.elasticsearch;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
/**
|
||||
* Sample application.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class SampleElasticsearchApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConfigurableApplicationContext context = SpringApplication.run(SampleElasticsearchApplication.class, args);
|
||||
SampleRepository repository = context.getBean(SampleRepository.class);
|
||||
createDocument(repository);
|
||||
listDocuments(repository);
|
||||
repository.deleteAll();
|
||||
context.close();
|
||||
}
|
||||
|
||||
private static void listDocuments(SampleRepository repository) {
|
||||
System.out.println("Documents:");
|
||||
for (SampleDocument foundDocument : repository.findAll()) {
|
||||
System.out.println(" " + foundDocument);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createDocument(SampleRepository repository) {
|
||||
SampleDocument document = new SampleDocument();
|
||||
document.setText("Look, new @DataElasticsearchTest!");
|
||||
String id = UUID.randomUUID().toString();
|
||||
document.setId(id);
|
||||
SampleDocument savedDocument = repository.save(document);
|
||||
System.out.println("Saved document " + savedDocument);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package smoketest.data.elasticsearch;
|
||||
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* Sample repository.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
interface SampleRepository extends ElasticsearchRepository<SampleDocument, String> {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user