Add SSL service connection support for Redis

See gh-41137
This commit is contained in:
Moritz Halbritter 2025-02-11 10:22:31 +01:00
parent b773dcd356
commit 7cf9cc74a2
19 changed files with 460 additions and 103 deletions

View File

@ -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.
@ -92,21 +92,17 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration {
private JedisConnectionFactory createJedisConnectionFactory(
ObjectProvider<JedisClientConfigurationBuilderCustomizer> builderCustomizers) {
JedisClientConfiguration clientConfiguration = getJedisClientConfiguration(builderCustomizers);
if (getSentinelConfig() != null) {
return new JedisConnectionFactory(getSentinelConfig(), clientConfiguration);
}
if (getClusterConfiguration() != null) {
return new JedisConnectionFactory(getClusterConfiguration(), clientConfiguration);
}
return new JedisConnectionFactory(getStandaloneConfig(), clientConfiguration);
return switch (this.mode) {
case STANDALONE -> new JedisConnectionFactory(getStandaloneConfig(), clientConfiguration);
case CLUSTER -> new JedisConnectionFactory(getClusterConfiguration(), clientConfiguration);
case SENTINEL -> new JedisConnectionFactory(getSentinelConfig(), clientConfiguration);
};
}
private JedisClientConfiguration getJedisClientConfiguration(
ObjectProvider<JedisClientConfigurationBuilderCustomizer> builderCustomizers) {
JedisClientConfigurationBuilder builder = applyProperties(JedisClientConfiguration.builder());
if (isSslEnabled()) {
applySsl(builder);
}
applySslIfNeeded(builder);
RedisProperties.Pool pool = getProperties().getJedis().getPool();
if (isPoolEnabled(pool)) {
applyPooling(pool, builder);
@ -126,18 +122,19 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration {
return builder;
}
private void applySsl(JedisClientConfigurationBuilder builder) {
JedisSslClientConfigurationBuilder sslBuilder = builder.useSsl();
if (getProperties().getSsl().getBundle() != null) {
SslBundle sslBundle = getSslBundles().getBundle(getProperties().getSsl().getBundle());
sslBuilder.sslSocketFactory(sslBundle.createSslContext().getSocketFactory());
SslOptions sslOptions = sslBundle.getOptions();
SSLParameters sslParameters = new SSLParameters();
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(sslOptions.getCiphers()).to(sslParameters::setCipherSuites);
map.from(sslOptions.getEnabledProtocols()).to(sslParameters::setProtocols);
sslBuilder.sslParameters(sslParameters);
private void applySslIfNeeded(JedisClientConfigurationBuilder builder) {
SslBundle sslBundle = getSslBundle();
if (sslBundle == null) {
return;
}
JedisSslClientConfigurationBuilder sslBuilder = builder.useSsl();
sslBuilder.sslSocketFactory(sslBundle.createSslContext().getSocketFactory());
SslOptions sslOptions = sslBundle.getOptions();
SSLParameters sslParameters = new SSLParameters();
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(sslOptions.getCiphers()).to(sslParameters::setCipherSuites);
map.from(sslOptions.getEnabledProtocols()).to(sslParameters::setProtocols);
sslBuilder.sslParameters(sslParameters);
}
private void applyPooling(RedisProperties.Pool pool,

View File

@ -116,19 +116,14 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
ObjectProvider<LettuceClientConfigurationBuilderCustomizer> clientConfigurationBuilderCustomizers,
ObjectProvider<LettuceClientOptionsBuilderCustomizer> clientOptionsBuilderCustomizers,
ClientResources clientResources) {
LettuceClientConfiguration clientConfig = getLettuceClientConfiguration(clientConfigurationBuilderCustomizers,
clientOptionsBuilderCustomizers, clientResources, getProperties().getLettuce().getPool());
return createLettuceConnectionFactory(clientConfig);
}
private LettuceConnectionFactory createLettuceConnectionFactory(LettuceClientConfiguration clientConfiguration) {
if (getSentinelConfig() != null) {
return new LettuceConnectionFactory(getSentinelConfig(), clientConfiguration);
}
if (getClusterConfiguration() != null) {
return new LettuceConnectionFactory(getClusterConfiguration(), clientConfiguration);
}
return new LettuceConnectionFactory(getStandaloneConfig(), clientConfiguration);
LettuceClientConfiguration clientConfiguration = getLettuceClientConfiguration(
clientConfigurationBuilderCustomizers, clientOptionsBuilderCustomizers, clientResources,
getProperties().getLettuce().getPool());
return switch (this.mode) {
case STANDALONE -> new LettuceConnectionFactory(getStandaloneConfig(), clientConfiguration);
case CLUSTER -> new LettuceConnectionFactory(getClusterConfiguration(), clientConfiguration);
case SENTINEL -> new LettuceConnectionFactory(getSentinelConfig(), clientConfiguration);
};
}
private LettuceClientConfiguration getLettuceClientConfiguration(
@ -136,11 +131,12 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
ObjectProvider<LettuceClientOptionsBuilderCustomizer> clientOptionsBuilderCustomizers,
ClientResources clientResources, Pool pool) {
LettuceClientConfigurationBuilder builder = createBuilder(pool);
applyProperties(builder);
SslBundle sslBundle = getSslBundle();
applyProperties(builder, sslBundle);
if (StringUtils.hasText(getProperties().getUrl())) {
customizeConfigurationFromUrl(builder);
}
builder.clientOptions(createClientOptions(clientOptionsBuilderCustomizers));
builder.clientOptions(createClientOptions(clientOptionsBuilderCustomizers, sslBundle));
builder.clientResources(clientResources);
clientConfigurationBuilderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
return builder.build();
@ -153,8 +149,8 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
return LettuceClientConfiguration.builder();
}
private void applyProperties(LettuceClientConfiguration.LettuceClientConfigurationBuilder builder) {
if (isSslEnabled()) {
private void applyProperties(LettuceClientConfigurationBuilder builder, SslBundle sslBundle) {
if (sslBundle != null) {
builder.useSsl();
}
if (getProperties().getTimeout() != null) {
@ -195,14 +191,14 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
}
private ClientOptions createClientOptions(
ObjectProvider<LettuceClientOptionsBuilderCustomizer> clientConfigurationBuilderCustomizers) {
ObjectProvider<LettuceClientOptionsBuilderCustomizer> clientConfigurationBuilderCustomizers,
SslBundle sslBundle) {
ClientOptions.Builder builder = initializeClientOptionsBuilder();
Duration connectTimeout = getProperties().getConnectTimeout();
if (connectTimeout != null) {
builder.socketOptions(SocketOptions.builder().connectTimeout(connectTimeout).build());
}
if (isSslEnabled() && getProperties().getSsl().getBundle() != null) {
SslBundle sslBundle = getSslBundles().getBundle(getProperties().getSsl().getBundle());
if (sslBundle != null) {
io.lettuce.core.SslOptions.Builder sslOptionsBuilder = io.lettuce.core.SslOptions.builder();
sslOptionsBuilder.keyManager(sslBundle.getManagers().getKeyManagerFactory());
sslOptionsBuilder.trustManager(sslBundle.getManagers().getTrustManagerFactory());

View File

@ -18,6 +18,11 @@ package org.springframework.boot.autoconfigure.data.redis;
import java.util.List;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Adapts {@link RedisProperties} to {@link RedisConnectionDetails}.
*
@ -32,8 +37,11 @@ class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
private final RedisProperties properties;
PropertiesRedisConnectionDetails(RedisProperties properties) {
private final SslBundles sslBundles;
PropertiesRedisConnectionDetails(RedisProperties properties, SslBundles sslBundles) {
this.properties = properties;
this.sslBundles = sslBundles;
}
@Override
@ -52,8 +60,21 @@ class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
public Standalone getStandalone() {
RedisUrl redisUrl = getRedisUrl();
return (redisUrl != null)
? Standalone.of(redisUrl.uri().getHost(), redisUrl.uri().getPort(), redisUrl.database())
: Standalone.of(this.properties.getHost(), this.properties.getPort(), this.properties.getDatabase());
? Standalone.of(redisUrl.uri().getHost(), redisUrl.uri().getPort(), redisUrl.database(), getSslBundle())
: Standalone.of(this.properties.getHost(), this.properties.getPort(), this.properties.getDatabase(),
getSslBundle());
}
private SslBundle getSslBundle() {
if (!this.properties.getSsl().isEnabled()) {
return null;
}
String bundleName = this.properties.getSsl().getBundle();
if (StringUtils.hasLength(bundleName)) {
Assert.notNull(this.sslBundles, "SSL bundle name has been set but no SSL bundles found in context");
return this.sslBundles.getBundle(bundleName);
}
return SslBundle.systemDefault();
}
@Override
@ -65,8 +86,7 @@ class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
@Override
public Cluster getCluster() {
RedisProperties.Cluster cluster = this.properties.getCluster();
List<Node> nodes = (cluster != null) ? asNodes(cluster.getNodes()) : null;
return (nodes != null) ? () -> nodes : null;
return (cluster != null) ? new PropertiesCluster(cluster) : null;
}
private RedisUrl getRedisUrl() {
@ -84,6 +104,29 @@ class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
return new Node(host, port);
}
/**
* {@link Cluster} implementation backed by properties.
*/
private class PropertiesCluster implements Cluster {
private final List<Node> nodes;
PropertiesCluster(RedisProperties.Cluster properties) {
this.nodes = asNodes(properties.getNodes());
}
@Override
public List<Node> getNodes() {
return this.nodes;
}
@Override
public SslBundle getSslBundle() {
return PropertiesRedisConnectionDetails.this.getSslBundle();
}
}
/**
* {@link Sentinel} implementation backed by properties.
*/
@ -123,6 +166,11 @@ class PropertiesRedisConnectionDetails implements RedisConnectionDetails {
return this.properties.getPassword();
}
@Override
public SslBundle getSslBundle() {
return PropertiesRedisConnectionDetails.this.getSslBundle();
}
}
}

View File

@ -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,12 +16,14 @@
package org.springframework.boot.autoconfigure.data.redis;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@ -51,8 +53,9 @@ public class RedisAutoConfiguration {
@Bean
@ConditionalOnMissingBean(RedisConnectionDetails.class)
PropertiesRedisConnectionDetails redisConnectionDetails(RedisProperties properties) {
return new PropertiesRedisConnectionDetails(properties);
PropertiesRedisConnectionDetails redisConnectionDetails(RedisProperties properties,
ObjectProvider<SslBundles> sslBundles) {
return new PropertiesRedisConnectionDetails(properties, sslBundles.getIfAvailable());
}
@Bean

View File

@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails.
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails.Node;
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails.Sentinel;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Pool;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisNode;
@ -62,6 +63,8 @@ abstract class RedisConnectionConfiguration {
private final SslBundles sslBundles;
protected final Mode mode;
protected RedisConnectionConfiguration(RedisProperties properties, RedisConnectionDetails connectionDetails,
ObjectProvider<RedisStandaloneConfiguration> standaloneConfigurationProvider,
ObjectProvider<RedisSentinelConfiguration> sentinelConfigurationProvider,
@ -73,6 +76,7 @@ abstract class RedisConnectionConfiguration {
this.clusterConfiguration = clusterConfigurationProvider.getIfAvailable();
this.connectionDetails = connectionDetails;
this.sslBundles = sslBundles.getIfAvailable();
this.mode = determineMode();
}
protected final RedisStandaloneConfiguration getStandaloneConfig() {
@ -153,6 +157,17 @@ abstract class RedisConnectionConfiguration {
return this.sslBundles;
}
protected SslBundle getSslBundle() {
return switch (this.mode) {
case STANDALONE -> (this.connectionDetails.getStandalone() != null)
? this.connectionDetails.getStandalone().getSslBundle() : null;
case CLUSTER -> (this.connectionDetails.getCluster() != null)
? this.connectionDetails.getCluster().getSslBundle() : null;
case SENTINEL -> (this.connectionDetails.getSentinel() != null)
? this.connectionDetails.getSentinel().getSslBundle() : null;
};
}
protected final boolean isSslEnabled() {
return getProperties().getSsl().isEnabled();
}
@ -178,4 +193,20 @@ abstract class RedisConnectionConfiguration {
return this.connectionDetails;
}
private Mode determineMode() {
if (getSentinelConfig() != null) {
return Mode.SENTINEL;
}
if (getClusterConfiguration() != null) {
return Mode.CLUSTER;
}
return Mode.STANDALONE;
}
enum Mode {
STANDALONE, CLUSTER, SENTINEL
}
}

View File

@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.data.redis;
import java.util.List;
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.util.Assert;
/**
@ -98,11 +99,58 @@ public interface RedisConnectionDetails extends ConnectionDetails {
return 0;
}
static Standalone of(String host, int port) {
return of(host, port, 0);
/**
* SSL bundle to use.
* @return the SSL bundle to use
* @since 3.5.0
*/
default SslBundle getSslBundle() {
return null;
}
/**
* Creates a new instance with the given host and port.
* @param host the host
* @param port the port
* @return the new instance
*/
static Standalone of(String host, int port) {
return of(host, port, 0, null);
}
/**
* Creates a new instance with the given host, port and SSL bundle.
* @param host the host
* @param port the port
* @param sslBundle the SSL bundle
* @return the new instance
* @since 3.5.0
*/
static Standalone of(String host, int port, SslBundle sslBundle) {
return of(host, port, 0, sslBundle);
}
/**
* Creates a new instance with the given host, port and database.
* @param host the host
* @param port the port
* @param database the database
* @return the new instance
*/
static Standalone of(String host, int port, int database) {
return of(host, port, database, null);
}
/**
* Creates a new instance with the given host, port, database and SSL bundle.
* @param host the host
* @param port the port
* @param database the database
* @param sslBundle the SSL bundle
* @return the new instance
* @since 3.5.0
*/
static Standalone of(String host, int port, int database, SslBundle sslBundle) {
Assert.hasLength(host, "'host' must not be empty");
return new Standalone() {
@ -121,6 +169,10 @@ public interface RedisConnectionDetails extends ConnectionDetails {
return database;
}
@Override
public SslBundle getSslBundle() {
return sslBundle;
}
};
}
@ -161,6 +213,15 @@ public interface RedisConnectionDetails extends ConnectionDetails {
*/
String getPassword();
/**
* SSL bundle to use.
* @return the SSL bundle to use
* @since 3.5.0
*/
default SslBundle getSslBundle() {
return null;
}
}
/**
@ -175,6 +236,15 @@ public interface RedisConnectionDetails extends ConnectionDetails {
*/
List<Node> getNodes();
/**
* SSL bundle to use.
* @return the SSL bundle to use
* @since 3.5.0
*/
default SslBundle getSslBundle() {
return null;
}
}
/**

View File

@ -18,40 +18,54 @@ package org.springframework.boot.autoconfigure.data.redis;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails.Node;
import org.springframework.boot.ssl.DefaultSslBundleRegistry;
import org.springframework.boot.ssl.SslBundle;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link PropertiesRedisConnectionDetails}.
*
* @author Scott Frederick
* @author Moritz Halbritter
*/
class PropertiesRedisConnectionDetailsTests {
private final RedisProperties properties = new RedisProperties();
private RedisProperties properties;
private PropertiesRedisConnectionDetails connectionDetails;
private DefaultSslBundleRegistry sslBundleRegistry;
@BeforeEach
void setUp() {
this.properties = new RedisProperties();
this.sslBundleRegistry = new DefaultSslBundleRegistry();
this.connectionDetails = new PropertiesRedisConnectionDetails(this.properties, this.sslBundleRegistry);
}
@Test
void connectionIsConfiguredWithDefaults() {
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
RedisConnectionDetails.Standalone standalone = connectionDetails.getStandalone();
RedisConnectionDetails.Standalone standalone = this.connectionDetails.getStandalone();
assertThat(standalone.getHost()).isEqualTo("localhost");
assertThat(standalone.getPort()).isEqualTo(6379);
assertThat(standalone.getDatabase()).isEqualTo(0);
assertThat(connectionDetails.getSentinel()).isNull();
assertThat(connectionDetails.getCluster()).isNull();
assertThat(connectionDetails.getUsername()).isNull();
assertThat(connectionDetails.getPassword()).isNull();
assertThat(this.connectionDetails.getSentinel()).isNull();
assertThat(this.connectionDetails.getCluster()).isNull();
assertThat(this.connectionDetails.getUsername()).isNull();
assertThat(this.connectionDetails.getPassword()).isNull();
}
@Test
void credentialsAreConfiguredFromUrlWithUsernameAndPassword() {
this.properties.setUrl("redis://user:secret@example.com");
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getUsername()).isEqualTo("user");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(this.connectionDetails.getUsername()).isEqualTo("user");
assertThat(this.connectionDetails.getPassword()).isEqualTo("secret");
}
@Test
@ -59,9 +73,8 @@ class PropertiesRedisConnectionDetailsTests {
this.properties.setUrl("redis://user:@example.com");
this.properties.setUsername("notused");
this.properties.setPassword("notused");
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getUsername()).isEqualTo("user");
assertThat(connectionDetails.getPassword()).isEmpty();
assertThat(this.connectionDetails.getUsername()).isEqualTo("user");
assertThat(this.connectionDetails.getPassword()).isEmpty();
}
@Test
@ -69,9 +82,8 @@ class PropertiesRedisConnectionDetailsTests {
this.properties.setUrl("redis://:secret@example.com");
this.properties.setUsername("notused");
this.properties.setPassword("notused");
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getUsername()).isEmpty();
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(this.connectionDetails.getUsername()).isEmpty();
assertThat(this.connectionDetails.getPassword()).isEqualTo("secret");
}
@Test
@ -79,18 +91,16 @@ class PropertiesRedisConnectionDetailsTests {
this.properties.setUrl("redis://secret@example.com");
this.properties.setUsername("notused");
this.properties.setPassword("notused");
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getUsername()).isNull();
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(this.connectionDetails.getUsername()).isNull();
assertThat(this.connectionDetails.getPassword()).isEqualTo("secret");
}
@Test
void credentialsAreConfiguredFromProperties() {
this.properties.setUsername("user");
this.properties.setPassword("secret");
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getUsername()).isEqualTo("user");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(this.connectionDetails.getUsername()).isEqualTo("user");
assertThat(this.connectionDetails.getPassword()).isEqualTo("secret");
}
@Test
@ -99,8 +109,7 @@ class PropertiesRedisConnectionDetailsTests {
this.properties.setHost("notused");
this.properties.setPort(9999);
this.properties.setDatabase(5);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
RedisConnectionDetails.Standalone standalone = connectionDetails.getStandalone();
RedisConnectionDetails.Standalone standalone = this.connectionDetails.getStandalone();
assertThat(standalone.getHost()).isEqualTo("example.com");
assertThat(standalone.getPort()).isEqualTo(1234);
assertThat(standalone.getDatabase()).isEqualTo(9999);
@ -110,7 +119,8 @@ class PropertiesRedisConnectionDetailsTests {
void standaloneIsConfiguredFromUrlWithoutDatabase() {
this.properties.setUrl("redis://example.com:1234");
this.properties.setDatabase(5);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties,
null);
RedisConnectionDetails.Standalone standalone = connectionDetails.getStandalone();
assertThat(standalone.getHost()).isEqualTo("example.com");
assertThat(standalone.getPort()).isEqualTo(1234);
@ -122,8 +132,7 @@ class PropertiesRedisConnectionDetailsTests {
this.properties.setHost("example.com");
this.properties.setPort(1234);
this.properties.setDatabase(5);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
RedisConnectionDetails.Standalone standalone = connectionDetails.getStandalone();
RedisConnectionDetails.Standalone standalone = this.connectionDetails.getStandalone();
assertThat(standalone.getHost()).isEqualTo("example.com");
assertThat(standalone.getPort()).isEqualTo(1234);
assertThat(standalone.getDatabase()).isEqualTo(5);
@ -134,8 +143,7 @@ class PropertiesRedisConnectionDetailsTests {
RedisProperties.Cluster cluster = new RedisProperties.Cluster();
cluster.setNodes(List.of("localhost:1111", "127.0.0.1:2222", "[::1]:3333"));
this.properties.setCluster(cluster);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
assertThat(connectionDetails.getCluster().getNodes()).containsExactly(new Node("localhost", 1111),
assertThat(this.connectionDetails.getCluster().getNodes()).containsExactly(new Node("localhost", 1111),
new Node("127.0.0.1", 2222), new Node("[::1]", 3333));
}
@ -145,7 +153,8 @@ class PropertiesRedisConnectionDetailsTests {
sentinel.setNodes(List.of("localhost:1111", "127.0.0.1:2222", "[::1]:3333"));
this.properties.setSentinel(sentinel);
this.properties.setDatabase(5);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties,
null);
assertThat(connectionDetails.getSentinel().getNodes()).containsExactly(new Node("localhost", 1111),
new Node("127.0.0.1", 2222), new Node("[::1]", 3333));
assertThat(connectionDetails.getSentinel().getDatabase()).isEqualTo(5);
@ -158,8 +167,32 @@ class PropertiesRedisConnectionDetailsTests {
this.properties.setSentinel(sentinel);
this.properties.setUrl("redis://example.com:1234/9999");
this.properties.setDatabase(5);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties);
PropertiesRedisConnectionDetails connectionDetails = new PropertiesRedisConnectionDetails(this.properties,
null);
assertThat(connectionDetails.getSentinel().getDatabase()).isEqualTo(9999);
}
@Test
void shouldReturnSslBundle() {
SslBundle bundle1 = mock(SslBundle.class);
this.sslBundleRegistry.registerBundle("bundle-1", bundle1);
this.properties.getSsl().setBundle("bundle-1");
SslBundle sslBundle = this.connectionDetails.getStandalone().getSslBundle();
assertThat(sslBundle).isSameAs(bundle1);
}
@Test
void shouldReturnSystemBundleIfSslIsEnabledButBundleNotSet() {
this.properties.getSsl().setEnabled(true);
SslBundle sslBundle = this.connectionDetails.getStandalone().getSslBundle();
assertThat(sslBundle).isNotNull();
}
@Test
void shouldReturnNullIfSslIsNotEnabled() {
this.properties.getSsl().setEnabled(false);
SslBundle sslBundle = this.connectionDetails.getStandalone().getSslBundle();
assertThat(sslBundle).isNull();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 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,9 +16,12 @@
package org.springframework.boot.docker.compose.service.connection.redis;
import javax.net.ssl.SSLContext;
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails;
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails.Standalone;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.boot.testsupport.container.TestImage;
import static org.assertj.core.api.Assertions.assertThat;
@ -39,6 +42,17 @@ class RedisDockerComposeConnectionDetailsFactoryIntegrationTests {
assertConnectionDetails(connectionDetails);
}
@DockerComposeTest(composeFile = "redis-ssl-compose.yaml", image = TestImage.REDIS,
additionalResources = { "ca.crt", "server.crt", "server.key", "client.crt", "client.key" })
void runWithSslCreatesConnectionDetails(RedisConnectionDetails connectionDetails) {
assertConnectionDetails(connectionDetails);
Standalone standalone = connectionDetails.getStandalone();
SslBundle sslBundle = standalone.getSslBundle();
assertThat(sslBundle).isNotNull();
SSLContext sslContext = sslBundle.createSslContext();
assertThat(sslContext).isNotNull();
}
@DockerComposeTest(composeFile = "redis-bitnami-compose.yaml", image = TestImage.BITNAMI_REDIS)
void runWithBitnamiImageCreatesConnectionDetails(RedisConnectionDetails connectionDetails) {
assertConnectionDetails(connectionDetails);

View File

@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFhjCCA26gAwIBAgIUfIkk29IT9OpbgfjL8oRIPSLjUcAwDQYJKoZIhvcNAQEL
BQAwOzEZMBcGA1UECgwQU3ByaW5nIEJvb3QgVGVzdDEeMBwGA1UEAwwVQ2VydGlm
aWNhdGUgQXV0aG9yaXR5MB4XDTI0MDUwMTE2NTMyNVoXDT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UnkCF1UpDRKPiEO5G/apPtav8PbCNaX
GAimLGw+WZNZuv7+T33bEBeUdwKBgQDAwiidayLXkRkz2deefdDKcXQsB7RHFGGy
vfZPBCGqizxml+6ojJkkDsVUKL1IXFfyK9KpQAI6tezn4oktgu4jAQqkYY7QZobs
RpQx1dR+KxEm7ISDBTq/B1Q9cFKUKVvQQy8N2pnIbCdzb6MTOKLmJqFGTjr+5T8q
F32B5vkDAQKBgDCKfH42AwFc5EZiPlEcTZcdARMtKCa/bXqbKVZjjgR+AFpi0K+3
womWoI1l8E5KYkYOEe0qaU+m+aaybgy37qjYkNqoe34qJFwvU1b9ToXScBFdRz9b
pbQRU1naSTKl/u/OrUxzeTfPwAU8H7VMOlFSiOVHp2he+J0JetcGtixdAoGBAIJQ
QMj7rxhxHcqyEVUy1b6nKNTDeJs9Kjd+uU/+CQyVCQaK3GvScY2w9rLIv/51f3dX
LRoDDf7HExxJSFgeVgQQJjOvSK+XQMvngzSVzQxm7TeVWpiBJpAS0l6e2xUTSODp
KpyBFsoqZBlkdaj+9xIFN66iILxGG4fHTbBOiDYBAoGBAOZMKjM5N/hGcCmik/6t
p/zBA2pN9O6zwPndITTsdyVWSlVqCZhXlRX47CerAN+/WVCidlh7Vp5Tuy75Wa77
v16IDLO01txgWNobcLaM4VgFsyLi5JuxK73S18Vb1cKWdHFRF0LH3cUIq20fjpv6
Odl4vjNOncXMZCLPHQ+bKWaf
-----END PRIVATE KEY-----

View File

@ -0,0 +1,21 @@
services:
redis:
image: '{imageName}'
ports:
- '6379'
secrets:
- ssl-ca
- ssl-key
- ssl-cert
command: 'redis-server --tls-port 6379 --port 0 --tls-cert-file /run/secrets/ssl-cert --tls-key-file /run/secrets/ssl-key --tls-ca-cert-file /run/secrets/ssl-ca'
labels:
- 'org.springframework.boot.sslbundle.pem.keystore.certificate=client.crt'
- 'org.springframework.boot.sslbundle.pem.keystore.private-key=client.key'
- 'org.springframework.boot.sslbundle.pem.truststore.certificate=ca.crt'
secrets:
ssl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Btq8ZE0zbO1
vsAm3gTBXcrCJxzw0Wjt8pzEbk3yELm4WE6VDEx4da2jWocdspslpIwdjHnPwsbH
r5O3ZAgigZs/ZtKW/U4=
-----END PRIVATE KEY-----

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 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.
@ -57,7 +57,7 @@ class RedisDockerComposeConnectionDetailsFactory extends DockerComposeConnection
RedisDockerComposeConnectionDetails(RunningService service) {
super(service);
this.standalone = Standalone.of(service.host(), service.ports().get(REDIS_PORT));
this.standalone = Standalone.of(service.host(), service.ports().get(REDIS_PORT), getSslBundle(service));
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 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.
@ -75,7 +75,8 @@ class RedisContainerConnectionDetailsFactory
@Override
public Standalone getStandalone() {
return Standalone.of(getContainer().getHost(), getContainer().getMappedPort(REDIS_PORT));
return Standalone.of(getContainer().getHost(), getContainer().getMappedPort(REDIS_PORT),
super.getSslBundle());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 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.
@ -26,6 +26,8 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
import org.springframework.boot.testcontainers.service.connection.PemKeyStore;
import org.springframework.boot.testcontainers.service.connection.PemTrustStore;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.container.TestImage;
@ -40,16 +42,15 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@Testcontainers(disabledWithoutDocker = true)
@ClassPathExclusions("lettuce-core-*.jar")
@DataRedisTest(properties = { "spring.data.redis.ssl.bundle=client",
"spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt",
"spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key",
"spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" })
@DataRedisTest
class SampleRedisApplicationJedisSslTests {
private static final Charset CHARSET = StandardCharsets.UTF_8;
@Container
@ServiceConnection
@PemKeyStore(certificate = "classpath:ssl/test-client.crt", privateKey = "classpath:ssl/test-client.key")
@PemTrustStore("classpath:ssl/test-ca.crt")
static RedisContainer redis = TestImage.container(SecureRedisContainer.class);
@Autowired

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 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.
@ -27,6 +27,8 @@ import reactor.test.StepVerifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.PemKeyStore;
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.redis.core.ReactiveRedisOperations;
@ -37,14 +39,13 @@ import org.springframework.data.redis.core.ReactiveRedisOperations;
* @author Scott Frederick
*/
@Testcontainers(disabledWithoutDocker = true)
@SpringBootTest(properties = { "spring.data.redis.ssl.bundle=client",
"spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt",
"spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key",
"spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" })
@SpringBootTest
class SampleRedisApplicationReactiveSslTests {
@Container
@ServiceConnection
@PemKeyStore(certificate = "classpath:ssl/test-client.crt", privateKey = "classpath:ssl/test-client.key")
@PemTrustStore("classpath:ssl/test-ca.crt")
static RedisContainer redis = TestImage.container(SecureRedisContainer.class);
@Autowired

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 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.
@ -26,6 +26,8 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.PemKeyStore;
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.redis.core.RedisOperations;
@ -38,16 +40,15 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Scott Frederick
*/
@Testcontainers(disabledWithoutDocker = true)
@SpringBootTest(properties = { "spring.data.redis.ssl.bundle=client",
"spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt",
"spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key",
"spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" })
@SpringBootTest
class SampleRedisApplicationSslTests {
private static final Charset CHARSET = StandardCharsets.UTF_8;
@Container
@ServiceConnection
@PemKeyStore(certificate = "classpath:ssl/test-client.crt", privateKey = "classpath:ssl/test-client.key")
@PemTrustStore("classpath:ssl/test-ca.crt")
static RedisContainer redis = TestImage.container(SecureRedisContainer.class);
@Autowired