Skip to content

Commit b3243ff

Browse files
committed
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: spring-projects#180.
1 parent 8edfb2b commit b3243ff

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
9898
private RedisClusterConfiguration clusterConfiguration;
9999
private ClusterCommandExecutor clusterCommandExecutor;
100100
private ClientResources clientResources;
101-
private boolean useSsl;
101+
private boolean useSsl = false;
102102
private boolean verifyPeer = true;
103-
private boolean startTls;
103+
private boolean startTls = false;
104104

105105
/**
106106
* Constructs a new <code>LettuceConnectionFactory</code> instance with default settings.
@@ -323,14 +323,14 @@ public void setUseSsl(boolean useSsl) {
323323
/**
324324
* Returns whether to use SSL.
325325
*
326-
* @return
326+
* @return use of SSL
327327
*/
328328
public boolean isUseSsl() {
329329
return useSsl;
330330
}
331331

332332
/**
333-
* Sets to use verify certificate validity/hostname check when SSL is used
333+
* Sets to use verify certificate validity/hostname check when SSL is used.
334334
*
335335
* @param verifyPeer {@literal false} not to verify hostname.
336336
*/
@@ -339,35 +339,34 @@ public void setVerifyPeer(boolean verifyPeer) {
339339
}
340340

341341
/**
342-
* Returns whether to verify certificate validity/hostname check when SSL is used
342+
* Returns whether to verify certificate validity/hostname check when SSL is used.
343343
*
344-
* @return
344+
* @return verify peers when using SSL
345345
*/
346346
public boolean isVerifyPeer() {
347347
return verifyPeer;
348348
}
349349

350350
/**
351-
* Returns whether to issue a StartTLS
351+
* Returns whether to issue a StartTLS.
352352
*
353-
* @return
354-
*/
353+
* @return use of StartTLS
354+
*/
355355
public boolean isStartTls() {
356356
return startTls;
357357
}
358358

359-
360359
/**
361-
* Sets to issue StartTLS
360+
* Sets to issue StartTLS.
362361
*
363-
* @param startTls {@literal true} to issue StartTLS
364-
*/
362+
* @param startTls {@literal true} to issue StartTLS.
363+
*/
365364
public void setStartTls(boolean startTls) {
366365
this.startTls = startTls;
367366
}
368367

369368
/**
370-
* Indicates if validation of the native Lettuce connection is enabled
369+
* Indicates if validation of the native Lettuce connection is enabled.
371370
*
372371
* @return connection validation enabled
373372
*/
@@ -594,10 +593,12 @@ private AbstractRedisClient createRedisClient() {
594593
if (password != null) {
595594
builder.withPassword(password);
596595
}
596+
597597
builder.withSsl(useSsl);
598598
builder.withVerifyPeer(verifyPeer);
599599
builder.withStartTls(startTls);
600600
builder.withTimeout(timeout, TimeUnit.MILLISECONDS);
601+
601602
if (clientResources != null) {
602603
return RedisClient.create(clientResources, builder.build());
603604
}

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/**
3838
* @author Christoph Strobl
3939
* @author Mark Paluch
40+
* @author Balázs Németh
4041
*/
4142
public class LettuceConnectionFactoryUnitTests {
4243

@@ -129,6 +130,30 @@ public void clusterClientShouldInitializeWithoutClientResources() {
129130
assertThat(client, instanceOf(RedisClusterClient.class));
130131
}
131132

133+
/**
134+
* @see DATAREDIS-480
135+
*/
136+
@Test
137+
public void sslOptionsShouldBeDisabledByDefaultOnClient() {
138+
139+
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
140+
connectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
141+
connectionFactory.afterPropertiesSet();
142+
ConnectionFactoryTracker.add(connectionFactory);
143+
144+
AbstractRedisClient client = (AbstractRedisClient) getField(connectionFactory, "client");
145+
assertThat(client, instanceOf(RedisClient.class));
146+
147+
RedisURI redisUri = (RedisURI) getField(client, "redisURI");
148+
149+
assertThat(redisUri.isSsl(), is(false));
150+
assertThat(connectionFactory.isUseSsl(), is(false));
151+
assertThat(redisUri.isStartTls(), is(false));
152+
assertThat(connectionFactory.isStartTls(), is(false));
153+
assertThat(redisUri.isVerifyPeer(), is(true));
154+
assertThat(connectionFactory.isVerifyPeer(), is(true));
155+
}
156+
132157
/**
133158
* @see DATAREDIS-476
134159
*/
@@ -148,6 +173,8 @@ public void sslShouldBeSetCorrectlyOnClient() {
148173

149174
assertThat(redisUri.isSsl(), is(true));
150175
assertThat(connectionFactory.isUseSsl(), is(true));
176+
assertThat(redisUri.isVerifyPeer(), is(true));
177+
assertThat(connectionFactory.isVerifyPeer(), is(true));
151178
}
152179

153180
/**

0 commit comments

Comments
 (0)