Fixed - Redis Sentinel prior 5.0.1 version doesn't require password. Regression since 3.10.5 #1981

pull/2053/head
Nikita Koksharov 6 years ago
parent ec5873bb1b
commit 1332b03ed9

@ -0,0 +1,32 @@
/**
* Copyright (c) 2013-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.client;
/**
* This error occurs when Redis requires authentication.
*
* @author Nikita Koksharov
*
*/
public class RedisAuthRequiredException extends RedisException {
private static final long serialVersionUID = -2565335188503354660L;
public RedisAuthRequiredException(String message) {
super(message);
}
}

@ -38,6 +38,7 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import org.redisson.client.RedisAskException;
import org.redisson.client.RedisAuthRequiredException;
import org.redisson.client.RedisException;
import org.redisson.client.RedisLoadingException;
import org.redisson.client.RedisMovedException;
@ -346,6 +347,9 @@ public class CommandDecoder extends ReplayingDecoder<State> {
} else if (error.contains("-OOM ")) {
data.tryFailure(new RedisOutOfMemoryException(error.split("-OOM ")[1]
+ ". channel: " + channel + " data: " + data));
} else if (error.startsWith("NOAUTH")) {
data.tryFailure(new RedisAuthRequiredException(error
+ ". channel: " + channel + " data: " + data));
} else {
if (data != null) {
data.tryFailure(new RedisException(error + ". channel: " + channel + " command: " + LogHelper.toString(data)));

@ -36,7 +36,9 @@ import java.util.function.BiConsumer;
import org.redisson.api.NodeType;
import org.redisson.api.RFuture;
import org.redisson.client.RedisAuthRequiredException;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisClientConfig;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisConnectionException;
import org.redisson.client.codec.StringCodec;
@ -75,6 +77,8 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
private ScheduledFuture<?> monitorFuture;
private AddressResolver<InetSocketAddress> sentinelResolver;
private boolean usePassword = false;
public SentinelConnectionManager(SentinelServersConfig cfg, Config config, UUID id) {
super(config, id);
@ -90,6 +94,22 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
this.sentinelResolver = resolverGroup.getResolver(getGroup().next());
for (URI addr : cfg.getSentinelAddresses()) {
RedisClient client = createClient(NodeType.SENTINEL, addr, this.config.getConnectTimeout(), this.config.getRetryInterval() * this.config.getRetryAttempts(), null);
try {
RedisConnection c = client.connect();
try {
c.sync(RedisCommands.PING);
} catch (RedisAuthRequiredException e) {
usePassword = true;
}
client.shutdown();
break;
} catch (Exception e) {
// skip
}
}
for (URI addr : cfg.getSentinelAddresses()) {
RedisClient client = createClient(NodeType.SENTINEL, addr, this.config.getConnectTimeout(), this.config.getRetryInterval() * this.config.getRetryAttempts(), null);
try {
@ -186,6 +206,16 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
scheduleSentinelDNSCheck();
}
@Override
protected RedisClientConfig createRedisConfig(NodeType type, URI address, int timeout, int commandTimeout,
String sslHostname) {
RedisClientConfig result = super.createRedisConfig(type, address, timeout, commandTimeout, sslHostname);
if (type == NodeType.SENTINEL && !usePassword) {
result.setPassword(null);
}
return result;
}
private void scheduleSentinelDNSCheck() {
monitorFuture = group.schedule(new Runnable() {

Loading…
Cancel
Save