User creation handler clean-ups (#1867)

* Wire up init user message

* Send schema list

* Load database roles

* Add create user

* Add a delete user handler and format service file
This commit is contained in:
Karl Burtram
2023-02-17 08:38:17 -08:00
committed by GitHub
parent 74dd15c868
commit 675427c690
9 changed files with 487 additions and 373 deletions

View File

@@ -3,55 +3,40 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
#nullable disable
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts
{
[JsonConverter(typeof(StringEnumConverter))]
public enum ServerAuthenticationType
{
[EnumMember(Value = "Windows")]
Windows,
[EnumMember(Value = "Sql")]
Sql,
[EnumMember(Value = "AAD")]
AzureActiveDirectory
}
[JsonConverter(typeof(StringEnumConverter))]
public enum DatabaseUserType
{
[EnumMember(Value = "UserWithLogin")]
UserWithLogin,
[EnumMember(Value = "UserWithoutLogin")]
UserWithoutLogin
// User with a server level login.
[EnumMember(Value = "WithLogin")]
WithLogin,
// User based on a Windows user/group that has no login, but can connect to the Database Engine through membership in a Windows group.
[EnumMember(Value = "WithWindowsGroupLogin")]
WithWindowsGroupLogin,
// Contained user, authentication is done within the database.
[EnumMember(Value = "Contained")]
Contained,
// User that cannot authenticate.
[EnumMember(Value = "NoConnectAccess")]
NoConnectAccess
}
public class ExtendedProperty
{
public string Name { get; set; }
public string Value { get; set; }
}
public class SqlObject
{
public string Name { get; set; }
public string Path { get; set; }
}
public class Permission
{
public string Name { get; set; }
public bool Grant { get; set; }
public bool WithGrant { get; set; }
public bool Deny { get; set; }
}
public class SecurablePermissions
{
public SqlObject Securable { get; set; }
public Permission[] Permissions { get; set; }
}
/// <summary>
/// a class for storing various user properties
@@ -60,69 +45,44 @@ namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts
{
public DatabaseUserType? Type { get; set; }
public string UserName { get; set; }
public string? Name { get; set; }
public string LoginName { get; set; }
public string? LoginName { get; set; }
public string Password { get; set; }
public string? Password { get; set; }
public string DefaultSchema { get; set; }
public string? DefaultSchema { get; set; }
public string[] OwnedSchemas { get; set; }
public string[]? OwnedSchemas { get; set; }
public bool isEnabled { get; set; }
public string[]? DatabaseRoles { get; set; }
public bool isAAD { get; set; }
public ServerAuthenticationType AuthenticationType { get; set; }
public ExtendedProperty[]? ExtendedProperties { get; set; }
public string? DefaultLanguage { get; set; }
}
public SecurablePermissions[]? SecurablePermissions { get; set; }
/// <summary>
/// The information required to render the user view.
/// </summary>
public class UserViewInfo
{
public UserInfo? ObjectInfo { get; set; }
public bool SupportContainedUser { get; set; }
public bool SupportWindowsAuthentication { get; set; }
public bool SupportAADAuthentication { get; set; }
public bool SupportSQLAuthentication { get; set; }
public string[]? Languages { get; set; }
public string[]? Schemas { get; set; }
public string[]? Logins { get; set; }
public string[]? DatabaseRoles { get; set; }
}
}
#if false
export interface ServerRole extends SqlObject {
owner: string | undefined;
securablePermissions: SecurablePermissions[];
members: SqlObject[];
memberships: SqlObject[];
isFixedRole: boolean;
}
export interface ServerLogin extends SqlObject {
type: LoginType;
password: string | undefined;
oldPassword: string | undefined;
enforcePasswordPolicy: boolean | undefined;
enforcePasswordExpiration: boolean | undefined;
defaultDatabase: string;
defaultLanguage: string;
serverRoles: string[];
userMapping: ServerLoginDatabaseUserMapping[];
isGroup: boolean;
isEnabled: boolean;
connectPermission: boolean;
isLockedOut: boolean;
}
export interface ServerLoginDatabaseUserMapping {
database: string;
user: string;
defaultSchema: string;
databaseRoles: string[];
}
export interface DatabaseRole extends SqlObject {
owner: string | undefined;
password: string | undefined;
ownedSchemas: string[];
securablePermissions: SecurablePermissions[] | undefined;
extendedProperties: ExtendedProperty[] | undefined;
isFixedRole: boolean;
}
#endif

View File

@@ -8,15 +8,43 @@ using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts
{
{
/// <summary>
/// Initialize User View parameters
/// </summary>
public class InitializeUserViewParams
{
public string? ContextId { get; set; }
public string? ConnectionUri { get; set; }
public bool isNewObject { get; set; }
public string? Database { get; set; }
public string? Name { get; set; }
}
/// <summary>
/// Initialize User View request type
/// </summary>
public class InitializeUserViewRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly
RequestType<InitializeUserViewParams, UserViewInfo> Type =
RequestType<InitializeUserViewParams, UserViewInfo>.Create("objectManagement/initializeUserView");
}
/// <summary>
/// Create User parameters
/// </summary>
public class CreateUserParams : GeneralRequestDetails
{
public string OwnerUri { get; set; }
public UserInfo User { get; set; }
public string? ContextId { get; set; }
public UserInfo? User { get; set; }
}
/// <summary>
@@ -24,10 +52,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts
/// </summary>
public class CreateUserResult : ResultStatus
{
public UserInfo User { get; set; }
public UserInfo? User { get; set; }
}
/// <summary>
/// Create User request type
/// </summary>
@@ -38,17 +65,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts
/// </summary>
public static readonly
RequestType<CreateUserParams, CreateUserResult> Type =
RequestType<CreateUserParams, CreateUserResult>.Create("objectmanagement/createuser");
RequestType<CreateUserParams, CreateUserResult>.Create("objectManagement/createUser");
}
/// <summary>
/// Delete User params
/// </summary>
public class DeleteUserParams : GeneralRequestDetails
public class DeleteUserParams
{
public string OwnerUri { get; set; }
public string UserName { get; set; }
public string? ConnectionUri { get; set; }
public string? Database { get; set; }
public string? Name { get; set; }
}
/// <summary>
@@ -61,6 +90,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts
/// </summary>
public static readonly
RequestType<DeleteUserParams, ResultStatus> Type =
RequestType<DeleteUserParams, ResultStatus>.Create("objectmanagement/deleteuser");
RequestType<DeleteUserParams, ResultStatus>.Create("objectManagement/deleteUser");
}
}