diff --git a/module/spring-boot-data-redis/src/dockerTest/java/org/springframework/boot/data/redis/docker/compose/DataRedisDockerComposeConnectionDetailsFactoryIntegrationTests.java b/module/spring-boot-data-redis/src/dockerTest/java/org/springframework/boot/data/redis/docker/compose/DataRedisDockerComposeConnectionDetailsFactoryIntegrationTests.java index aec2e5a51d8..23922f3ec8b 100644 --- a/module/spring-boot-data-redis/src/dockerTest/java/org/springframework/boot/data/redis/docker/compose/DataRedisDockerComposeConnectionDetailsFactoryIntegrationTests.java +++ b/module/spring-boot-data-redis/src/dockerTest/java/org/springframework/boot/data/redis/docker/compose/DataRedisDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -46,8 +46,7 @@ class DataRedisDockerComposeConnectionDetailsFactoryIntegrationTests { additionalResources = { "ca.crt", "server.crt", "server.key", "client.crt", "client.key" }) void runWithSslCreatesConnectionDetails(DataRedisConnectionDetails connectionDetails) { assertConnectionDetails(connectionDetails); - Standalone standalone = connectionDetails.getStandalone(); - SslBundle sslBundle = standalone.getSslBundle(); + SslBundle sslBundle = connectionDetails.getSslBundle(); assertThat(sslBundle).isNotNull(); SSLContext sslContext = sslBundle.createSslContext(); assertThat(sslContext).isNotNull(); diff --git a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionConfiguration.java b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionConfiguration.java index 29a12a37515..9aba8363d9c 100644 --- a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionConfiguration.java +++ b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionConfiguration.java @@ -156,14 +156,7 @@ abstract class DataRedisConnectionConfiguration { } protected @Nullable 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; - }; + return this.connectionDetails.getSslBundle(); } protected final boolean isSslEnabled() { diff --git a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionDetails.java b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionDetails.java index cfebee1246f..ec249e1993d 100644 --- a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionDetails.java +++ b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/DataRedisConnectionDetails.java @@ -49,6 +49,14 @@ public interface DataRedisConnectionDetails extends ConnectionDetails { return null; } + /** + * SSL bundle to use. + * @return the SSL bundle to use + */ + default @Nullable SslBundle getSslBundle() { + return null; + } + /** * Redis standalone configuration. Mutually exclusive with {@link #getSentinel()} and * {@link #getCluster()}. @@ -101,14 +109,6 @@ public interface DataRedisConnectionDetails extends ConnectionDetails { return 0; } - /** - * SSL bundle to use. - * @return the SSL bundle to use - */ - default @Nullable SslBundle getSslBundle() { - return null; - } - /** * Creates a new instance with the given host and port. * @param host the host @@ -116,18 +116,7 @@ public interface DataRedisConnectionDetails extends ConnectionDetails { * @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 - */ - static Standalone of(String host, int port, @Nullable SslBundle sslBundle) { - return of(host, port, 0, sslBundle); + return of(host, port, 0); } /** @@ -138,18 +127,6 @@ public interface DataRedisConnectionDetails extends ConnectionDetails { * @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 - */ - static Standalone of(String host, int port, int database, @Nullable SslBundle sslBundle) { Assert.hasLength(host, "'host' must not be empty"); return new Standalone() { @@ -168,10 +145,6 @@ public interface DataRedisConnectionDetails extends ConnectionDetails { return database; } - @Override - public @Nullable SslBundle getSslBundle() { - return sslBundle; - } }; } @@ -212,14 +185,6 @@ public interface DataRedisConnectionDetails extends ConnectionDetails { */ @Nullable String getPassword(); - /** - * SSL bundle to use. - * @return the SSL bundle to use - */ - default @Nullable SslBundle getSslBundle() { - return null; - } - } /** @@ -234,14 +199,6 @@ public interface DataRedisConnectionDetails extends ConnectionDetails { */ List getNodes(); - /** - * SSL bundle to use. - * @return the SSL bundle to use - */ - default @Nullable SslBundle getSslBundle() { - return null; - } - } /** diff --git a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/PropertiesDataRedisConnectionDetails.java b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/PropertiesDataRedisConnectionDetails.java index 515b2f9d672..97e786186ee 100644 --- a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/PropertiesDataRedisConnectionDetails.java +++ b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/autoconfigure/PropertiesDataRedisConnectionDetails.java @@ -60,15 +60,7 @@ class PropertiesDataRedisConnectionDetails implements DataRedisConnectionDetails } @Override - public Standalone getStandalone() { - DataRedisUrl redisUrl = getRedisUrl(); - return (redisUrl != null) - ? Standalone.of(redisUrl.uri().getHost(), redisUrl.uri().getPort(), redisUrl.database(), getSslBundle()) - : Standalone.of(this.properties.getHost(), this.properties.getPort(), this.properties.getDatabase(), - getSslBundle()); - } - - private @Nullable SslBundle getSslBundle() { + public @Nullable SslBundle getSslBundle() { if (!this.properties.getSsl().isEnabled()) { return null; } @@ -80,6 +72,14 @@ class PropertiesDataRedisConnectionDetails implements DataRedisConnectionDetails return SslBundle.systemDefault(); } + @Override + public Standalone getStandalone() { + DataRedisUrl 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()); + } + @Override public @Nullable Sentinel getSentinel() { DataRedisProperties.Sentinel sentinel = this.properties.getSentinel(); @@ -126,11 +126,6 @@ class PropertiesDataRedisConnectionDetails implements DataRedisConnectionDetails return this.nodes; } - @Override - public @Nullable SslBundle getSslBundle() { - return PropertiesDataRedisConnectionDetails.this.getSslBundle(); - } - } /** @@ -174,11 +169,6 @@ class PropertiesDataRedisConnectionDetails implements DataRedisConnectionDetails return this.properties.getPassword(); } - @Override - public @Nullable SslBundle getSslBundle() { - return PropertiesDataRedisConnectionDetails.this.getSslBundle(); - } - } } diff --git a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/docker/compose/RedisDockerComposeConnectionDetailsFactory.java b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/docker/compose/RedisDockerComposeConnectionDetailsFactory.java index 92b89b39c81..435e803b974 100644 --- a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/docker/compose/RedisDockerComposeConnectionDetailsFactory.java +++ b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/docker/compose/RedisDockerComposeConnectionDetailsFactory.java @@ -16,10 +16,13 @@ package org.springframework.boot.data.redis.docker.compose; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.data.redis.autoconfigure.DataRedisConnectionDetails; import org.springframework.boot.docker.compose.core.RunningService; import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory; import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource; +import org.springframework.boot.ssl.SslBundle; /** * {@link DockerComposeConnectionDetailsFactory} to create @@ -56,9 +59,17 @@ class RedisDockerComposeConnectionDetailsFactory private final Standalone standalone; + private final @Nullable SslBundle sslBundle; + RedisDockerComposeConnectionDetails(RunningService service) { super(service); - this.standalone = Standalone.of(service.host(), service.ports().get(REDIS_PORT), getSslBundle(service)); + this.standalone = Standalone.of(service.host(), service.ports().get(REDIS_PORT)); + this.sslBundle = getSslBundle(service); + } + + @Override + public @Nullable SslBundle getSslBundle() { + return this.sslBundle; } @Override diff --git a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/testcontainers/RedisContainerConnectionDetailsFactory.java b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/testcontainers/RedisContainerConnectionDetailsFactory.java index 697eb67cefa..008596c1afa 100644 --- a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/testcontainers/RedisContainerConnectionDetailsFactory.java +++ b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/testcontainers/RedisContainerConnectionDetailsFactory.java @@ -20,10 +20,12 @@ import java.util.List; import com.redis.testcontainers.RedisContainer; import com.redis.testcontainers.RedisStackContainer; +import org.jspecify.annotations.Nullable; import org.testcontainers.containers.Container; import org.testcontainers.containers.GenericContainer; import org.springframework.boot.data.redis.autoconfigure.DataRedisConnectionDetails; +import org.springframework.boot.ssl.SslBundle; import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactory; import org.springframework.boot.testcontainers.service.connection.ContainerConnectionSource; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; @@ -75,10 +77,14 @@ class RedisContainerConnectionDetailsFactory super(source); } + @Override + public @Nullable SslBundle getSslBundle() { + return super.getSslBundle(); + } + @Override public Standalone getStandalone() { - return Standalone.of(getContainer().getHost(), getContainer().getMappedPort(REDIS_PORT), - super.getSslBundle()); + return Standalone.of(getContainer().getHost(), getContainer().getMappedPort(REDIS_PORT)); } } diff --git a/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/autoconfigure/PropertiesRedisConnectionDetailsTests.java b/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/autoconfigure/PropertiesRedisConnectionDetailsTests.java index 8417258ea95..51610c47c94 100644 --- a/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/autoconfigure/PropertiesRedisConnectionDetailsTests.java +++ b/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/autoconfigure/PropertiesRedisConnectionDetailsTests.java @@ -177,21 +177,21 @@ class PropertiesRedisConnectionDetailsTests { SslBundle bundle1 = mock(SslBundle.class); this.sslBundleRegistry.registerBundle("bundle-1", bundle1); this.properties.getSsl().setBundle("bundle-1"); - SslBundle sslBundle = this.connectionDetails.getStandalone().getSslBundle(); + SslBundle sslBundle = this.connectionDetails.getSslBundle(); assertThat(sslBundle).isSameAs(bundle1); } @Test void shouldReturnSystemBundleIfSslIsEnabledButBundleNotSet() { this.properties.getSsl().setEnabled(true); - SslBundle sslBundle = this.connectionDetails.getStandalone().getSslBundle(); + SslBundle sslBundle = this.connectionDetails.getSslBundle(); assertThat(sslBundle).isNotNull(); } @Test void shouldReturnNullIfSslIsNotEnabled() { this.properties.getSsl().setEnabled(false); - SslBundle sslBundle = this.connectionDetails.getStandalone().getSslBundle(); + SslBundle sslBundle = this.connectionDetails.getSslBundle(); assertThat(sslBundle).isNull(); }