User handler bugs WIP (#1925)

This commit is contained in:
Karl Burtram
2023-03-08 16:45:46 -08:00
committed by GitHub
parent f055e28bbc
commit 94becba176
2 changed files with 33 additions and 32 deletions

View File

@@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.SqlServer.Management.Common;
@@ -199,7 +198,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
SupportSQLAuthentication = true,
Languages = new string[] { },
Schemas = currentUserPrototype.SchemaNames.ToArray(),
Logins = LoadSqlLogins(serverConnection),
Logins = DatabaseUtils.LoadSqlLogins(serverConnection),
DatabaseRoles = currentUserPrototype.DatabaseRoleNames.ToArray()
};
@@ -400,36 +399,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
}
}
}
private string[] LoadSqlLogins(ServerConnection serverConnection)
{
return LoadItems(serverConnection, "Server/Login");
}
private string[] LoadItems(ServerConnection serverConnection, string urn)
{
List<string> items = new List<string>();
Request req = new Request();
req.Urn = urn;
req.ResultType = ResultType.IDataReader;
req.Fields = new string[] { "Name" };
Enumerator en = new Enumerator();
using (IDataReader reader = en.Process(serverConnection, req).Data as IDataReader)
{
if (reader != null)
{
string name;
while (reader.Read())
{
// Get the permission name
name = reader.GetString(0);
items.Add(name);
}
}
}
return items.ToArray();
}
}
internal class UserActions : ManagementActionBase

View File

@@ -12,6 +12,7 @@ using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.Management;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Security;
@@ -245,5 +246,36 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
dataContainer.Server.ResourceGovernor.Alter();
}
}
public static string[] LoadSqlLogins(ServerConnection serverConnection)
{
return LoadItems(serverConnection, "Server/Login");
}
public static string[] LoadItems(ServerConnection serverConnection, string urn)
{
List<string> items = new List<string>();
Request req = new Request();
req.Urn = urn;
req.ResultType = ResultType.IDataReader;
req.Fields = new string[] { "Name" };
Enumerator en = new Enumerator();
using (IDataReader reader = en.Process(serverConnection, req).Data as IDataReader)
{
if (reader != null)
{
string name;
while (reader.Read())
{
// Get the permission name
name = reader.GetString(0);
items.Add(name);
}
}
}
items.Sort();
return items.ToArray();
}
}
}