From 6a7899281a4b48b986861b93105a56059b9ba7b2 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Mon, 1 May 2023 13:29:55 -0700 Subject: [PATCH] remove auth type from user (#22905) * remove auth type from user * vbump sts --- extensions/mssql/config.json | 2 +- extensions/mssql/src/mssql.d.ts | 51 ++++------- .../mssql/src/objectManagement/commands.ts | 10 +-- .../objectManagement/localizedConstants.ts | 79 ++++++++++++++++- .../objectManagementService.ts | 33 ++++--- .../objectManagement/ui/findObjectDialog.ts | 5 +- .../src/objectManagement/ui/loginDialog.ts | 24 ++---- .../ui/objectManagementDialogBase.ts | 8 +- .../src/objectManagement/ui/userDialog.ts | 86 +++++++------------ .../mssql/src/objectManagement/utils.ts | 76 ---------------- 10 files changed, 157 insertions(+), 217 deletions(-) diff --git a/extensions/mssql/config.json b/extensions/mssql/config.json index 09a2549faa..73b9a6473e 100644 --- a/extensions/mssql/config.json +++ b/extensions/mssql/config.json @@ -1,6 +1,6 @@ { "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", - "version": "4.7.0.23", + "version": "4.7.0.24", "downloadFileNames": { "Windows_86": "win-x86-net7.0.zip", "Windows_64": "win-x64-net7.0.zip", diff --git a/extensions/mssql/src/mssql.d.ts b/extensions/mssql/src/mssql.d.ts index 034ac53554..d130ac1db0 100644 --- a/extensions/mssql/src/mssql.d.ts +++ b/extensions/mssql/src/mssql.d.ts @@ -1027,17 +1027,9 @@ declare module 'mssql' { */ export interface LoginViewInfo extends ObjectViewInfo { /** - * Whether Windows Authentication is supported. + * The authentication types supported by the server. */ - supportWindowsAuthentication: boolean; - /** - * Whether Azure Active Directory Authentication is supported. - */ - supportAADAuthentication: boolean; - /** - * Whether SQL Authentication is supported. - */ - supportSQLAuthentication: boolean; + authenticationTypes: AuthenticationType[]; /** * Whether the locked out state can be changed. */ @@ -1119,21 +1111,25 @@ declare module 'mssql' { */ export const enum UserType { /** - * User with a server level login. + * Mapped to a server login. */ - WithLogin = 'WithLogin', + LoginMapped = 'LoginMapped', /** - * User based on a Windows user/group that has no login, but can connect to the Database Engine through membership in a Windows group. + * Mapped to a Windows user or group. */ - WithWindowsGroupLogin = 'WithWindowsGroupLogin', + WindowsUser = 'WindowsUser', /** - * Contained user, authentication is done within the database. + * Authenticate with password. */ - Contained = 'Contained', + SqlAuthentication = 'SqlAuthentication', + /** + * Authenticate with Azure Active Directory. + */ + AADAuthentication = 'AADAuthentication', /** * User that cannot authenticate. */ - NoConnectAccess = 'NoConnectAccess' + NoLoginAccess = 'NoLoginAccess' } /** @@ -1166,11 +1162,6 @@ declare module 'mssql' { * Only applicable when the user type is 'Contained'. */ defaultLanguage: string | undefined; - /** - * Authentication type. - * Only applicable when user type is 'Contained'. - */ - authenticationType: AuthenticationType | undefined; /** * Password of the user. * Only applicable when the user type is 'Contained' and the authentication type is 'Sql'. @@ -1183,21 +1174,9 @@ declare module 'mssql' { */ export interface UserViewInfo extends ObjectViewInfo { /** - * Whether contained user is supported. + * All user types supported by the database. */ - supportContainedUser: boolean; - /** - * Whether Windows authentication is supported. - */ - supportWindowsAuthentication: boolean; - /** - * Whether Azure Active Directory authentication is supported. - */ - supportAADAuthentication: boolean; - /** - * Whether SQL Authentication is supported. - */ - supportSQLAuthentication: boolean; + userTypes: UserType[]; /** * All languages supported by the database. */ diff --git a/extensions/mssql/src/objectManagement/commands.ts b/extensions/mssql/src/objectManagement/commands.ts index dcd992d07c..431ac43b92 100644 --- a/extensions/mssql/src/objectManagement/commands.ts +++ b/extensions/mssql/src/objectManagement/commands.ts @@ -14,7 +14,7 @@ import * as localizedConstants from './localizedConstants'; import { UserDialog } from './ui/userDialog'; import { IObjectManagementService, ObjectManagement } from 'mssql'; import * as constants from '../constants'; -import { getNodeTypeDisplayName, refreshParentNode } from './utils'; +import { refreshParentNode } from './utils'; import { TelemetryReporter } from '../telemetry'; import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './ui/objectManagementDialogBase'; import { ServerRoleDialog } from './ui/serverRoleDialog'; @@ -91,7 +91,7 @@ async function handleNewObjectDialogCommand(context: azdata.ObjectExplorerContex objectType: context.nodeInfo!.nodeType }).send(); console.error(err); - await vscode.window.showErrorMessage(localizedConstants.OpenNewObjectDialogError(getNodeTypeDisplayName(objectType), getErrorMessage(err))); + await vscode.window.showErrorMessage(localizedConstants.OpenNewObjectDialogError(localizedConstants.getNodeTypeDisplayName(objectType), getErrorMessage(err))); } } @@ -120,7 +120,7 @@ async function handleObjectPropertiesDialogCommand(context: azdata.ObjectExplore objectType: context.nodeInfo!.nodeType }).send(); console.error(err); - await vscode.window.showErrorMessage(localizedConstants.OpenObjectPropertiesDialogError(getNodeTypeDisplayName(context.nodeInfo!.nodeType), context.nodeInfo!.label, getErrorMessage(err))); + await vscode.window.showErrorMessage(localizedConstants.OpenObjectPropertiesDialogError(localizedConstants.getNodeTypeDisplayName(context.nodeInfo!.nodeType), context.nodeInfo!.label, getErrorMessage(err))); } } @@ -137,7 +137,7 @@ async function handleDeleteObjectCommand(context: azdata.ObjectExplorerContext, default: break; } - const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo!.nodeType); + const nodeTypeDisplayName = localizedConstants.getNodeTypeDisplayName(context.nodeInfo!.nodeType); let confirmMessage = localizedConstants.DeleteObjectConfirmationText(nodeTypeDisplayName, context.nodeInfo!.label); if (additionalConfirmationMessage) { confirmMessage = `${additionalConfirmationMessage} ${confirmMessage}`; @@ -179,7 +179,7 @@ async function handleRenameObjectCommand(context: azdata.ObjectExplorerContext, if (!connectionUri) { return; } - const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo!.nodeType); + const nodeTypeDisplayName = localizedConstants.getNodeTypeDisplayName(context.nodeInfo!.nodeType); const originalName = context.nodeInfo!.metadata!.name; const newName = await vscode.window.showInputBox({ title: localizedConstants.RenameObjectDialogTitle, diff --git a/extensions/mssql/src/objectManagement/localizedConstants.ts b/extensions/mssql/src/objectManagement/localizedConstants.ts index f199fb4939..23a5570dbf 100644 --- a/extensions/mssql/src/objectManagement/localizedConstants.ts +++ b/extensions/mssql/src/objectManagement/localizedConstants.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vscode-nls'; +import { ObjectManagement } from 'mssql'; const localize = nls.loadMessageBundle(); // Object Types @@ -167,10 +168,11 @@ export const OldPasswordCannotBeEmptyError = localize('objectManagement.login.ol // User export const UserTypeText = localize('objectManagement.user.type', "Type"); -export const UserWithLoginText = localize('objectManagement.user.userWithLogin', "User with login"); -export const UserWithWindowsGroupLoginText = localize('objectManagement.user.userWithGroupLogin', "User with Windows group login"); -export const ContainedUserText = localize('objectManagement.user.containedUser', "Contained user"); -export const UserWithNoConnectAccess = localize('objectManagement.user.userWithNoConnectAccess', "User with no connect access"); +export const UserType_LoginMapped = localize('objectManagement.user.loginMapped', "Mapped to a server login"); +export const UserType_WindowsUser = localize('objectManagement.user.windowsUser', "Mapped to a Windows user/group"); +export const UserType_SqlAuthentication = localize('objectManagement.user.sqlAuth', "Authenticate with password"); +export const UserType_AADAuthentication = localize('objectManagement.user.aadAuth', "Authenticate with Azure Active Directory"); +export const UserType_NoLoginAccess = localize('objectManagement.user.noLogin', "No Login Access"); export const DefaultSchemaText = localize('objectManagement.user.defaultSchemaLabel', "Default schema"); export const LoginText = localize('objectManagement.user.loginLabel', "Login"); export const OwnedSchemaSectionHeader = localize('objectManagement.user.ownedSchemasLabel', "Owned Schemas"); @@ -193,3 +195,72 @@ export const LoadingObjectsText = localize('objectManagement.loadingObjectsLabel export function LoadingObjectsCompletedText(count: number): string { return localize('objectManagement.loadingObjectsCompletedLabel', "Loading objects completed, {0} objects found", count); } + +// Util functions + +export function getNodeTypeDisplayName(type: string, inTitle: boolean = false): string { + switch (type) { + case ObjectManagement.NodeType.ApplicationRole: + return inTitle ? ApplicationRoleTypeDisplayNameInTitle : ApplicationRoleTypeDisplayName; + case ObjectManagement.NodeType.DatabaseRole: + return inTitle ? DatabaseRoleTypeDisplayNameInTitle : DatabaseRoleTypeDisplayName; + case ObjectManagement.NodeType.ServerLevelLogin: + return inTitle ? LoginTypeDisplayNameInTitle : LoginTypeDisplayName; + case ObjectManagement.NodeType.ServerLevelServerRole: + return inTitle ? ServerRoleTypeDisplayNameInTitle : ServerRoleTypeDisplayName; + case ObjectManagement.NodeType.User: + return inTitle ? UserTypeDisplayNameInTitle : UserTypeDisplayName; + case ObjectManagement.NodeType.Table: + return TableTypeDisplayName; + case ObjectManagement.NodeType.View: + return ViewTypeDisplayName; + case ObjectManagement.NodeType.Column: + return ColumnTypeDisplayName; + case ObjectManagement.NodeType.Database: + return DatabaseTypeDisplayName; + default: + throw new Error(`Unknown node type: ${type}`); + } +} + +const AuthencationTypeDisplayNameMap = new Map(); +AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.Windows, WindowsAuthenticationTypeDisplayText); +AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.Sql, SQLAuthenticationTypeDisplayText); +AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.AzureActiveDirectory, AADAuthenticationTypeDisplayText); + +export function getAuthenticationTypeDisplayName(authType: ObjectManagement.AuthenticationType): string { + if (AuthencationTypeDisplayNameMap.has(authType)) { + return AuthencationTypeDisplayNameMap.get(authType); + } + throw new Error(`Unknown authentication type: ${authType}`); +} + +export function getAuthenticationTypeByDisplayName(displayName: string): ObjectManagement.AuthenticationType { + for (let [key, value] of AuthencationTypeDisplayNameMap.entries()) { + if (value === displayName) + return key; + } + throw new Error(`Unknown authentication type display name: ${displayName}`); +} + +const UserTypeDisplayNameMap = new Map(); +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); + +export function getUserTypeDisplayName(userType: ObjectManagement.UserType): string { + if (UserTypeDisplayNameMap.has(userType)) { + return UserTypeDisplayNameMap.get(userType); + } + throw new Error(`Unknown user type: ${userType}`); +} + +export function getUserTypeByDisplayName(displayName: string): ObjectManagement.UserType { + for (let [key, value] of UserTypeDisplayNameMap.entries()) { + if (value === displayName) + return key; + } + throw new Error(`Unknown user type display name: ${displayName}`); +} diff --git a/extensions/mssql/src/objectManagement/objectManagementService.ts b/extensions/mssql/src/objectManagement/objectManagementService.ts index a15e891ca4..85575b2e11 100644 --- a/extensions/mssql/src/objectManagement/objectManagementService.ts +++ b/extensions/mssql/src/objectManagement/objectManagementService.ts @@ -138,9 +138,7 @@ export class TestObjectManagementService implements IObjectManagementService { isEnabled: true, isLockedOut: false }, - supportAADAuthentication: true, - supportSQLAuthentication: true, - supportWindowsAuthentication: true, + authenticationTypes: [ObjectManagement.AuthenticationType.Sql, ObjectManagement.AuthenticationType.Windows], supportAdvancedOptions: true, supportAdvancedPasswordOptions: true, canEditLockedOutState: false, @@ -164,9 +162,7 @@ export class TestObjectManagementService implements IObjectManagementService { isLockedOut: false, password: '******************' }, - supportAADAuthentication: true, - supportSQLAuthentication: true, - supportWindowsAuthentication: true, + authenticationTypes: [ObjectManagement.AuthenticationType.Sql, ObjectManagement.AuthenticationType.Windows], supportAdvancedOptions: true, supportAdvancedPasswordOptions: true, canEditLockedOutState: false, @@ -189,7 +185,7 @@ export class TestObjectManagementService implements IObjectManagementService { viewInfo = { objectInfo: { name: '', - type: ObjectManagement.UserType.WithLogin, + type: ObjectManagement.UserType.LoginMapped, defaultSchema: 'dbo', defaultLanguage: '', authenticationType: ObjectManagement.AuthenticationType.Sql, @@ -202,20 +198,21 @@ export class TestObjectManagementService implements IObjectManagementService { schemas: schemas, logins: logins, databaseRoles: databaseRoles, - supportContainedUser: true, - supportAADAuthentication: true, - supportSQLAuthentication: true, - supportWindowsAuthentication: true + userTypes: [ + ObjectManagement.UserType.LoginMapped, + ObjectManagement.UserType.AADAuthentication, + ObjectManagement.UserType.SqlAuthentication, + ObjectManagement.UserType.NoLoginAccess + ] }; } else { viewInfo = { objectInfo: { name: name, - type: ObjectManagement.UserType.WithLogin, + type: ObjectManagement.UserType.LoginMapped, defaultSchema: 'dbo', defaultLanguage: '', loginName: 'sa', - authenticationType: ObjectManagement.AuthenticationType.Sql, ownedSchemas: ['dbo'], databaseRoles: ['dbmanager', 'bulkadmin'] }, @@ -223,10 +220,12 @@ export class TestObjectManagementService implements IObjectManagementService { schemas: schemas, logins: logins, databaseRoles: databaseRoles, - supportContainedUser: true, - supportAADAuthentication: true, - supportSQLAuthentication: true, - supportWindowsAuthentication: true + userTypes: [ + ObjectManagement.UserType.LoginMapped, + ObjectManagement.UserType.AADAuthentication, + ObjectManagement.UserType.SqlAuthentication, + ObjectManagement.UserType.NoLoginAccess + ] }; } return viewInfo; diff --git a/extensions/mssql/src/objectManagement/ui/findObjectDialog.ts b/extensions/mssql/src/objectManagement/ui/findObjectDialog.ts index e8158cf5ca..46ed0f302d 100644 --- a/extensions/mssql/src/objectManagement/ui/findObjectDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/findObjectDialog.ts @@ -7,7 +7,6 @@ import * as azdata from 'azdata'; import * as mssql from 'mssql'; import { DefaultTableListItemEnabledStateGetter, DefaultMaxTableHeight, DialogBase, TableListItemComparer, TableListItemValueGetter } from './dialogBase'; import * as localizedConstants from '../localizedConstants'; -import { getNodeTypeDisplayName } from '../utils'; import { getErrorMessage } from '../../utils'; export interface FindObjectDialogOptions { @@ -28,7 +27,7 @@ const ObjectComparer: TableListItemComparer = (item) => { - return [item.name, getNodeTypeDisplayName(item.type, true)]; + return [item.name, localizedConstants.getNodeTypeDisplayName(item.type, true)]; }; const ObjectsTableMaxHeight = 700; @@ -59,7 +58,7 @@ export class FindObjectDialog extends DialogBase { this.selectedObjectTypes, DefaultMaxTableHeight, DefaultTableListItemEnabledStateGetter, (item) => { - return [getNodeTypeDisplayName(item, true)]; + return [localizedConstants.getNodeTypeDisplayName(item, true)]; }); this.findButton = this.createButton(localizedConstants.FindText, localizedConstants.FindText, async () => { await this.onFindObjectButtonClick(); diff --git a/extensions/mssql/src/objectManagement/ui/loginDialog.ts b/extensions/mssql/src/objectManagement/ui/loginDialog.ts index 2269f845ac..f9f863b00d 100644 --- a/extensions/mssql/src/objectManagement/ui/loginDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/loginDialog.ts @@ -8,7 +8,7 @@ import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './obj import { IObjectManagementService, ObjectManagement } from 'mssql'; import * as localizedConstants from '../localizedConstants'; import { AlterLoginDocUrl, CreateLoginDocUrl, PublicServerRoleName } from '../constants'; -import { getAuthenticationTypeByDisplayName, getAuthenticationTypeDisplayName, isValidSQLPassword } from '../utils'; +import { isValidSQLPassword } from '../utils'; import { DefaultMaxTableHeight } from './dialogBase'; export class LoginDialog extends ObjectManagementDialogBase { @@ -107,20 +107,14 @@ export class LoginDialog extends ObjectManagementDialogBase { - this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(newValue); - this.setViewByAuthenticationType(); - }, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject); + this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, + async (newValue) => { + this.objectInfo.authenticationType = localizedConstants.getAuthenticationTypeByDisplayName(newValue); + this.setViewByAuthenticationType(); + }, + this.viewInfo.authenticationTypes.map(authType => localizedConstants.getAuthenticationTypeDisplayName(authType)), + localizedConstants.getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), + this.options.isNewObject); const authTypeContainer = this.createLabelInputContainer(localizedConstants.AuthTypeText, this.authTypeDropdown); diff --git a/extensions/mssql/src/objectManagement/ui/objectManagementDialogBase.ts b/extensions/mssql/src/objectManagement/ui/objectManagementDialogBase.ts index 7cbf361b29..199291a469 100644 --- a/extensions/mssql/src/objectManagement/ui/objectManagementDialogBase.ts +++ b/extensions/mssql/src/objectManagement/ui/objectManagementDialogBase.ts @@ -8,7 +8,7 @@ import { IObjectManagementService, ObjectManagement } from 'mssql'; import * as vscode from 'vscode'; import { generateUuid } from 'vscode-languageclient/lib/utils/uuid'; import * as localizedConstants from '../localizedConstants'; -import { deepClone, getNodeTypeDisplayName, refreshNode, refreshParentNode } from '../utils'; +import { deepClone, refreshNode, refreshParentNode } from '../utils'; import { DialogBase } from './dialogBase'; import { ObjectManagementViewName, TelemetryActions } from '../constants'; import { TelemetryReporter } from '../../telemetry'; @@ -41,8 +41,8 @@ export abstract class ObjectManagementDialogBase { await this.initializeData(); await this.initializeUI(); - const typeDisplayName = getNodeTypeDisplayName(this.options.objectType); + const typeDisplayName = localizedConstants.getNodeTypeDisplayName(this.options.objectType); this.dialogObject.registerOperation({ displayName: this.options.isNewObject ? localizedConstants.CreateObjectOperationDisplayName(typeDisplayName) : localizedConstants.UpdateObjectOperationDisplayName(typeDisplayName, this.options.objectName), diff --git a/extensions/mssql/src/objectManagement/ui/userDialog.ts b/extensions/mssql/src/objectManagement/ui/userDialog.ts index d2d625b73f..bd1ca5f165 100644 --- a/extensions/mssql/src/objectManagement/ui/userDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/userDialog.ts @@ -7,7 +7,7 @@ import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './obj import { IObjectManagementService, ObjectManagement } from 'mssql'; import * as localizedConstants from '../localizedConstants'; import { AlterUserDocUrl, CreateUserDocUrl } from '../constants'; -import { getAuthenticationTypeByDisplayName, getAuthenticationTypeDisplayName, getUserTypeByDisplayName, getUserTypeDisplayName, isValidSQLPassword } from '../utils'; +import { isValidSQLPassword } from '../utils'; import { DefaultMaxTableHeight } from './dialogBase'; export class UserDialog extends ObjectManagementDialogBase { @@ -18,8 +18,6 @@ export class UserDialog extends ObjectManagementDialogBase { const errors = await super.validateInput(); - if (this.objectInfo.type === ObjectManagement.UserType.Contained && this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql) { + if (this.objectInfo.type === ObjectManagement.UserType.SqlAuthentication) { if (!this.objectInfo.password) { errors.push(localizedConstants.PasswordCannotBeEmptyError); } @@ -57,10 +55,8 @@ export class UserDialog extends ObjectManagementDialogBase { - this.objectInfo.type = getUserTypeByDisplayName(newValue); - this.setViewByUserType(); - }, userTypes, getUserTypeDisplayName(this.objectInfo.type), this.options.isNewObject); + this.typeDropdown = this.createDropdown(localizedConstants.UserTypeText, + async (newValue) => { + this.objectInfo.type = localizedConstants.getUserTypeByDisplayName(newValue); + this.setViewByUserType(); + }, + this.viewInfo.userTypes.map(userType => localizedConstants.getUserTypeDisplayName(userType)), + localizedConstants.getUserTypeDisplayName(this.objectInfo.type), + this.options.isNewObject); this.typeContainer = this.createLabelInputContainer(localizedConstants.UserTypeText, this.typeDropdown); this.loginDropdown = this.createDropdown(localizedConstants.LoginText, async (newValue) => { @@ -100,22 +97,6 @@ export class UserDialog extends ObjectManagementDialogBase { - this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(newValue); - this.setViewByAuthenticationType(); - }, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject); - this.authTypeContainer = this.createLabelInputContainer(localizedConstants.AuthTypeText, this.authTypeDropdown); - this.passwordInput = this.createPasswordInputBox(localizedConstants.PasswordText, async (newValue) => { this.objectInfo.password = newValue; }, this.objectInfo.password ?? ''); @@ -128,7 +109,6 @@ export class UserDialog extends ObjectManagementDialogBase(obj: T): T { @@ -53,81 +52,6 @@ export async function refreshNode(context: azdata.ObjectExplorerContext): Promis } } -export function getNodeTypeDisplayName(type: string, inTitle: boolean = false): string { - switch (type) { - case ObjectManagement.NodeType.ApplicationRole: - return inTitle ? localizedConstants.ApplicationRoleTypeDisplayNameInTitle : localizedConstants.ApplicationRoleTypeDisplayName; - case ObjectManagement.NodeType.DatabaseRole: - return inTitle ? localizedConstants.DatabaseRoleTypeDisplayNameInTitle : localizedConstants.DatabaseRoleTypeDisplayName; - case ObjectManagement.NodeType.ServerLevelLogin: - return inTitle ? localizedConstants.LoginTypeDisplayNameInTitle : localizedConstants.LoginTypeDisplayName; - case ObjectManagement.NodeType.ServerLevelServerRole: - return inTitle ? localizedConstants.ServerRoleTypeDisplayNameInTitle : localizedConstants.ServerRoleTypeDisplayName; - case ObjectManagement.NodeType.User: - return inTitle ? localizedConstants.UserTypeDisplayNameInTitle : localizedConstants.UserTypeDisplayName; - case ObjectManagement.NodeType.Table: - return localizedConstants.TableTypeDisplayName; - case ObjectManagement.NodeType.View: - return localizedConstants.ViewTypeDisplayName; - case ObjectManagement.NodeType.Column: - return localizedConstants.ColumnTypeDisplayName; - case ObjectManagement.NodeType.Database: - return localizedConstants.DatabaseTypeDisplayName; - default: - throw new Error(`Unknown node type: ${type}`); - } -} - -export function getAuthenticationTypeDisplayName(authType: ObjectManagement.AuthenticationType | undefined): string | undefined { - if (authType === undefined) { return undefined; } - - switch (authType) { - case ObjectManagement.AuthenticationType.Windows: - return localizedConstants.WindowsAuthenticationTypeDisplayText; - case ObjectManagement.AuthenticationType.AzureActiveDirectory: - return localizedConstants.AADAuthenticationTypeDisplayText; - default: - return localizedConstants.SQLAuthenticationTypeDisplayText; - } -} - -export function getAuthenticationTypeByDisplayName(displayValue: string): ObjectManagement.AuthenticationType { - switch (displayValue) { - case localizedConstants.WindowsAuthenticationTypeDisplayText: - return ObjectManagement.AuthenticationType.Windows; - case localizedConstants.AADAuthenticationTypeDisplayText: - return ObjectManagement.AuthenticationType.AzureActiveDirectory; - default: - return ObjectManagement.AuthenticationType.Sql; - } -} - -export function getUserTypeDisplayName(userType: ObjectManagement.UserType): string { - switch (userType) { - case ObjectManagement.UserType.WithLogin: - return localizedConstants.UserWithLoginText; - case ObjectManagement.UserType.WithWindowsGroupLogin: - return localizedConstants.UserWithWindowsGroupLoginText; - case ObjectManagement.UserType.Contained: - return localizedConstants.ContainedUserText; - default: - return localizedConstants.UserWithNoConnectAccess; - } -} - -export function getUserTypeByDisplayName(userTypeDisplayName: string): ObjectManagement.UserType { - switch (userTypeDisplayName) { - case localizedConstants.UserWithLoginText: - return ObjectManagement.UserType.WithLogin; - case localizedConstants.UserWithWindowsGroupLoginText: - return ObjectManagement.UserType.WithWindowsGroupLogin; - case localizedConstants.ContainedUserText: - return ObjectManagement.UserType.Contained; - default: - return ObjectManagement.UserType.NoConnectAccess; - } -} - // https://docs.microsoft.com/sql/relational-databases/security/password-policy export function isValidSQLPassword(password: string, userName: string = 'sa'): boolean { const containsUserName = password && userName && password.toUpperCase().includes(userName.toUpperCase());