forked from redis/lettuce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated authentication to support Supplier<Credentials> redis#1774
- Loading branch information
Showing
12 changed files
with
435 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.lettuce.core; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Value object representing credentials used to authenticate with Redis. | ||
* | ||
* @author Jon Iantosca | ||
* @since 6.2 | ||
*/ | ||
public class Credentials { | ||
|
||
private String username; | ||
|
||
private char[] password; | ||
|
||
public Credentials(char[] password) { | ||
this(null, password); | ||
} | ||
|
||
public Credentials(String username, char[] password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public boolean hasUsername() { | ||
return username != null && !username.isEmpty(); | ||
} | ||
|
||
public char[] getPassword() { | ||
return password; | ||
} | ||
|
||
public boolean hasPassword() { | ||
return password != null && password.length > 0; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof Credentials)) { | ||
return false; | ||
} | ||
Credentials credentials = (Credentials) o; | ||
|
||
return Objects.equals(username, credentials.username) && Arrays.equals(password, credentials.password); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(username) + Arrays.hashCode(password); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/io/lettuce/core/DefaultCredentialsSupplier.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,57 @@ | ||
package io.lettuce.core; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Internal {@link Supplier<Credentials>} with support to delegate to a client supplied {@link Supplier<Credentials>}. | ||
* | ||
* @author Jon Iantosca | ||
* @since 6.2 | ||
*/ | ||
class DefaultCredentialsSupplier implements Supplier<Credentials> { | ||
|
||
private String username; | ||
|
||
private char[] password; | ||
|
||
private Supplier<Credentials> delegate; | ||
|
||
DefaultCredentialsSupplier() { | ||
} | ||
|
||
DefaultCredentialsSupplier(char[] password) { | ||
this(null, password); | ||
} | ||
|
||
DefaultCredentialsSupplier(String username, char[] password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
|
||
@Override | ||
public Credentials get() { | ||
return hasDelegate() ? delegate.get() : new Credentials(this.username, this.password); | ||
} | ||
|
||
void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
void setPassword(char[] password) { | ||
this.password = password; | ||
} | ||
|
||
Supplier<Credentials> getCredentialsSupplier() { | ||
return hasDelegate() ? delegate : this; | ||
} | ||
|
||
void setDelegate(Supplier<Credentials> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
boolean hasDelegate() { | ||
return delegate != null; | ||
} | ||
|
||
} |
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
Oops, something went wrong.