mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Add default auth type configuration setting for Azure resources (#16999)
* Adding user config for default auth type * adding feature * removing the SqlLogin default from the model * fixing bug, removing dead code * removing unneeded instance of configurationService * fixing line break * removing extra parameter * removing comments * Fix test breaks * Fix build break * More breaks * Address code review feedback Co-authored-by: Troy Witthoeft <troy.witthoeft@gmail.com>
This commit is contained in:
@@ -43,7 +43,7 @@ export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProvi
|
|||||||
databaseName: database.name,
|
databaseName: database.name,
|
||||||
userName: database.loginName,
|
userName: database.loginName,
|
||||||
password: '',
|
password: '',
|
||||||
authenticationType: 'SqlLogin',
|
authenticationType: '',
|
||||||
savePassword: true,
|
savePassword: true,
|
||||||
groupFullName: '',
|
groupFullName: '',
|
||||||
groupId: '',
|
groupId: '',
|
||||||
|
|||||||
@@ -218,6 +218,11 @@ export interface IConnectionManagementService {
|
|||||||
|
|
||||||
getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap: { [providerDisplayName: string]: string }): { [providerDisplayName: string]: string };
|
getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap: { [providerDisplayName: string]: string }): { [providerDisplayName: string]: string };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default authentication type from the configuration service
|
||||||
|
*/
|
||||||
|
getDefaultAuthenticationTypeId(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels the connection
|
* Cancels the connection
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ export const defaultEngine = 'defaultEngine';
|
|||||||
|
|
||||||
export const passwordChars = '***************';
|
export const passwordChars = '***************';
|
||||||
|
|
||||||
|
/* default authentication type setting name*/
|
||||||
|
export const defaultAuthenticationType = 'defaultAuthenticationType';
|
||||||
|
|
||||||
/* authentication types */
|
/* authentication types */
|
||||||
export const sqlLogin = 'SqlLogin';
|
export const sqlLogin = 'SqlLogin';
|
||||||
export const integrated = 'Integrated';
|
export const integrated = 'Integrated';
|
||||||
|
|||||||
@@ -306,6 +306,11 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
return undefined!;
|
return undefined!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDefaultAuthenticationTypeId(): string {
|
||||||
|
return undefined!;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
getConnections(activeConnectionsOnly?: boolean): ConnectionProfile[] {
|
getConnections(activeConnectionsOnly?: boolean): ConnectionProfile[] {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,5 @@ export function getSqlConfigSection(workspaceConfigService: IConfigurationServic
|
|||||||
|
|
||||||
export function getSqlConfigValue<T>(workspaceConfigService: IConfigurationService, configName: string): T {
|
export function getSqlConfigValue<T>(workspaceConfigService: IConfigurationService, configName: string): T {
|
||||||
let config = workspaceConfigService.getValue<{ [key: string]: any }>(ConnectionConstants.sqlConfigSectionName);
|
let config = workspaceConfigService.getValue<{ [key: string]: any }>(ConnectionConstants.sqlConfigSectionName);
|
||||||
return config[configName];
|
return config ? config[configName] : undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,6 +176,18 @@ configurationRegistry.registerConfiguration({
|
|||||||
'default': 25,
|
'default': 25,
|
||||||
'description': localize('sql.maxRecentConnectionsDescription', "The maximum number of recently used connections to store in the connection list.")
|
'description': localize('sql.maxRecentConnectionsDescription', "The maximum number of recently used connections to store in the connection list.")
|
||||||
},
|
},
|
||||||
|
'sql.defaultAuthenticationType': {
|
||||||
|
'type': 'string',
|
||||||
|
'enum': ['SqlLogin', 'AzureMFA', `AzureMFAAndUser`, 'Integrated'],
|
||||||
|
'description': localize('sql.defaultAuthenticationTypeDescription', "Default authentication type to use when connecting to Azure resources. "),
|
||||||
|
'enumDescriptions': [
|
||||||
|
localize('sql.defaultAuthenticationType.SqlLogin', "Sql Login"),
|
||||||
|
localize('sql.defaultAuthenticationType.AzureMFA', "Azure Active Directory - Universal with MFA support"),
|
||||||
|
localize('sql.defaultAuthenticationType.AzureMFAAndUser', "Azure Active Directory - Password"),
|
||||||
|
localize('sql.defaultAuthenticationType.Integrated', "Windows Authentication"),
|
||||||
|
],
|
||||||
|
'default': 'AzureMFA'
|
||||||
|
},
|
||||||
'sql.defaultEngine': {
|
'sql.defaultEngine': {
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'description': localize('sql.defaultEngineDescription', "Default SQL Engine to use. This drives default language provider in .sql files and the default to use when creating a new connection."),
|
'description': localize('sql.defaultEngineDescription', "Default SQL Engine to use. This drives default language provider in .sql files and the default to use when creating a new connection."),
|
||||||
|
|||||||
@@ -152,6 +152,16 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
|||||||
return defaultProvider || Constants.mssqlProviderName;
|
return defaultProvider || Constants.mssqlProviderName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getDefaultAuthenticationTypeName(): string {
|
||||||
|
let defaultAuthenticationType: string;
|
||||||
|
if (!defaultAuthenticationType && this._configurationService) {
|
||||||
|
defaultAuthenticationType = WorkbenchUtils.getSqlConfigValue<string>(this._configurationService, Constants.defaultAuthenticationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultAuthenticationType || Constants.sqlLogin; // as a fallback, default to sql login if the value from settings is not available
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private handleOnConnect(params: INewConnectionParams, profile?: IConnectionProfile): void {
|
private handleOnConnect(params: INewConnectionParams, profile?: IConnectionProfile): void {
|
||||||
this._logService.debug('ConnectionDialogService: onConnect event is received');
|
this._logService.debug('ConnectionDialogService: onConnect event is received');
|
||||||
if (!this._connecting) {
|
if (!this._connecting) {
|
||||||
@@ -383,6 +393,14 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
|||||||
if (model && !model.providerName) {
|
if (model && !model.providerName) {
|
||||||
model.providerName = providerName;
|
model.providerName = providerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultAuthenticationType = this.getDefaultAuthenticationTypeName();
|
||||||
|
let authenticationTypeName = model ? model.authenticationType : defaultAuthenticationType;
|
||||||
|
authenticationTypeName = authenticationTypeName ? authenticationTypeName : defaultAuthenticationType;
|
||||||
|
if (model && !model.authenticationType) {
|
||||||
|
model.authenticationType = authenticationTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
let newProfile = new ConnectionProfile(this._capabilitiesService, model || providerName);
|
let newProfile = new ConnectionProfile(this._capabilitiesService, model || providerName);
|
||||||
newProfile.saveProfile = true;
|
newProfile.saveProfile = true;
|
||||||
newProfile.generateNewId();
|
newProfile.generateNewId();
|
||||||
|
|||||||
@@ -306,6 +306,11 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
// Fill in the Azure account token if needed and open the connection dialog if it fails
|
// Fill in the Azure account token if needed and open the connection dialog if it fails
|
||||||
let tokenFillSuccess = await this.fillInOrClearToken(newConnection);
|
let tokenFillSuccess = await this.fillInOrClearToken(newConnection);
|
||||||
|
|
||||||
|
// If there is no authentication type set, set it using configuration
|
||||||
|
if (!newConnection.authenticationType || newConnection.authenticationType === '') {
|
||||||
|
newConnection.authenticationType = this.getDefaultAuthenticationTypeId();
|
||||||
|
}
|
||||||
|
|
||||||
// If the password is required and still not loaded show the dialog
|
// If the password is required and still not loaded show the dialog
|
||||||
if ((!foundPassword && this._connectionStore.isPasswordRequired(newConnection) && !newConnection.password) || !tokenFillSuccess) {
|
if ((!foundPassword && this._connectionStore.isPasswordRequired(newConnection) && !newConnection.password) || !tokenFillSuccess) {
|
||||||
return this.showConnectionDialogOnError(connection, owner, { connected: false, errorMessage: undefined, callStack: undefined, errorCode: undefined }, options);
|
return this.showConnectionDialogOnError(connection, owner, { connected: false, errorMessage: undefined, callStack: undefined, errorCode: undefined }, options);
|
||||||
@@ -792,6 +797,11 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
return defaultProvider && this._providers.has(defaultProvider) ? defaultProvider : undefined;
|
return defaultProvider && this._providers.has(defaultProvider) ? defaultProvider : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getDefaultAuthenticationTypeId(): string {
|
||||||
|
let defaultAuthenticationType = WorkbenchUtils.getSqlConfigValue<string>(this._configurationService, Constants.defaultAuthenticationType);
|
||||||
|
return defaultAuthenticationType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Previously, the only resource available for AAD access tokens was for Azure SQL / SQL Server.
|
* Previously, the only resource available for AAD access tokens was for Azure SQL / SQL Server.
|
||||||
* Use that as a default if the provider extension does not configure a different one. If one is
|
* Use that as a default if the provider extension does not configure a different one. If one is
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import * as azdata from 'azdata';
|
import * as azdata from 'azdata';
|
||||||
|
import * as WorkbenchUtils from 'sql/workbench/common/sqlWorkbenchUtils';
|
||||||
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
|
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
|
||||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||||
@@ -14,6 +15,7 @@ import { hash } from 'vs/base/common/hash';
|
|||||||
import { Disposable } from 'vs/base/common/lifecycle';
|
import { Disposable } from 'vs/base/common/lifecycle';
|
||||||
import { generateUuid } from 'vs/base/common/uuid';
|
import { generateUuid } from 'vs/base/common/uuid';
|
||||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||||
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; //TODO: Needed?
|
||||||
import { TreeItemCollapsibleState } from 'vs/workbench/common/views';
|
import { TreeItemCollapsibleState } from 'vs/workbench/common/views';
|
||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
import { NodeType } from 'sql/workbench/services/objectExplorer/common/nodeType';
|
import { NodeType } from 'sql/workbench/services/objectExplorer/common/nodeType';
|
||||||
@@ -41,7 +43,8 @@ export class OEShimService extends Disposable implements IOEShimService {
|
|||||||
constructor(
|
constructor(
|
||||||
@IObjectExplorerService private oe: IObjectExplorerService,
|
@IObjectExplorerService private oe: IObjectExplorerService,
|
||||||
@IConnectionManagementService private cm: IConnectionManagementService,
|
@IConnectionManagementService private cm: IConnectionManagementService,
|
||||||
@ICapabilitiesService private capabilities: ICapabilitiesService
|
@ICapabilitiesService private capabilities: ICapabilitiesService,
|
||||||
|
@IConfigurationService private configurationService: IConfigurationService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -133,6 +136,10 @@ export class OEShimService extends Disposable implements IOEShimService {
|
|||||||
|
|
||||||
public async getChildren(node: ITreeItem, viewId: string): Promise<ITreeItem[]> {
|
public async getChildren(node: ITreeItem, viewId: string): Promise<ITreeItem[]> {
|
||||||
if (node.payload) {
|
if (node.payload) {
|
||||||
|
if (node.payload.authenticationType !== undefined && node.payload.authenticationType === '') {
|
||||||
|
node.payload.authenticationType = this.getDefaultAuthenticationType(this.configurationService); // we need to set auth type here, because it's value is part of the session key
|
||||||
|
}
|
||||||
|
|
||||||
const sessionId = await this.getOrCreateSession(viewId, node);
|
const sessionId = await this.getOrCreateSession(viewId, node);
|
||||||
const requestHandle = this.nodeHandleMap.get(generateNodeMapKey(viewId, node)) || node.handle;
|
const requestHandle = this.nodeHandleMap.get(generateNodeMapKey(viewId, node)) || node.handle;
|
||||||
const treeNode = new TreeNode(undefined!, undefined!, undefined!, requestHandle, undefined!); // hack since this entire system is a hack anyways
|
const treeNode = new TreeNode(undefined!, undefined!, undefined!, requestHandle, undefined!); // hack since this entire system is a hack anyways
|
||||||
@@ -222,6 +229,10 @@ export class OEShimService extends Disposable implements IOEShimService {
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getDefaultAuthenticationType(configurationService: IConfigurationService): string {
|
||||||
|
return WorkbenchUtils.getSqlConfigValue<string>(configurationService, 'defaultAuthenticationType');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateSessionMapKey(viewId: string, node: ITreeItem): number {
|
function generateSessionMapKey(viewId: string, node: ITreeItem): number {
|
||||||
|
|||||||
Reference in New Issue
Block a user