DATAREDIS-480 - Polishing.

Add missing author tag. Minor reformatting. Explicitly set default SSL options and add test to verify default SSL options. Enhance JavaDoc.

Original pull request: #180.
This commit is contained in:
Mark Paluch
2016-03-22 10:59:59 +01:00
parent 8edfb2b94e
commit b3243ff328
2 changed files with 42 additions and 14 deletions

View File

@@ -98,9 +98,9 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
private RedisClusterConfiguration clusterConfiguration;
private ClusterCommandExecutor clusterCommandExecutor;
private ClientResources clientResources;
private boolean useSsl;
private boolean useSsl = false;
private boolean verifyPeer = true;
private boolean startTls;
private boolean startTls = false;
/**
* Constructs a new <code>LettuceConnectionFactory</code> instance with default settings.
@@ -323,14 +323,14 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
/**
* Returns whether to use SSL.
*
* @return
* @return use of SSL
*/
public boolean isUseSsl() {
return useSsl;
}
/**
* Sets to use verify certificate validity/hostname check when SSL is used
* Sets to use verify certificate validity/hostname check when SSL is used.
*
* @param verifyPeer {@literal false} not to verify hostname.
*/
@@ -339,35 +339,34 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
}
/**
* Returns whether to verify certificate validity/hostname check when SSL is used
* Returns whether to verify certificate validity/hostname check when SSL is used.
*
* @return
* @return verify peers when using SSL
*/
public boolean isVerifyPeer() {
return verifyPeer;
}
/**
* Returns whether to issue a StartTLS
* Returns whether to issue a StartTLS.
*
* @return
*/
* @return use of StartTLS
*/
public boolean isStartTls() {
return startTls;
}
/**
* Sets to issue StartTLS
* Sets to issue StartTLS.
*
* @param startTls {@literal true} to issue StartTLS
*/
* @param startTls {@literal true} to issue StartTLS.
*/
public void setStartTls(boolean startTls) {
this.startTls = startTls;
}
/**
* Indicates if validation of the native Lettuce connection is enabled
* Indicates if validation of the native Lettuce connection is enabled.
*
* @return connection validation enabled
*/
@@ -594,10 +593,12 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
if (password != null) {
builder.withPassword(password);
}
builder.withSsl(useSsl);
builder.withVerifyPeer(verifyPeer);
builder.withStartTls(startTls);
builder.withTimeout(timeout, TimeUnit.MILLISECONDS);
if (clientResources != null) {
return RedisClient.create(clientResources, builder.build());
}

View File

@@ -37,6 +37,7 @@ import com.lambdaworks.redis.cluster.RedisClusterClient;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Balázs Németh
*/
public class LettuceConnectionFactoryUnitTests {
@@ -129,6 +130,30 @@ public class LettuceConnectionFactoryUnitTests {
assertThat(client, instanceOf(RedisClusterClient.class));
}
/**
* @see DATAREDIS-480
*/
@Test
public void sslOptionsShouldBeDisabledByDefaultOnClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
connectionFactory.afterPropertiesSet();
ConnectionFactoryTracker.add(connectionFactory);
AbstractRedisClient client = (AbstractRedisClient) getField(connectionFactory, "client");
assertThat(client, instanceOf(RedisClient.class));
RedisURI redisUri = (RedisURI) getField(client, "redisURI");
assertThat(redisUri.isSsl(), is(false));
assertThat(connectionFactory.isUseSsl(), is(false));
assertThat(redisUri.isStartTls(), is(false));
assertThat(connectionFactory.isStartTls(), is(false));
assertThat(redisUri.isVerifyPeer(), is(true));
assertThat(connectionFactory.isVerifyPeer(), is(true));
}
/**
* @see DATAREDIS-476
*/
@@ -148,6 +173,8 @@ public class LettuceConnectionFactoryUnitTests {
assertThat(redisUri.isSsl(), is(true));
assertThat(connectionFactory.isUseSsl(), is(true));
assertThat(redisUri.isVerifyPeer(), is(true));
assertThat(connectionFactory.isVerifyPeer(), is(true));
}
/**