CMS - SQL Login (#5989)

* initial SQL Login with save password working

* fix switching auth types

* remove metadata from package file

* allow editing connections for unsaved password connections

* review comments

* change thenables to async/awaits

* review comments

* changed thenables to promises

* remove authTypeChanged bool

* removed unused import

* review comments

* removed try catches

* cr comments

* review comments
This commit is contained in:
Aditya Bist
2019-07-01 11:40:11 -07:00
committed by GitHub
parent 6b5193908c
commit 678b2737bd
12 changed files with 317 additions and 211 deletions

View File

@@ -75,6 +75,9 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
}
let connectionProfile = await this._connectionDialogService.openDialogAndWait(this._connectionManagementService,
{ connectionType: connectionType, providers: providers }, initialConnectionProfile, undefined);
if (connectionProfile) {
connectionProfile.options.savePassword = connectionProfile.savePassword;
}
const connection = connectionProfile ? {
connectionId: connectionProfile.id,
options: connectionProfile.options,

View File

@@ -36,8 +36,8 @@ export class CmsConnectionController extends ConnectionController {
}, providerName);
}
public showUiComponent(container: HTMLElement): void {
public showUiComponent(container: HTMLElement, authTypeChanged: boolean = false): void {
this._databaseCache = new Map<string, string[]>();
this._connectionWidget.createConnectionWidget(container);
this._connectionWidget.createConnectionWidget(container, authTypeChanged);
}
}

View File

