Skip to content

Commit

Permalink
[SDCISA-13110] Support Redis 6.x authentication method
Browse files Browse the repository at this point in the history
- separated redisAuth and redisPassword
  • Loading branch information
thwint committed Aug 29, 2023
1 parent 701181c commit 6984674
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ private String createConnectString() {
StringBuilder connectionStringBuilder = new StringBuilder();
connectionStringBuilder.append(configuration.isRedisEnableTls() ? "rediss://" : "redis://");
String redisUser = configuration.getRedisUser();
if (StringUtils.isNotEmpty(redisUser)) {
connectionStringBuilder.append(configuration.getRedisUser()).append(":").append(configuration.getRedisAuth()).append("@");
String redisPassword = configuration.getRedisPassword();
if (StringUtils.isNotEmpty(redisUser) && StringUtils.isNotEmpty(redisPassword)) {
connectionStringBuilder.append(configuration.getRedisUser()).append(":").append(redisPassword).append("@");

Check warning on line 89 in src/main/java/org/swisspush/reststorage/DefaultRedisProvider.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/reststorage/DefaultRedisProvider.java#L89

Added line #L89 was not covered by tests
}
connectionStringBuilder.append(configuration.getRedisHost()).append(":").append(configuration.getRedisPort());
return connectionStringBuilder.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.swisspush.reststorage.util;

import io.vertx.core.json.JsonObject;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -33,7 +32,12 @@ public enum StorageType {
private String redisHost = "localhost";
private int redisPort = 6379;
private boolean redisEnableTls;
/**
* @deprecated Instance authentication is considered as legacy. With Redis from 6.x on the ACL authentication method should be used.
*/
@Deprecated(since = "3.0.17")
private String redisAuth = null;
private String redisPassword = null;
private String redisUser = null;
private String expirablePrefix = "rest-storage:expirable";
private String resourcesPrefix = "rest-storage:resources";
Expand Down Expand Up @@ -121,11 +125,17 @@ public ModuleConfiguration redisEnableTls(boolean redisEnableTls) {
return this;
}

@Deprecated(since = "3.0.17")
public ModuleConfiguration redisAuth(String redisAuth) {
this.redisAuth = redisAuth;
return this;
}

public ModuleConfiguration redisPassword(String redisPassword) {
this.redisPassword = redisPassword;
return this;

Check warning on line 136 in src/main/java/org/swisspush/reststorage/util/ModuleConfiguration.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/reststorage/util/ModuleConfiguration.java#L135-L136

Added lines #L135 - L136 were not covered by tests
}

public ModuleConfiguration redisUser(String redisUser) {
this.redisUser = redisUser;
return this;

Check warning on line 141 in src/main/java/org/swisspush/reststorage/util/ModuleConfiguration.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/reststorage/util/ModuleConfiguration.java#L140-L141

Added lines #L140 - L141 were not covered by tests
Expand Down Expand Up @@ -257,6 +267,10 @@ public String getRedisAuth() {
return redisAuth;
}

public String getRedisPassword() {
return redisPassword;
}

public String getRedisUser() {
return redisUser;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public void testGetDefaultAsJsonObject(TestContext testContext){
testContext.assertEquals(json.getInteger("redisPort"), 6379);
testContext.assertEquals(json.getInteger("maxRedisWaitingHandlers"), 2048);
testContext.assertNull(json.getString("redisAuth"));
testContext.assertNull(json.getString("redisPassword"));
testContext.assertNull(json.getString("redisUser"));
testContext.assertEquals(json.getString("expirablePrefix"), "rest-storage:expirable");
testContext.assertEquals(json.getString("resourcesPrefix"), "rest-storage:resources");
testContext.assertEquals(json.getString("collectionsPrefix"), "rest-storage:collections");
Expand Down

0 comments on commit 6984674

Please sign in to comment.