Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import java.net.URI;
import java.time.Duration;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;

import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;

Expand Down Expand Up @@ -56,7 +60,7 @@
* .build();
* </code></pre>
*
* @param <T> the component type that this builder is being used for
* @param <T> the component type that this builder is being used for
*
* @since 5.0.0
*/
Expand All @@ -80,6 +84,9 @@ public abstract class RedisStoreBuilder<T> implements ComponentConfigurer<T>, Di
String password = null;
boolean tls = false;
JedisPoolConfig poolConfig = null;
SSLSocketFactory sslSocketFactory = null;
SSLParameters sslParameters = null;
HostnameVerifier hostnameVerifier = null;

// These constructors are called only from Implementations
RedisStoreBuilder() {
Expand Down Expand Up @@ -146,7 +153,52 @@ public RedisStoreBuilder<T> tls(boolean tls) {
this.tls = tls;
return this;
}


/**
* Optionally specifies a custom {@link SSLSocketFactory} for TLS connections.
* <p>
* This is only used when TLS is enabled (either via {@link #tls(boolean)} or by using a
* {@code rediss:} URI). If TLS is not enabled this value is silently ignored. If not set,
* the JVM default SSL socket factory is used.
*
* @param sslSocketFactory the SSL socket factory, or null to use the default
* @return the builder
*/
public RedisStoreBuilder<T> sslSocketFactory(SSLSocketFactory sslSocketFactory) {
this.sslSocketFactory = sslSocketFactory;
return this;
}

/**
* Optionally specifies {@link SSLParameters} for TLS connections.
* <p>
* This is only used when TLS is enabled (either via {@link #tls(boolean)} or by using a
* {@code rediss:} URI). If TLS is not enabled this value is silently ignored. If not set,
* the JVM default SSL parameters are used.
*
* @param sslParameters the SSL parameters, or null to use the default
* @return the builder
*/
public RedisStoreBuilder<T> sslParameters(SSLParameters sslParameters) {
this.sslParameters = sslParameters;
return this;
}

/**
* Optionally specifies a {@link HostnameVerifier} for TLS connections.
* <p>
* This is only used when TLS is enabled (either via {@link #tls(boolean)} or by using a
* {@code rediss:} URI). If TLS is not enabled this value is silently ignored. If not set,
* the JVM default hostname verifier is used.
*
* @param hostnameVerifier the hostname verifier, or null to use the default
* @return the builder
*/
public RedisStoreBuilder<T> hostnameVerifier(HostnameVerifier hostnameVerifier) {
this.hostnameVerifier = hostnameVerifier;
return this;
}

/**
* Specifies a Redis host URI other than {@link #DEFAULT_URI}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected RedisStoreImplBase(RedisStoreBuilder<?> builder, LDLogger logger) {
this.prefix = (builder.prefix == null || builder.prefix.isEmpty()) ?
RedisStoreBuilder.DEFAULT_PREFIX :
builder.prefix;

this.pool = new JedisPool(poolConfig,
host,
port,
Expand All @@ -50,9 +51,9 @@ protected RedisStoreImplBase(RedisStoreBuilder<?> builder, LDLogger logger) {
database,
null, // clientName
tls,
null, // sslSocketFactory
null, // sslParameters
null // hostnameVerifier
builder.sslSocketFactory,
builder.sslParameters,
builder.hostnameVerifier
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;

import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;

Expand All @@ -23,6 +28,9 @@ public void testDefaultValues() {
assertNull(conf.database);
assertNull(conf.password);
assertFalse(conf.tls);
assertNull(conf.sslSocketFactory);
assertNull(conf.sslParameters);
assertNull(conf.hostnameVerifier);
assertEquals(Duration.ofMillis(Protocol.DEFAULT_TIMEOUT), conf.connectTimeout);
assertEquals(Duration.ofMillis(Protocol.DEFAULT_TIMEOUT), conf.socketTimeout);
assertEquals(RedisStoreBuilder.DEFAULT_PREFIX, conf.prefix);
Expand Down Expand Up @@ -53,6 +61,27 @@ public void testTlsConfigured() {
RedisStoreBuilder<?> conf = Redis.dataStore().tls(true);
assertTrue(conf.tls);
}

@Test
public void testSslSocketFactoryConfigured() {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
RedisStoreBuilder<?> conf = Redis.dataStore().sslSocketFactory(factory);
assertEquals(factory, conf.sslSocketFactory);
}

@Test
public void testSslParametersConfigured() {
SSLParameters params = new SSLParameters();
RedisStoreBuilder<?> conf = Redis.dataStore().sslParameters(params);
assertEquals(params, conf.sslParameters);
}

@Test
public void testHostnameVerifierConfigured() {
HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
RedisStoreBuilder<?> conf = Redis.dataStore().hostnameVerifier(verifier);
assertEquals(verifier, conf.hostnameVerifier);
}

@Test
public void testPrefixConfigured() throws URISyntaxException {
Expand Down
Loading