[User Management] Fix a few bugs in login handlers (#1897)

This commit is contained in:
Hai Cao
2023-03-03 10:37:53 -08:00
committed by GitHub
parent eda17d165d
commit e721a44588

View File

@@ -864,6 +864,10 @@ INNER JOIN sys.sql_logins AS sql_logins
internal class LoginPrototype internal class LoginPrototype
{ {
private SqlCollationSensitiveStringComparer comparer = null; private SqlCollationSensitiveStringComparer comparer = null;
private static string AZURE_SERVER_ROLE_ALTER_QUERY =
@"ALTER SERVER ROLE {0}
{1} MEMBER [{2}]";
/// <summary> /// <summary>
/// string of asterisks to display in lieu of the actual password /// string of asterisks to display in lieu of the actual password
@@ -912,7 +916,7 @@ INNER JOIN sys.sql_logins AS sql_logins
private bool initialized = false; private bool initialized = false;
private Login login = null; private Login login = null;
private Microsoft.SqlServer.Management.Smo.Server server; private Microsoft.SqlServer.Management.Smo.Server server;
private static string defaultLanguageDisplay; private static string defaultLanguageDisplay = string.Empty;
private bool windowsAuthSupported = true; private bool windowsAuthSupported = true;
private bool aadAuthSupported = false; private bool aadAuthSupported = false;
@@ -1352,6 +1356,7 @@ INNER JOIN sys.sql_logins AS sql_logins
{ {
LoginType = SqlServer.Management.Smo.LoginType.SqlLogin; LoginType = SqlServer.Management.Smo.LoginType.SqlLogin;
} }
LoadData();
} }
/// <summary> /// <summary>
@@ -2088,7 +2093,9 @@ INNER JOIN sys.sql_logins AS sql_logins
this.SqlPassword = login.Password; this.SqlPassword = login.Password;
this.OldPassword = login.OldPassword; this.OldPassword = login.OldPassword;
this.LoginType = GetLoginType(login); this.LoginType = GetLoginType(login);
if (this.DefaultLanguage != null && 0 != String.Compare(login.DefaultLanguage, SR.DefaultLanguagePlaceholder, StringComparison.Ordinal)) if (this.DefaultLanguage != null
&& 0 != String.Compare(login.DefaultLanguage, SR.DefaultLanguagePlaceholder, StringComparison.Ordinal)
&& (server.DatabaseEngineType == DatabaseEngineType.Standalone|| server.DatabaseEngineEdition == DatabaseEngineEdition.SqlManagedInstance))
{ {
this.DefaultLanguage = login.DefaultLanguage.Split(" - ")[1]; this.DefaultLanguage = login.DefaultLanguage.Split(" - ")[1];
} }
@@ -2396,12 +2403,14 @@ INNER JOIN sys.sql_logins AS sql_logins
// if the login is currently a member of the role, but wasn't originally a member, add the login to the role // if the login is currently a member of the role, but wasn't originally a member, add the login to the role
if (isCurrentlyARoleMember && !wasOriginallyARoleMember) if (isCurrentlyARoleMember && !wasOriginallyARoleMember)
{ {
//run query to add // run query to add
server.ExecutionManager.ConnectionContext.ExecuteNonQuery(string.Format(AZURE_SERVER_ROLE_ALTER_QUERY, role, "ADD", this.LoginName));
} }
// if the login is not currently a member of the role, but originally was a member, remove the login from the role // if the login is not currently a member of the role, but originally was a member, remove the login from the role
else if (!isCurrentlyARoleMember && wasOriginallyARoleMember) else if (!isCurrentlyARoleMember && wasOriginallyARoleMember)
{ {
//run query to drop //run query to drop
server.ExecutionManager.ConnectionContext.ExecuteNonQuery(string.Format(AZURE_SERVER_ROLE_ALTER_QUERY, role, "DROP", this.LoginName));
} }
} }
} }