@@ -35,7 +35,7 @@ export class CmsConnectionWidget extends ConnectionWidget {
private _serverDescriptionInputBox: InputBox;
protected _authTypeMap: { [providerName: string]: AuthenticationType[] } = {
[Constants.cmsProviderName]: [AuthenticationType.Integrated]
[Constants.cmsProviderName]: [AuthenticationType.SqlLogin, AuthenticationType.Integrated]
};
constructor(options: azdata.ConnectionOption[],
@@ -53,8 +53,14 @@ export class CmsConnectionWidget extends ConnectionWidget {
super(options, callbacks, providerName, _themeService, _contextViewService, _connectionManagementService, _capabilitiesService,
_clipboardService, _configurationService, _accountManagementService);
let authTypeOption = this._optionsMaps[ConnectionOptionSpecialType.authType];
authTypeOption.defaultValue = this.getAuthTypeDisplayName(AuthenticationType.Integrated);
this._authTypeSelectBox = new SelectBox(authTypeOption.categoryValues.map(c => c.displayName), authTypeOption.defaultValue, this._contextViewService, undefined, { ariaLabel: authTypeOption.displayName });
if (authTypeOption) {
if (OS === OperatingSystem.Windows) {
authTypeOption.defaultValue = this.getAuthTypeDisplayName(AuthenticationType.Integrated);
} else {
authTypeOption.defaultValue = this.getAuthTypeDisplayName(AuthenticationType.SqlLogin);
}
this._authTypeSelectBox = new SelectBox(authTypeOption.categoryValues.map(c => c.displayName), authTypeOption.defaultValue, this._contextViewService, undefined, { ariaLabel: authTypeOption.displayName });
}
}
protected registerListeners(): void {
@@ -64,12 +70,12 @@ export class CmsConnectionWidget extends ConnectionWidget {
}
}
protected fillInConnectionForm(): void {
protected fillInConnectionForm(authTypeChanged: boolean = false): void {
// Server Name
this.addServerNameOption();
// Authentication type
this.addAuthenticationTypeOption();
this.addAuthenticationTypeOption(authTypeChanged);
// Login Options
this.addLoginOptions();
@@ -84,16 +90,28 @@ export class CmsConnectionWidget extends ConnectionWidget {
this.addAdvancedOptions();
}
protected addAuthenticationTypeOption(): void {
super.addAuthenticationTypeOption();
protected addAuthenticationTypeOption(authTypeChanged: boolean = false): void {
super.addAuthenticationTypeOption(authTypeChanged);
let authTypeOption = this._optionsMaps[ConnectionOptionSpecialType.authType];
let newAuthTypes = authTypeOption.categoryValues;
// CMS only supports Integrated Auth
newAuthTypes = authTypeOption.categoryValues.filter((option) => option.name === AuthenticationType.Integrated);
this._authTypeSelectBox.setOptions(newAuthTypes.map(c => c.displayName), 0);
authTypeOption.defaultValue = AuthenticationType.Integrated;
this._authTypeSelectBox.setOptions(authTypeOption.categoryValues.map(c => c.displayName), 1);
// True when opening a CMS dialog to add a registered server
if (authTypeChanged) {
// Registered Servers only support Integrated Auth
newAuthTypes = authTypeOption.categoryValues.filter((option) => option.name === AuthenticationType.Integrated);
this._authTypeSelectBox.setOptions(newAuthTypes.map(c => c.displayName));
authTypeOption.defaultValue = AuthenticationType.Integrated;
} else {
// CMS supports all auth types
newAuthTypes = authTypeOption.categoryValues;
this._authTypeSelectBox.setOptions(newAuthTypes.map(c => c.displayName));
if (OS === OperatingSystem.Windows) {
authTypeOption.defaultValue = this.getAuthTypeDisplayName(AuthenticationType.Integrated);
} else {
authTypeOption.defaultValue = this.getAuthTypeDisplayName(AuthenticationType.SqlLogin);
}
}
this._authTypeSelectBox.selectWithOptionName(authTypeOption.defaultValue);
}
private addServerDescriptionOption(): void {
@@ -107,10 +125,10 @@ export class CmsConnectionWidget extends ConnectionWidget {
}
}
public createConnectionWidget(container: HTMLElement): void {
public createConnectionWidget(container: HTMLElement, authTypeChanged: boolean = false): void {
this._container = DOM.append(container, DOM.$('div.connection-table'));
this._tableContainer = DOM.append(this._container, DOM.$('table.connection-table-content'));
this.fillInConnectionForm();
this.fillInConnectionForm(authTypeChanged);
this.registerListeners();
if (this._authTypeSelectBox) {
this.onAuthTypeSelected(this._authTypeSelectBox.value);
@@ -147,4 +165,12 @@ export class CmsConnectionWidget extends ConnectionWidget {
}
return validInputs;
}
public fillInConnectionInputs(connectionInfo: IConnectionProfile) {
super.fillInConnectionInputs(connectionInfo);
if (connectionInfo) {
let description = connectionInfo.options.registeredServerDescription ? connectionInfo.options.registeredServerDescription : '';
this._serverDescriptionInputBox.value = description;
}
}
}

View File

@@ -318,7 +318,12 @@ export class ConnectionDialogService implements IConnectionDialogService {
this._model.providerName = this._currentProviderType;
this._model = new ConnectionProfile(this._capabilitiesService, this._model);
this.uiController.showUiComponent(input.container);
if (this._inputModel && this._inputModel.options) {
this.uiController.showUiComponent(input.container,
this._inputModel.options.authTypeChanged);
} else {
this.uiController.showUiComponent(input.container);
}
}

View File

@@ -123,13 +123,13 @@ export class ConnectionWidget {
this._providerName = providerName;
}
public createConnectionWidget(container: HTMLElement): void {
public createConnectionWidget(container: HTMLElement, authTypeChanged: boolean = false): void {
this._serverGroupOptions = [this.DefaultServerGroup];
this._serverGroupSelectBox = new SelectBox(this._serverGroupOptions.map(g => g.name), this.DefaultServerGroup.name, this._contextViewService, undefined, { ariaLabel: this._serverGroupDisplayString });
this._previousGroupOption = this._serverGroupSelectBox.value;
this._container = DOM.append(container, DOM.$('div.connection-table'));
this._tableContainer = DOM.append(this._container, DOM.$('table.connection-table-content'));
this.fillInConnectionForm();
this.fillInConnectionForm(authTypeChanged);
this.registerListeners();
if (this._authTypeSelectBox) {
this.onAuthTypeSelected(this._authTypeSelectBox.value);
@@ -155,12 +155,12 @@ export class ConnectionWidget {
}
}
protected fillInConnectionForm(): void {
protected fillInConnectionForm(authTypeChanged: boolean = false): void {
// Server Name
this.addServerNameOption();
// Authentication type
this.addAuthenticationTypeOption();
this.addAuthenticationTypeOption(authTypeChanged);
// Login Options
this.addLoginOptions();
@@ -178,7 +178,7 @@ export class ConnectionWidget {
this.addAdvancedOptions();
}
protected addAuthenticationTypeOption(): void {
protected addAuthenticationTypeOption(authTypeChanged: boolean = false): void {
if (this._optionsMaps[ConnectionOptionSpecialType.authType]) {
let authType = DialogHelper.appendRow(this._tableContainer, this._optionsMaps[ConnectionOptionSpecialType.authType].displayName, 'connection-label', 'connection-input');
DialogHelper.appendInputSelectBox(authType, this._authTypeSelectBox);