-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce credentials provider (#3224)
References: 1. #1602 and related PRs. Current PR is probably better than handling in JedisFactory 2. redis/redis-py#2261 - main reason of this PR 3. redis/lettuce#1774 4. #632 --- * Introduce credentials provider * use volatile * Test in Sentineled mode * Support CharSequence in DefaultRedisCredentials * Added doc for prepare() and cleanUp() * Test the provider interface * Added example * Removed deprecations
- Loading branch information
Showing
15 changed files
with
439 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/redis/clients/jedis/DefaultRedisCredentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package redis.clients.jedis; | ||
|
||
public final class DefaultRedisCredentials implements RedisCredentials { | ||
|
||
private final String user; | ||
private final char[] password; | ||
|
||
public DefaultRedisCredentials(String user, char[] password) { | ||
this.user = user; | ||
this.password = password; | ||
} | ||
|
||
public DefaultRedisCredentials(String user, CharSequence password) { | ||
this.user = user; | ||
this.password = password == null ? null | ||
: password instanceof String ? ((String) password).toCharArray() | ||
: toCharArray(password); | ||
} | ||
|
||
@Override | ||
public String getUser() { | ||
return user; | ||
} | ||
|
||
@Override | ||
public char[] getPassword() { | ||
return password; | ||
} | ||
|
||
private static char[] toCharArray(CharSequence seq) { | ||
final int len = seq.length(); | ||
char[] arr = new char[len]; | ||
for (int i = 0; i < len; i++) { | ||
arr[i] = seq.charAt(i); | ||
} | ||
return arr; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/redis/clients/jedis/DefaultRedisCredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package redis.clients.jedis; | ||
|
||
public final class DefaultRedisCredentialsProvider implements RedisCredentialsProvider { | ||
|
||
private volatile RedisCredentials credentials; | ||
|
||
public DefaultRedisCredentialsProvider(RedisCredentials credentials) { | ||
this.credentials = credentials; | ||
} | ||
|
||
public void setCredentials(RedisCredentials credentials) { | ||
this.credentials = credentials; | ||
} | ||
|
||
@Override | ||
public RedisCredentials get() { | ||
return this.credentials; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package redis.clients.jedis; | ||
|
||
public interface RedisCredentials { | ||
|
||
/** | ||
* @return Redis ACL user | ||
*/ | ||
default String getUser() { | ||
return null; | ||
} | ||
|
||
default char[] getPassword() { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.