
io.lettuce.core.StaticCredentialsProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lettuce-core Show documentation
Show all versions of lettuce-core Show documentation
Advanced and thread-safe Java Redis client for synchronous, asynchronous, and
reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs
and much more.
The newest version!
package io.lettuce.core;
import reactor.core.publisher.Mono;
import io.lettuce.core.internal.LettuceAssert;
/**
* Static implementation of {@link RedisCredentialsProvider}.
*
* @author Mark Paluch
* @since 6.2
*/
public class StaticCredentialsProvider
implements RedisCredentialsProvider, RedisCredentialsProvider.ImmediateRedisCredentialsProvider {
private final RedisCredentials credentials;
private final Mono mono;
/**
* Create a static {@link StaticCredentialsProvider} object from {@code username} and {@code password}.
*
* @param username can be {@code null}.
* @param password can be {@code null}.
*/
public StaticCredentialsProvider(String username, char[] password) {
this(RedisCredentials.just(username, password));
}
/**
* Create a static {@link StaticCredentialsProvider} object from {@link RedisCredentials}. The snapshot of the given
* credentials is used to create a static representation to avoid credentials changes if the {@link RedisCredentials} change
* over time.
*
* @param credentials must not be {@code null}.
*/
public StaticCredentialsProvider(RedisCredentials credentials) {
LettuceAssert.notNull(credentials, "RedisCredentials must not be null");
this.credentials = RedisCredentials.just(credentials.getUsername(), credentials.getPassword());
this.mono = Mono.just(credentials);
}
@Override
public Mono resolveCredentials() {
return mono;
}
@Override
public RedisCredentials resolveCredentialsNow() {
return this.credentials;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy