move object management interfaces (#23358)

This commit is contained in:
Alan Ren
2023-06-08 12:46:44 -07:00
committed by GitHub
parent f9b4c52211
commit 7886b28565
11 changed files with 522 additions and 509 deletions

View File

@@ -0,0 +1,441 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ObjectManagement } from 'mssql';
/**
* Base interface for all the security principal objects. e.g. Login, Server Role, Database Role...
*/
export interface SecurityPrincipalObject extends ObjectManagement.SqlObject {
securablePermissions: SecurablePermissions[];
}
/**
* Securable type metadata.
*/
export interface SecurableTypeMetadata {
/**
* Name of the securable type.
*/
name: string;
/**
* Display name of the securable type.
*/
displayName: string;
/**
* Permissions supported by the securable type.
*/
permissions: PermissionMetadata[];
}
/**
* Permission metadata.
*/
export interface PermissionMetadata {
/**
* Name of the permission.
*/
name: string;
/**
* Display name of the permission.
*/
displayName: string;
}
/**
* Base interface for security principal object's view information.
*/
export interface SecurityPrincipalViewInfo<T extends SecurityPrincipalObject> extends ObjectManagement.ObjectViewInfo<T> {
/**
* The securable types that the security principal object can be granted permissions on.
*/
supportedSecurableTypes: SecurableTypeMetadata[];
}
/**
* Base interface for database level security principal object's view information.
*/
export interface DatabaseLevelPrincipalViewInfo<T extends SecurityPrincipalObject> extends SecurityPrincipalViewInfo<T> {
/**
* The schemas in the database.
*/
schemas: string[];
}
/**
* Server level login.
*/
export interface Login extends SecurityPrincipalObject {
/**
* Authentication type.
*/
authenticationType: AuthenticationType;
/**
* Password for the login.
* Only applicable when the authentication type is 'Sql'.
*/
password: string | undefined;
/**
* Old password of the login.
* Only applicable when the authentication type is 'Sql'.
* The old password is required when updating the login's own password and it doesn't have the 'ALTER ANY LOGIN' permission.
*/
oldPassword: string | undefined;
/**
* Whether the password complexity policy is enforced.
* Only applicable when the authentication type is 'Sql'.
*/
enforcePasswordPolicy: boolean | undefined;
/**
* Whether the password expiration policy is enforced.
* Only applicable when the authentication type is 'Sql'.
*/
enforcePasswordExpiration: boolean | undefined;
/**
* Whether SQL Server should prompt for an updated password when the next the login is used.
* Only applicable when the authentication type is 'Sql'.
*/
mustChangePassword: boolean | undefined;
/**
* Whether the login is locked out due to password policy violation.
* Only applicable when the authentication type is 'Sql'.
*/
isLockedOut: boolean;
/**
* The default database for the login.
*/
defaultDatabase: string;
/**
* The default language for the login.
*/
defaultLanguage: string;
/**
* The server roles of the login.
*/
serverRoles: string[];
/**
* The database users the login is mapped to.
*/
userMapping: ServerLoginUserInfo[];
/**
* Whether the login is enabled.
*/
isEnabled: boolean;
/**
* Whether the connect permission is granted to the login.
*/
connectPermission: boolean;
}
/**
* The authentication types.
*/
export const enum AuthenticationType {
Windows = 'Windows',
Sql = 'Sql',
AzureActiveDirectory = 'AAD'
}
/**
* The user mapping information for login.
*/
export interface ServerLoginUserInfo {
/**
* Target database name.
*/
database: string;
/**
* User name.
*/
user: string;
/**
* Default schema of the user.
*/
defaultSchema: string;
/**
* Databases roles of the user.
*/
databaseRoles: string[];
}
/**
* The information required to render the login view.
*/
export interface LoginViewInfo extends SecurityPrincipalViewInfo<Login> {
/**
* The authentication types supported by the server.
*/
authenticationTypes: AuthenticationType[];
/**
* Whether the locked out state can be changed.
*/
canEditLockedOutState: boolean;
/**
* Name of the databases in the server.
*/
databases: string[];
/**
* Available languages in the server.
*/
languages: string[];
/**
* All server roles in the server.
*/
serverRoles: string[];
/**
* Whether advanced password options are supported.
* Advanced password options: check policy, check expiration, must change, unlock.
* Notes: 2 options to control the advanced options because Analytics Platform supports advanced options but does not support advanced options.
*/
supportAdvancedPasswordOptions: boolean;
/**
* Whether advanced options are supported.
* Advanced options: default database, default language and connect permission.
*/
supportAdvancedOptions: boolean;
}
/**
* The permission information a principal has on a securable.
*/
export interface SecurablePermissionItem {
/**
* name of the permission.
*/
permission: string;
/**
* Name of the grantor.
*/
grantor: string;
/**
* Whether the permission is granted or denied. Undefined means not specified.
*/
grant?: boolean;
/**
* Whether the pincipal can grant this permission to other principals.
* The value will be ignored if the grant property is set to false.
*/
withGrant?: boolean;
}
/**
* The permissions a principal has over a securable.
*/
export interface SecurablePermissions {
/**
* The securable name.
*/
name: string;
/**
* The securable type.
*/
type: string;
/**
* The schema name of the object if applicable.
*/
schema?: string;
/**
* The permissions.
*/
permissions: SecurablePermissionItem[];
/**
* The effective permissions. Includes all permissions granted to the principal, including those granted through role memberships.
*/
effectivePermissions: string[];
}
/**
* Extend property for objects.
*/
export interface ExtendedProperty {
/**
* Name of the property.
*/
name: string;
/**
* Value of the property.
*/
value: string;
}
/**
* User types.
*/
export const enum UserType {
/**
* Mapped to a server login.
*/
LoginMapped = 'LoginMapped',
/**
* Mapped to a Windows user or group.
*/
WindowsUser = 'WindowsUser',
/**
* Authenticate with password.
*/
SqlAuthentication = 'SqlAuthentication',
/**
* Authenticate with Azure Active Directory.
*/
AADAuthentication = 'AADAuthentication',
/**
* User that cannot authenticate.
*/
NoLoginAccess = 'NoLoginAccess'
}
/**
* Database user.
*/
export interface User extends SecurityPrincipalObject {
/**
* Type of the user.
*/
type: UserType;
/**
* Default schema of the user.
*/
defaultSchema: string | undefined;
/**
* Schemas owned by the user.
*/
ownedSchemas: string[];
/**
* Database roles that the user belongs to.
*/
databaseRoles: string[];
/**
* The name of the server login associated with the user.
* Only applicable when the user type is 'WithLogin'.
*/
loginName: string | undefined;
/**
* The default language of the user.
* Only applicable when the user type is 'Contained'.
*/
defaultLanguage: string | undefined;
/**
* Password of the user.
* Only applicable when the user type is 'Contained' and the authentication type is 'Sql'.
*/
password: string | undefined;
}
/**
* The information required to render the user view.
*/
export interface UserViewInfo extends DatabaseLevelPrincipalViewInfo<User> {
/**
* All user types supported by the database.
*/
userTypes: UserType[];
/**
* All languages supported by the database.
*/
languages: string[];
/**
* Name of all the logins in the server.
*/
logins: string[];
/**
* Name of all the database roles.
*/
databaseRoles: string[];
}
/**
* Interface representing the server role object.
*/
export interface ServerRoleInfo extends SecurityPrincipalObject {
/**
* Name of the server principal that owns the server role.
*/
owner: string;
/**
* Name of the server principals that are members of the server role.
*/
members: string[];
/**
* Server roles that the server role is a member of.
*/
memberships: string[];
}
/**
* Interface representing the information required to render the server role view.
*/
export interface ServerRoleViewInfo extends SecurityPrincipalViewInfo<ServerRoleInfo> {
/**
* Whether the server role is a fixed role.
*/
isFixedRole: boolean;
/**
* List of all the server roles.
*/
serverRoles: string[];
}
/**
* Interface representing the application role object.
*/
export interface ApplicationRoleInfo extends SecurityPrincipalObject {
/**
* Default schema of the application role.
*/
defaultSchema: string;
/**
* Schemas owned by the application role.
*/
ownedSchemas: string[];
/**
* Password of the application role.
*/
password: string;
}
/**
* Interface representing the information required to render the application role view.
*/
export interface ApplicationRoleViewInfo extends DatabaseLevelPrincipalViewInfo<ApplicationRoleInfo> {
}
/**
* Interface representing the database role object.
*/
export interface DatabaseRoleInfo extends SecurityPrincipalObject {
/**
* Name of the database principal that owns the database role.
*/
owner: string;
/**
* Schemas owned by the database role.
*/
ownedSchemas: string[];
/**
* Name of the user or database role that are members of the database role.
*/
members: string[];
}
/**
* Interface representing the information required to render the database role view.
*/
export interface DatabaseRoleViewInfo extends DatabaseLevelPrincipalViewInfo<DatabaseRoleInfo> {
}
export interface Database extends ObjectManagement.SqlObject {
owner?: string;
collationName?: string;
recoveryModel?: string;
compatibilityLevel?: string;
containmentType?: string;
}
export interface DatabaseViewInfo extends ObjectManagement.ObjectViewInfo<Database> {
loginNames: string[];
collationNames: string[];
compatibilityLevels: string[];
containmentTypes: string[];
recoveryModels: string[];
}

View File

@@ -6,6 +6,7 @@
import * as nls from 'vscode-nls';
import { ObjectManagement } from 'mssql';
import { ObjectTypeInfo } from './ui/findObjectDialog';
import { AuthenticationType, UserType } from './interfaces';
const localize = nls.loadMessageBundle();
// Object Types
@@ -242,19 +243,19 @@ export function getNodeTypeDisplayName(type: string, inTitle: boolean = false):
}
}
const AuthencationTypeDisplayNameMap = new Map<ObjectManagement.AuthenticationType, string>();
AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.Windows, WindowsAuthenticationTypeDisplayText);
AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.Sql, SQLAuthenticationTypeDisplayText);
AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.AzureActiveDirectory, AADAuthenticationTypeDisplayText);
const AuthencationTypeDisplayNameMap = new Map<AuthenticationType, string>();
AuthencationTypeDisplayNameMap.set(AuthenticationType.Windows, WindowsAuthenticationTypeDisplayText);
AuthencationTypeDisplayNameMap.set(AuthenticationType.Sql, SQLAuthenticationTypeDisplayText);
AuthencationTypeDisplayNameMap.set(AuthenticationType.AzureActiveDirectory, AADAuthenticationTypeDisplayText);
export function getAuthenticationTypeDisplayName(authType: ObjectManagement.AuthenticationType): string {
export function getAuthenticationTypeDisplayName(authType: AuthenticationType): string {
if (AuthencationTypeDisplayNameMap.has(authType)) {
return AuthencationTypeDisplayNameMap.get(authType);
}
throw new Error(`Unknown authentication type: ${authType}`);
}
export function getAuthenticationTypeByDisplayName(displayName: string): ObjectManagement.AuthenticationType {
export function getAuthenticationTypeByDisplayName(displayName: string): AuthenticationType {
for (let [key, value] of AuthencationTypeDisplayNameMap.entries()) {
if (value === displayName)
return key;
@@ -262,21 +263,21 @@ export function getAuthenticationTypeByDisplayName(displayName: string): ObjectM
throw new Error(`Unknown authentication type display name: ${displayName}`);
}
const UserTypeDisplayNameMap = new Map<ObjectManagement.UserType, string>();
UserTypeDisplayNameMap.set(ObjectManagement.UserType.LoginMapped, UserType_LoginMapped);
UserTypeDisplayNameMap.set(ObjectManagement.UserType.WindowsUser, UserType_WindowsUser);
UserTypeDisplayNameMap.set(ObjectManagement.UserType.SqlAuthentication, UserType_SqlAuthentication);
UserTypeDisplayNameMap.set(ObjectManagement.UserType.AADAuthentication, UserType_AADAuthentication);
UserTypeDisplayNameMap.set(ObjectManagement.UserType.NoLoginAccess, UserType_NoLoginAccess);
const UserTypeDisplayNameMap = new Map<UserType, string>();
UserTypeDisplayNameMap.set(UserType.LoginMapped, UserType_LoginMapped);
UserTypeDisplayNameMap.set(UserType.WindowsUser, UserType_WindowsUser);
UserTypeDisplayNameMap.set(UserType.SqlAuthentication, UserType_SqlAuthentication);
UserTypeDisplayNameMap.set(UserType.AADAuthentication, UserType_AADAuthentication);
UserTypeDisplayNameMap.set(UserType.NoLoginAccess, UserType_NoLoginAccess);
export function getUserTypeDisplayName(userType: ObjectManagement.UserType): string {
export function getUserTypeDisplayName(userType: UserType): string {
if (UserTypeDisplayNameMap.has(userType)) {
return UserTypeDisplayNameMap.get(userType);
}
throw new Error(`Unknown user type: ${userType}`);
}
export function getUserTypeByDisplayName(displayName: string): ObjectManagement.UserType {
export function getUserTypeByDisplayName(displayName: string): UserType {
for (let [key, value] of UserTypeDisplayNameMap.entries()) {
if (value === displayName)
return key;

View File

@@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ApplicationRoleViewInfo, AuthenticationType, DatabaseRoleViewInfo, LoginViewInfo, SecurablePermissions, SecurableTypeMetadata, ServerRoleViewInfo, User, UserType, UserViewInfo } from './interfaces';
import * as Utils from '../utils';
import * as constants from '../constants';
import * as contracts from '../contracts';
@@ -67,7 +67,7 @@ export class ObjectManagementService extends BaseService implements IObjectManag
}
}
const ServerLevelSecurableTypes: ObjectManagement.SecurableTypeMetadata[] = [
const ServerLevelSecurableTypes: SecurableTypeMetadata[] = [
{
name: 'Server',
displayName: 'Server',
@@ -94,7 +94,7 @@ const ServerLevelSecurableTypes: ObjectManagement.SecurableTypeMetadata[] = [
}
];
const DatabaseLevelSecurableTypes: ObjectManagement.SecurableTypeMetadata[] = [
const DatabaseLevelSecurableTypes: SecurableTypeMetadata[] = [
{
name: 'AggregateFunction',
displayName: 'Aggregate Function',
@@ -137,7 +137,7 @@ const DatabaseLevelSecurableTypes: ObjectManagement.SecurableTypeMetadata[] = [
}
]
const ServerLevelPermissions: ObjectManagement.SecurablePermissions[] = [
const ServerLevelPermissions: SecurablePermissions[] = [
{
name: 'Server',
type: 'Server',
@@ -158,7 +158,7 @@ const ServerLevelPermissions: ObjectManagement.SecurablePermissions[] = [
}
];
const DatabaseLevelPermissions: ObjectManagement.SecurablePermissions[] = [
const DatabaseLevelPermissions: SecurablePermissions[] = [
{
name: 'table1',
type: 'Table',
@@ -238,16 +238,16 @@ export class TestObjectManagementService implements IObjectManagementService {
return items;
}
private getLoginView(isNewObject: boolean, name: string): ObjectManagement.LoginViewInfo {
private getLoginView(isNewObject: boolean, name: string): LoginViewInfo {
const serverRoles = ['sysadmin', 'public', 'bulkadmin', 'dbcreator', 'diskadmin', 'processadmin', 'securityadmin', 'serveradmin'];
const languages = ['<default>', 'English'];
const databases = ['master', 'db1', 'db2'];
let login: ObjectManagement.LoginViewInfo;
let login: LoginViewInfo;
if (isNewObject) {
login = <ObjectManagement.LoginViewInfo>{
login = <LoginViewInfo>{
objectInfo: {
name: '',
authenticationType: ObjectManagement.AuthenticationType.Sql,
authenticationType: AuthenticationType.Sql,
enforcePasswordPolicy: true,
enforcePasswordExpiration: true,
mustChangePassword: true,
@@ -259,7 +259,7 @@ export class TestObjectManagementService implements IObjectManagementService {
isLockedOut: false,
securablePermissions: []
},
authenticationTypes: [ObjectManagement.AuthenticationType.Sql, ObjectManagement.AuthenticationType.Windows],
authenticationTypes: [AuthenticationType.Sql, AuthenticationType.Windows],
supportAdvancedOptions: true,
supportAdvancedPasswordOptions: true,
canEditLockedOutState: false,
@@ -269,10 +269,10 @@ export class TestObjectManagementService implements IObjectManagementService {
supportedSecurableTypes: ServerLevelSecurableTypes
};
} else {
login = <ObjectManagement.LoginViewInfo>{
login = <LoginViewInfo>{
objectInfo: {
name: name,
authenticationType: ObjectManagement.AuthenticationType.Sql,
authenticationType: AuthenticationType.Sql,
enforcePasswordPolicy: true,
enforcePasswordExpiration: true,
mustChangePassword: true,
@@ -285,7 +285,7 @@ export class TestObjectManagementService implements IObjectManagementService {
password: '******************',
securablePermissions: ServerLevelPermissions
},
authenticationTypes: [ObjectManagement.AuthenticationType.Sql, ObjectManagement.AuthenticationType.Windows],
authenticationTypes: [AuthenticationType.Sql, AuthenticationType.Windows],
supportAdvancedOptions: true,
supportAdvancedPasswordOptions: true,
canEditLockedOutState: false,
@@ -298,8 +298,8 @@ export class TestObjectManagementService implements IObjectManagementService {
return login;
}
private getUserView(isNewObject: boolean, name: string): ObjectManagement.UserViewInfo {
let viewInfo: ObjectManagement.UserViewInfo;
private getUserView(isNewObject: boolean, name: string): UserViewInfo {
let viewInfo: UserViewInfo;
const languages = ['<default>', 'English'];
const schemas = ['dbo', 'sys', 'alanren'];
const logins = ['sa', 'alanren', 'alanren@microsoft.com'];
@@ -307,12 +307,12 @@ export class TestObjectManagementService implements IObjectManagementService {
if (isNewObject) {
viewInfo = {
objectInfo: <ObjectManagement.User>{
objectInfo: <User>{
name: '',
type: ObjectManagement.UserType.LoginMapped,
type: UserType.LoginMapped,
defaultSchema: 'dbo',
defaultLanguage: '<default>',
authenticationType: ObjectManagement.AuthenticationType.Sql,
authenticationType: AuthenticationType.Sql,
loginName: 'sa',
ownedSchemas: [],
databaseRoles: [],
@@ -324,18 +324,18 @@ export class TestObjectManagementService implements IObjectManagementService {
logins: logins,
databaseRoles: databaseRoles,
userTypes: [
ObjectManagement.UserType.LoginMapped,
ObjectManagement.UserType.AADAuthentication,
ObjectManagement.UserType.SqlAuthentication,
ObjectManagement.UserType.NoLoginAccess
UserType.LoginMapped,
UserType.AADAuthentication,
UserType.SqlAuthentication,
UserType.NoLoginAccess
],
supportedSecurableTypes: DatabaseLevelSecurableTypes
};
} else {
viewInfo = {
objectInfo: <ObjectManagement.User>{
objectInfo: <User>{
name: name,
type: ObjectManagement.UserType.LoginMapped,
type: UserType.LoginMapped,
defaultSchema: 'dbo',
defaultLanguage: '<default>',
loginName: 'sa',
@@ -348,10 +348,10 @@ export class TestObjectManagementService implements IObjectManagementService {
logins: logins,
databaseRoles: databaseRoles,
userTypes: [
ObjectManagement.UserType.LoginMapped,
ObjectManagement.UserType.AADAuthentication,
ObjectManagement.UserType.SqlAuthentication,
ObjectManagement.UserType.NoLoginAccess
UserType.LoginMapped,
UserType.AADAuthentication,
UserType.SqlAuthentication,
UserType.NoLoginAccess
],
supportedSecurableTypes: DatabaseLevelSecurableTypes
};
@@ -359,8 +359,8 @@ export class TestObjectManagementService implements IObjectManagementService {
return viewInfo;
}
private getServerRoleView(isNewObject: boolean, name: string): ObjectManagement.ServerRoleViewInfo {
return isNewObject ? <ObjectManagement.ServerRoleViewInfo>{
private getServerRoleView(isNewObject: boolean, name: string): ServerRoleViewInfo {
return isNewObject ? <ServerRoleViewInfo>{
objectInfo: {
name: '',
members: [],
@@ -371,7 +371,7 @@ export class TestObjectManagementService implements IObjectManagementService {
isFixedRole: false,
serverRoles: ['ServerLevelServerRole 1', 'ServerLevelServerRole 2', 'ServerLevelServerRole 3', 'ServerLevelServerRole 4'],
supportedSecurableTypes: ServerLevelSecurableTypes
} : <ObjectManagement.ServerRoleViewInfo>{
} : <ServerRoleViewInfo>{
objectInfo: {
name: 'ServerLevelServerRole 1',
members: ['ServerLevelLogin 1', 'ServerLevelServerRole 2'],
@@ -385,8 +385,8 @@ export class TestObjectManagementService implements IObjectManagementService {
};
}
private getApplicationRoleView(isNewObject: boolean, name: string): ObjectManagement.ApplicationRoleViewInfo {
return isNewObject ? <ObjectManagement.ApplicationRoleViewInfo>{
private getApplicationRoleView(isNewObject: boolean, name: string): ApplicationRoleViewInfo {
return isNewObject ? <ApplicationRoleViewInfo>{
objectInfo: {
name: '',
defaultSchema: 'dbo',
@@ -395,7 +395,7 @@ export class TestObjectManagementService implements IObjectManagementService {
},
schemas: ['dbo', 'sys', 'admin'],
supportedSecurableTypes: []
} : <ObjectManagement.ApplicationRoleViewInfo>{
} : <ApplicationRoleViewInfo>{
objectInfo: {
name: 'app role1',
password: '******************',
@@ -408,8 +408,8 @@ export class TestObjectManagementService implements IObjectManagementService {
};
}
private getDatabaseRoleView(isNewObject: boolean, name: string): ObjectManagement.DatabaseRoleViewInfo {
return isNewObject ? <ObjectManagement.DatabaseRoleViewInfo>{
private getDatabaseRoleView(isNewObject: boolean, name: string): DatabaseRoleViewInfo {
return isNewObject ? <DatabaseRoleViewInfo>{
objectInfo: {
name: '',
owner: '',
@@ -419,7 +419,7 @@ export class TestObjectManagementService implements IObjectManagementService {
},
schemas: ['dbo', 'sys', 'admin'],
supportedSecurableTypes: DatabaseLevelSecurableTypes
} : <ObjectManagement.DatabaseRoleViewInfo>{
} : <DatabaseRoleViewInfo>{
objectInfo: {
name: 'db role1',
owner: '',

View File

@@ -4,14 +4,15 @@
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import { ObjectManagementDialogOptions } from './objectManagementDialogBase';
import { IObjectManagementService, ObjectManagement } from 'mssql';
import { IObjectManagementService } from 'mssql';
import * as localizedConstants from '../localizedConstants';
import { AlterApplicationRoleDocUrl, CreateApplicationRoleDocUrl } from '../constants';
import { isValidSQLPassword } from '../utils';
import { DefaultMaxTableRowCount } from '../../ui/dialogBase';
import { PrincipalDialogBase } from './principalDialogBase';
import { ApplicationRoleInfo, ApplicationRoleViewInfo } from '../interfaces';
export class ApplicationRoleDialog extends PrincipalDialogBase<ObjectManagement.ApplicationRoleInfo, ObjectManagement.ApplicationRoleViewInfo> {
export class ApplicationRoleDialog extends PrincipalDialogBase<ApplicationRoleInfo, ApplicationRoleViewInfo> {
// Sections
private generalSection: azdata.GroupContainer;
private ownedSchemasSection: azdata.GroupContainer;

View File

@@ -5,11 +5,12 @@
import * as azdata from 'azdata';
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
import { IObjectManagementService, ObjectManagement } from 'mssql';
import { IObjectManagementService } from 'mssql';
import * as localizedConstants from '../localizedConstants';
import { CreateDatabaseDocUrl } from '../constants';
import { Database, DatabaseViewInfo } from '../interfaces';
export class DatabaseDialog extends ObjectManagementDialogBase<ObjectManagement.Database, ObjectManagement.DatabaseViewInfo> {
export class DatabaseDialog extends ObjectManagementDialogBase<Database, DatabaseViewInfo> {
private _nameInput: azdata.InputBoxComponent;
constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {

View File

@@ -10,8 +10,9 @@ import { AlterDatabaseRoleDocUrl, CreateDatabaseRoleDocUrl } from '../constants'
import { FindObjectDialog } from './findObjectDialog';
import { DefaultMaxTableRowCount } from '../../ui/dialogBase';
import { PrincipalDialogBase } from './principalDialogBase';
import { DatabaseRoleInfo, DatabaseRoleViewInfo } from '../interfaces';
export class DatabaseRoleDialog extends PrincipalDialogBase<ObjectManagement.DatabaseRoleInfo, ObjectManagement.DatabaseRoleViewInfo> {
export class DatabaseRoleDialog extends PrincipalDialogBase<DatabaseRoleInfo, DatabaseRoleViewInfo> {
// Sections
private generalSection: azdata.GroupContainer;
private ownedSchemasSection: azdata.GroupContainer;

View File

@@ -5,15 +5,16 @@
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { ObjectManagementDialogOptions } from './objectManagementDialogBase';
import { IObjectManagementService, ObjectManagement } from 'mssql';
import { IObjectManagementService } from 'mssql';
import * as objectManagementLoc from '../localizedConstants';
import * as uiLoc from '../../ui/localizedConstants';
import { AlterLoginDocUrl, CreateLoginDocUrl, PublicServerRoleName } from '../constants';
import { isValidSQLPassword } from '../utils';
import { DefaultMaxTableRowCount } from '../../ui/dialogBase';
import { PrincipalDialogBase } from './principalDialogBase';
import { AuthenticationType, Login, LoginViewInfo } from '../interfaces';
export class LoginDialog extends PrincipalDialogBase<ObjectManagement.Login, ObjectManagement.LoginViewInfo> {
export class LoginDialog extends PrincipalDialogBase<Login, LoginViewInfo> {
private generalSection: azdata.GroupContainer;
private sqlAuthSection: azdata.GroupContainer;
private serverRoleSection: azdata.GroupContainer;
@@ -46,7 +47,7 @@ export class LoginDialog extends PrincipalDialogBase<ObjectManagement.Login, Obj
// Empty password is only allowed when advanced password options are supported and the password policy check is off.
// To match the SSMS behavior, a warning is shown to the user.
if (this.viewInfo.supportAdvancedPasswordOptions
&& this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql
&& this.objectInfo.authenticationType === AuthenticationType.Sql
&& !this.objectInfo.password
&& !this.objectInfo.enforcePasswordPolicy) {
const result = await vscode.window.showWarningMessage(objectManagementLoc.BlankPasswordConfirmationText, { modal: true }, uiLoc.YesText);
@@ -57,7 +58,7 @@ export class LoginDialog extends PrincipalDialogBase<ObjectManagement.Login, Obj
protected override async validateInput(): Promise<string[]> {
const errors = await super.validateInput();
if (this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql) {
if (this.objectInfo.authenticationType === AuthenticationType.Sql) {
if (!this.objectInfo.password && !(this.viewInfo.supportAdvancedPasswordOptions && !this.objectInfo.enforcePasswordPolicy)) {
errors.push(objectManagementLoc.PasswordCannotBeEmptyError);
}

View File

@@ -12,6 +12,7 @@ import { FindObjectDialog, FindObjectDialogResult } from './findObjectDialog';
import { deepClone } from '../../util/objects';
import { DefaultTableWidth, getTableHeight } from '../../ui/dialogBase';
import { ObjectSelectionMethod, ObjectSelectionMethodDialog } from './objectSelectionMethodDialog';
import { DatabaseLevelPrincipalViewInfo, SecurablePermissionItem, SecurablePermissions, SecurityPrincipalObject, SecurityPrincipalViewInfo } from '../interfaces';
const GrantColumnIndex = 2;
const WithGrantColumnIndex = 3;
@@ -25,14 +26,14 @@ export interface PrincipalDialogOptions extends ObjectManagementDialogOptions {
/**
* Base class for security principal dialogs such as user, role, etc.
*/
export abstract class PrincipalDialogBase<ObjectInfoType extends mssql.ObjectManagement.SecurityPrincipalObject, ViewInfoType extends mssql.ObjectManagement.SecurityPrincipalViewInfo<ObjectInfoType>> extends ObjectManagementDialogBase<ObjectInfoType, ViewInfoType> {
export abstract class PrincipalDialogBase<ObjectInfoType extends SecurityPrincipalObject, ViewInfoType extends SecurityPrincipalViewInfo<ObjectInfoType>> extends ObjectManagementDialogBase<ObjectInfoType, ViewInfoType> {
protected securableTable: azdata.TableComponent;
protected permissionTable: azdata.TableComponent;
protected effectivePermissionTable: azdata.TableComponent;
protected securableSection: azdata.GroupContainer;
protected explicitPermissionTableLabel: azdata.TextComponent;
protected effectivePermissionTableLabel: azdata.TextComponent;
private securablePermissions: mssql.ObjectManagement.SecurablePermissions[] = [];
private securablePermissions: SecurablePermissions[] = [];
constructor(objectManagementService: mssql.IObjectManagementService, private readonly dialogOptions: PrincipalDialogOptions) {
super(objectManagementService, dialogOptions);
@@ -82,7 +83,7 @@ export abstract class PrincipalDialogBase<ObjectInfoType extends mssql.ObjectMan
this.disposables.push(this.permissionTable.onCellAction(async (arg: azdata.ICheckboxCellActionEventArgs) => {
const permissionName = this.permissionTable.data[arg.row][0];
const securable = this.securablePermissions[this.securableTable.selectedRows[0]];
let permission: mssql.ObjectManagement.SecurablePermissionItem = securable.permissions.find(securablePermission => securablePermission.permission === permissionName);
let permission: SecurablePermissionItem = securable.permissions.find(securablePermission => securablePermission.permission === permissionName);
if (!permission) {
permission = {
permission: permissionName,
@@ -126,7 +127,7 @@ export abstract class PrincipalDialogBase<ObjectInfoType extends mssql.ObjectMan
if (this.dialogOptions.isDatabaseLevelPrincipal) {
const methodDialog = new ObjectSelectionMethodDialog({
objectTypes: this.viewInfo.supportedSecurableTypes,
schemas: (<mssql.ObjectManagement.DatabaseLevelPrincipalViewInfo<mssql.ObjectManagement.SecurityPrincipalObject>><unknown>this.viewInfo).schemas,
schemas: (<DatabaseLevelPrincipalViewInfo<SecurityPrincipalObject>><unknown>this.viewInfo).schemas,
});
await methodDialog.open();
const methodResult = await methodDialog.waitForClose();

View File

@@ -9,8 +9,9 @@ import * as localizedConstants from '../localizedConstants';
import { AlterServerRoleDocUrl, CreateServerRoleDocUrl } from '../constants';
import { FindObjectDialog } from './findObjectDialog';
import { PrincipalDialogBase } from './principalDialogBase';
import { ServerRoleInfo, ServerRoleViewInfo } from '../interfaces';
export class ServerRoleDialog extends PrincipalDialogBase<ObjectManagement.ServerRoleInfo, ObjectManagement.ServerRoleViewInfo> {
export class ServerRoleDialog extends PrincipalDialogBase<ServerRoleInfo, ServerRoleViewInfo> {
// Sections
private generalSection: azdata.GroupContainer;
private membershipSection: azdata.GroupContainer;

View File

@@ -4,14 +4,15 @@
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import { ObjectManagementDialogOptions } from './objectManagementDialogBase';
import { IObjectManagementService, ObjectManagement } from 'mssql';
import { IObjectManagementService } from 'mssql';
import * as localizedConstants from '../localizedConstants';
import { AlterUserDocUrl, CreateUserDocUrl } from '../constants';
import { isValidSQLPassword } from '../utils';
import { DefaultMaxTableRowCount } from '../../ui/dialogBase';
import { PrincipalDialogBase } from './principalDialogBase';
import { User, UserType, UserViewInfo } from '../interfaces';
export class UserDialog extends PrincipalDialogBase<ObjectManagement.User, ObjectManagement.UserViewInfo> {
export class UserDialog extends PrincipalDialogBase<User, UserViewInfo> {
private generalSection: azdata.GroupContainer;
private ownedSchemaSection: azdata.GroupContainer;
private membershipSection: azdata.GroupContainer;
@@ -45,7 +46,7 @@ export class UserDialog extends PrincipalDialogBase<ObjectManagement.User, Objec
protected override async validateInput(): Promise<string[]> {
const errors = await super.validateInput();
if (this.objectInfo.type === ObjectManagement.UserType.SqlAuthentication) {
if (this.objectInfo.type === UserType.SqlAuthentication) {
if (!this.objectInfo.password) {
errors.push(localizedConstants.PasswordCannotBeEmptyError);
}
@@ -56,7 +57,7 @@ export class UserDialog extends PrincipalDialogBase<ObjectManagement.User, Objec
&& (this.options.isNewObject || this.objectInfo.password !== this.originalObjectInfo.password)) {
errors.push(localizedConstants.InvalidPasswordError);
}
} else if (this.objectInfo.type === ObjectManagement.UserType.LoginMapped && !this.objectInfo.loginName) {
} else if (this.objectInfo.type === UserType.LoginMapped && !this.objectInfo.loginName) {
errors.push(localizedConstants.LoginNotSelectedError);
}
return errors;
@@ -148,18 +149,18 @@ export class UserDialog extends PrincipalDialogBase<ObjectManagement.User, Objec
this.removeItem(this.generalSection, this.confirmPasswordContainer);
this.removeItem(this.formContainer, this.advancedSection);
switch (this.objectInfo.type) {
case ObjectManagement.UserType.LoginMapped:
case UserType.LoginMapped:
this.addItem(this.generalSection, this.loginContainer);
break;
case ObjectManagement.UserType.AADAuthentication:
case UserType.AADAuthentication:
this.addItem(this.formContainer, this.advancedSection);
break;
case ObjectManagement.UserType.SqlAuthentication:
case UserType.SqlAuthentication:
this.addItem(this.generalSection, this.passwordContainer);
this.addItem(this.generalSection, this.confirmPasswordContainer);
this.addItem(this.formContainer, this.advancedSection);
break;
case ObjectManagement.UserType.WindowsUser:
case UserType.WindowsUser:
if (this.objectInfo.loginName) {
this.addItem(this.generalSection, this.loginContainer);
}