Unverified Commit 84bce912 authored by Marc Gravell's avatar Marc Gravell Committed by GitHub

allow auth with user (redis 6) (#1410)

parent 8349c04f
...@@ -76,6 +76,7 @@ internal const string ...@@ -76,6 +76,7 @@ internal const string
HighPrioritySocketThreads = "highPriorityThreads", HighPrioritySocketThreads = "highPriorityThreads",
KeepAlive = "keepAlive", KeepAlive = "keepAlive",
ClientName = "name", ClientName = "name",
User = "user",
Password = "password", Password = "password",
PreserveAsyncOrder = "preserveAsyncOrder", PreserveAsyncOrder = "preserveAsyncOrder",
Proxy = "proxy", Proxy = "proxy",
...@@ -104,6 +105,7 @@ internal const string ...@@ -104,6 +105,7 @@ internal const string
DefaultDatabase, DefaultDatabase,
HighPrioritySocketThreads, HighPrioritySocketThreads,
KeepAlive, KeepAlive,
User,
Password, Password,
PreserveAsyncOrder, PreserveAsyncOrder,
Proxy, Proxy,
...@@ -305,6 +307,11 @@ public int ConnectTimeout ...@@ -305,6 +307,11 @@ public int ConnectTimeout
public int KeepAlive { get { return keepAlive.GetValueOrDefault(-1); } set { keepAlive = value; } } public int KeepAlive { get { return keepAlive.GetValueOrDefault(-1); } set { keepAlive = value; } }
#pragma warning restore RCS1128 // Use coalesce expression. #pragma warning restore RCS1128 // Use coalesce expression.
/// <summary>
/// The user to use to authenticate with the server.
/// </summary>
public string User { get; set; }
/// <summary> /// <summary>
/// The password to use to authenticate with the server. /// The password to use to authenticate with the server.
/// </summary> /// </summary>
...@@ -441,6 +448,7 @@ public ConfigurationOptions Clone() ...@@ -441,6 +448,7 @@ public ConfigurationOptions Clone()
allowAdmin = allowAdmin, allowAdmin = allowAdmin,
defaultVersion = defaultVersion, defaultVersion = defaultVersion,
connectTimeout = connectTimeout, connectTimeout = connectTimeout,
User = User,
Password = Password, Password = Password,
tieBreaker = tieBreaker, tieBreaker = tieBreaker,
writeBuffer = writeBuffer, writeBuffer = writeBuffer,
...@@ -505,6 +513,7 @@ public string ToString(bool includePassword) ...@@ -505,6 +513,7 @@ public string ToString(bool includePassword)
Append(sb, OptionKeys.AllowAdmin, allowAdmin); Append(sb, OptionKeys.AllowAdmin, allowAdmin);
Append(sb, OptionKeys.Version, defaultVersion); Append(sb, OptionKeys.Version, defaultVersion);
Append(sb, OptionKeys.ConnectTimeout, connectTimeout); Append(sb, OptionKeys.ConnectTimeout, connectTimeout);
Append(sb, OptionKeys.User, User);
Append(sb, OptionKeys.Password, (includePassword || string.IsNullOrEmpty(Password)) ? Password : "*****"); Append(sb, OptionKeys.Password, (includePassword || string.IsNullOrEmpty(Password)) ? Password : "*****");
Append(sb, OptionKeys.TieBreaker, tieBreaker); Append(sb, OptionKeys.TieBreaker, tieBreaker);
Append(sb, OptionKeys.WriteBuffer, writeBuffer); Append(sb, OptionKeys.WriteBuffer, writeBuffer);
...@@ -597,9 +606,10 @@ private static void Append(StringBuilder sb, string prefix, object value) ...@@ -597,9 +606,10 @@ private static void Append(StringBuilder sb, string prefix, object value)
private void Clear() private void Clear()
{ {
ClientName = ServiceName = Password = tieBreaker = sslHost = configChannel = null; ClientName = ServiceName = User =Password = tieBreaker = sslHost = configChannel = null;
keepAlive = syncTimeout = asyncTimeout = connectTimeout = writeBuffer = connectRetry = configCheckSeconds = DefaultDatabase = null; keepAlive = syncTimeout = asyncTimeout = connectTimeout = writeBuffer = connectRetry = configCheckSeconds = DefaultDatabase = null;
allowAdmin = abortOnConnectFail = highPrioritySocketThreads = resolveDns = ssl = null; allowAdmin = abortOnConnectFail = highPrioritySocketThreads = resolveDns = ssl = null;
SslProtocols = null;
defaultVersion = null; defaultVersion = null;
EndPoints.Clear(); EndPoints.Clear();
commandMap = null; commandMap = null;
...@@ -686,6 +696,9 @@ private void DoParse(string configuration, bool ignoreUnknown) ...@@ -686,6 +696,9 @@ private void DoParse(string configuration, bool ignoreUnknown)
case OptionKeys.Version: case OptionKeys.Version:
DefaultVersion = OptionKeys.ParseVersion(key, value); DefaultVersion = OptionKeys.ParseVersion(key, value);
break; break;
case OptionKeys.User:
User = value;
break;
case OptionKeys.Password: case OptionKeys.Password:
Password = value; Password = value;
break; break;
......
...@@ -753,8 +753,16 @@ private async Task HandshakeAsync(PhysicalConnection connection, LogProxy log) ...@@ -753,8 +753,16 @@ private async Task HandshakeAsync(PhysicalConnection connection, LogProxy log)
return; return;
} }
Message msg; Message msg;
string password = Multiplexer.RawConfig.Password; // note that we need "" (not null) for password in the case of 'nopass' logins
if (!string.IsNullOrWhiteSpace(password)) string user = Multiplexer.RawConfig.User, password = Multiplexer.RawConfig.Password ?? "";
if (!string.IsNullOrWhiteSpace(user))
{
log?.WriteLine("Authenticating (user/password)");
msg = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.AUTH, (RedisValue)user, (RedisValue)password);
msg.SetInternalCall();
await WriteDirectOrQueueFireAndForgetAsync(connection, msg, ResultProcessor.DemandOK).ForAwait();
}
else if (!string.IsNullOrWhiteSpace(password))
{ {
log?.WriteLine("Authenticating (password)"); log?.WriteLine("Authenticating (password)");
msg = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.AUTH, (RedisValue)password); msg = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.AUTH, (RedisValue)password);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment