mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Fix AuthLibrary detection and use MSAL by default (#22140)
This commit is contained in:
@@ -48,11 +48,9 @@ import { Iterable } from 'vs/base/common/iterator';
|
|||||||
import { LoadingSpinner } from 'sql/base/browser/ui/loadingSpinner/loadingSpinner';
|
import { LoadingSpinner } from 'sql/base/browser/ui/loadingSpinner/loadingSpinner';
|
||||||
import { Tenant, TenantListDelegate, TenantListRenderer } from 'sql/workbench/services/accountManagement/browser/tenantListRenderer';
|
import { Tenant, TenantListDelegate, TenantListRenderer } from 'sql/workbench/services/accountManagement/browser/tenantListRenderer';
|
||||||
import { IAccountManagementService } from 'sql/platform/accounts/common/interfaces';
|
import { IAccountManagementService } from 'sql/platform/accounts/common/interfaces';
|
||||||
|
import { ADAL_AUTH_LIBRARY, AuthLibrary, getAuthLibrary } from 'sql/workbench/services/accountManagement/utils';
|
||||||
|
|
||||||
export const VIEWLET_ID = 'workbench.view.accountpanel';
|
export const VIEWLET_ID = 'workbench.view.accountpanel';
|
||||||
export type AuthLibrary = 'ADAL' | 'MSAL';
|
|
||||||
export const MSAL_AUTH_LIBRARY: AuthLibrary = 'MSAL'; // default
|
|
||||||
export const ADAL_AUTH_LIBRARY: AuthLibrary = 'ADAL';
|
|
||||||
|
|
||||||
export class AccountPaneContainer extends ViewPaneContainer { }
|
export class AccountPaneContainer extends ViewPaneContainer { }
|
||||||
|
|
||||||
@@ -392,7 +390,7 @@ export class AccountDialog extends Modal {
|
|||||||
this._splitView!.layout(DOM.getContentHeight(this._container!));
|
this._splitView!.layout(DOM.getContentHeight(this._container!));
|
||||||
|
|
||||||
// Set the initial items of the list
|
// Set the initial items of the list
|
||||||
const authLibrary: AuthLibrary = this._configurationService.getValue('azure.authenticationLibrary');
|
const authLibrary: AuthLibrary = getAuthLibrary(this._configurationService);
|
||||||
let updatedAccounts: azdata.Account[];
|
let updatedAccounts: azdata.Account[];
|
||||||
if (authLibrary) {
|
if (authLibrary) {
|
||||||
updatedAccounts = filterAccounts(newProvider.initialAccounts, authLibrary);
|
updatedAccounts = filterAccounts(newProvider.initialAccounts, authLibrary);
|
||||||
@@ -443,7 +441,7 @@ export class AccountDialog extends Modal {
|
|||||||
if (!providerMapping || !providerMapping.view) {
|
if (!providerMapping || !providerMapping.view) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const authLibrary: AuthLibrary = this._configurationService.getValue('azure.authenticationLibrary');
|
const authLibrary: AuthLibrary = getAuthLibrary(this._configurationService);
|
||||||
let updatedAccounts: azdata.Account[];
|
let updatedAccounts: azdata.Account[];
|
||||||
if (authLibrary) {
|
if (authLibrary) {
|
||||||
updatedAccounts = filterAccounts(args.accountList, authLibrary);
|
updatedAccounts = filterAccounts(args.accountList, authLibrary);
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ import { INotificationService, Severity, INotification } from 'vs/platform/notif
|
|||||||
import { Action } from 'vs/base/common/actions';
|
import { Action } from 'vs/base/common/actions';
|
||||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
import { ADAL_AUTH_LIBRARY, AuthLibrary, filterAccounts, MSAL_AUTH_LIBRARY } from 'sql/workbench/services/accountManagement/browser/accountDialog';
|
import { filterAccounts } from 'sql/workbench/services/accountManagement/browser/accountDialog';
|
||||||
|
import { ADAL_AUTH_LIBRARY, MSAL_AUTH_LIBRARY, AuthLibrary, AZURE_AUTH_LIBRARY_CONFIG, getAuthLibrary } from 'sql/workbench/services/accountManagement/utils';
|
||||||
|
|
||||||
export class AccountManagementService implements IAccountManagementService {
|
export class AccountManagementService implements IAccountManagementService {
|
||||||
// CONSTANTS ///////////////////////////////////////////////////////////
|
// CONSTANTS ///////////////////////////////////////////////////////////
|
||||||
@@ -41,7 +42,6 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
private _autoOAuthDialogController?: AutoOAuthDialogController;
|
private _autoOAuthDialogController?: AutoOAuthDialogController;
|
||||||
private _mementoContext?: Memento;
|
private _mementoContext?: Memento;
|
||||||
protected readonly disposables = new DisposableStore();
|
protected readonly disposables = new DisposableStore();
|
||||||
private readonly configurationService: IConfigurationService;
|
|
||||||
|
|
||||||
// EVENT EMITTERS //////////////////////////////////////////////////////
|
// EVENT EMITTERS //////////////////////////////////////////////////////
|
||||||
private _addAccountProviderEmitter: Emitter<AccountProviderAddedEventParams>;
|
private _addAccountProviderEmitter: Emitter<AccountProviderAddedEventParams>;
|
||||||
@@ -61,7 +61,7 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
@IOpenerService private _openerService: IOpenerService,
|
@IOpenerService private _openerService: IOpenerService,
|
||||||
@ILogService private readonly _logService: ILogService,
|
@ILogService private readonly _logService: ILogService,
|
||||||
@INotificationService private readonly _notificationService: INotificationService,
|
@INotificationService private readonly _notificationService: INotificationService,
|
||||||
@IConfigurationService configurationService: IConfigurationService
|
@IConfigurationService private _configurationService: IConfigurationService
|
||||||
) {
|
) {
|
||||||
this._mementoContext = new Memento(AccountManagementService.ACCOUNT_MEMENTO, this._storageService);
|
this._mementoContext = new Memento(AccountManagementService.ACCOUNT_MEMENTO, this._storageService);
|
||||||
const mementoObj = this._mementoContext.getMemento(StorageScope.GLOBAL, StorageTarget.MACHINE);
|
const mementoObj = this._mementoContext.getMemento(StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||||
@@ -71,11 +71,10 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
this._addAccountProviderEmitter = new Emitter<AccountProviderAddedEventParams>();
|
this._addAccountProviderEmitter = new Emitter<AccountProviderAddedEventParams>();
|
||||||
this._removeAccountProviderEmitter = new Emitter<azdata.AccountProviderMetadata>();
|
this._removeAccountProviderEmitter = new Emitter<azdata.AccountProviderMetadata>();
|
||||||
this._updateAccountListEmitter = new Emitter<UpdateAccountListEventParams>();
|
this._updateAccountListEmitter = new Emitter<UpdateAccountListEventParams>();
|
||||||
this.configurationService = configurationService;
|
|
||||||
|
|
||||||
// Determine authentication library in use, to support filtering accounts respectively.
|
// Determine authentication library in use, to support filtering accounts respectively.
|
||||||
// When this value is changed a restart is required so there isn't a need to dynamically update this value at runtime.
|
// When this value is changed a restart is required so there isn't a need to dynamically update this value at runtime.
|
||||||
this._authLibrary = this.configurationService.getValue('azure.authenticationLibrary');
|
this._authLibrary = getAuthLibrary(this._configurationService);
|
||||||
|
|
||||||
_storageService.onWillSaveState(() => this.shutdown());
|
_storageService.onWillSaveState(() => this.shutdown());
|
||||||
this.registerListeners();
|
this.registerListeners();
|
||||||
@@ -169,7 +168,6 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
if (result.accountModified) {
|
if (result.accountModified) {
|
||||||
this.spliceModifiedAccount(provider, result.changedAccount);
|
this.spliceModifiedAccount(provider, result.changedAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fireAccountListUpdate(provider, result.accountAdded);
|
this.fireAccountListUpdate(provider, result.accountAdded);
|
||||||
} finally {
|
} finally {
|
||||||
notificationHandler.close();
|
notificationHandler.close();
|
||||||
@@ -519,7 +517,7 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const authLibrary: AuthLibrary = this.configurationService.getValue('azure.authenticationLibrary');
|
const authLibrary: AuthLibrary = getAuthLibrary(this._configurationService)
|
||||||
let updatedAccounts: azdata.Account[]
|
let updatedAccounts: azdata.Account[]
|
||||||
if (authLibrary) {
|
if (authLibrary) {
|
||||||
updatedAccounts = filterAccounts(provider.accounts, authLibrary);
|
updatedAccounts = filterAccounts(provider.accounts, authLibrary);
|
||||||
@@ -543,9 +541,9 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private registerListeners(): void {
|
private registerListeners(): void {
|
||||||
this.disposables.add(this.configurationService.onDidChangeConfiguration(async e => {
|
this.disposables.add(this._configurationService.onDidChangeConfiguration(async e => {
|
||||||
if (e.affectsConfiguration('azure.authenticationLibrary')) {
|
if (e.affectsConfiguration(AZURE_AUTH_LIBRARY_CONFIG)) {
|
||||||
const authLibrary: AuthLibrary = this.configurationService.getValue('azure.authenticationLibrary') ?? MSAL_AUTH_LIBRARY;
|
const authLibrary: AuthLibrary = getAuthLibrary(this._configurationService);
|
||||||
let accounts = await this._accountStore.getAllAccounts();
|
let accounts = await this._accountStore.getAllAccounts();
|
||||||
if (accounts) {
|
if (accounts) {
|
||||||
let updatedAccounts = await this.filterAndMergeAccounts(accounts, authLibrary);
|
let updatedAccounts = await this.filterAndMergeAccounts(accounts, authLibrary);
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ const noAccountProvider: azdata.AccountProviderMetadata = {
|
|||||||
const account: azdata.Account = {
|
const account: azdata.Account = {
|
||||||
key: {
|
key: {
|
||||||
providerId: hasAccountProvider.id,
|
providerId: hasAccountProvider.id,
|
||||||
accountId: 'testAccount1'
|
accountId: 'testAccount1',
|
||||||
|
authLibrary: 'MSAL'
|
||||||
},
|
},
|
||||||
displayInfo: {
|
displayInfo: {
|
||||||
displayName: 'Test Account 1',
|
displayName: 'Test Account 1',
|
||||||
@@ -320,7 +321,12 @@ suite('Account Management Service Tests:', () => {
|
|||||||
return ams.getAccountsForProvider(hasAccountProvider.id)
|
return ams.getAccountsForProvider(hasAccountProvider.id)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
// Then: I should get back the list of accounts
|
// Then: I should get back the list of accounts
|
||||||
assert.strictEqual(result, accountList);
|
// Since account are filtered by AuthLibrary and list is prepared again, they are not strict equal.
|
||||||
|
// We compare strict equality of actual accounts here.
|
||||||
|
assert.strictEqual(accountList.length, result.length);
|
||||||
|
for (var i = 0; i < accountList.length; i++) {
|
||||||
|
assert.strictEqual(result[i], accountList[i]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -534,7 +540,8 @@ function getTestState(): AccountManagementState {
|
|||||||
const testConfigurationService = new TestConfigurationService();
|
const testConfigurationService = new TestConfigurationService();
|
||||||
|
|
||||||
// Create the account management service
|
// Create the account management service
|
||||||
let ams = new AccountManagementService(mockInstantiationService.object, new TestStorageService(), undefined!, undefined!, undefined!, testNotificationService, testConfigurationService);
|
let ams = new AccountManagementService(mockInstantiationService.object, new TestStorageService(),
|
||||||
|
undefined, undefined, undefined, testNotificationService, testConfigurationService);
|
||||||
|
|
||||||
// Wire up event handlers
|
// Wire up event handlers
|
||||||
let evUpdate = new EventVerifierSingle<UpdateAccountListEventParams>();
|
let evUpdate = new EventVerifierSingle<UpdateAccountListEventParams>();
|
||||||
|
|||||||
18
src/sql/workbench/services/accountManagement/utils.ts
Normal file
18
src/sql/workbench/services/accountManagement/utils.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
|
|
||||||
|
export const AZURE_AUTH_LIBRARY_CONFIG = 'azure.authenticationLibrary';
|
||||||
|
|
||||||
|
export type AuthLibrary = 'ADAL' | 'MSAL';
|
||||||
|
export const MSAL_AUTH_LIBRARY: AuthLibrary = 'MSAL';
|
||||||
|
export const ADAL_AUTH_LIBRARY: AuthLibrary = 'ADAL';
|
||||||
|
|
||||||
|
export const DEFAULT_AUTH_LIBRARY: AuthLibrary = MSAL_AUTH_LIBRARY;
|
||||||
|
|
||||||
|
export function getAuthLibrary(configurationService: IConfigurationService): AuthLibrary {
|
||||||
|
return configurationService.getValue(AZURE_AUTH_LIBRARY_CONFIG) || DEFAULT_AUTH_LIBRARY;
|
||||||
|
}
|
||||||
@@ -36,10 +36,11 @@ import Severity from 'vs/base/common/severity';
|
|||||||
import { ConnectionStringOptions } from 'sql/platform/capabilities/common/capabilitiesService';
|
import { ConnectionStringOptions } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||||
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
|
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
|
||||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
import { AuthLibrary, filterAccounts } from 'sql/workbench/services/accountManagement/browser/accountDialog';
|
import { filterAccounts } from 'sql/workbench/services/accountManagement/browser/accountDialog';
|
||||||
import { AuthenticationType, Actions } from 'sql/platform/connection/common/constants';
|
import { AuthenticationType, Actions } from 'sql/platform/connection/common/constants';
|
||||||
import { AdsWidget } from 'sql/base/browser/ui/adsWidget';
|
import { AdsWidget } from 'sql/base/browser/ui/adsWidget';
|
||||||
import { createCSSRule } from 'vs/base/browser/dom';
|
import { createCSSRule } from 'vs/base/browser/dom';
|
||||||
|
import { AuthLibrary, getAuthLibrary } from 'sql/workbench/services/accountManagement/utils';
|
||||||
|
|
||||||
const ConnectionStringText = localize('connectionWidget.connectionString', "Connection string");
|
const ConnectionStringText = localize('connectionWidget.connectionString', "Connection string");
|
||||||
|
|
||||||
@@ -112,7 +113,6 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
|||||||
color: undefined,
|
color: undefined,
|
||||||
description: undefined,
|
description: undefined,
|
||||||
};
|
};
|
||||||
private readonly configurationService: IConfigurationService;
|
|
||||||
constructor(options: azdata.ConnectionOption[],
|
constructor(options: azdata.ConnectionOption[],
|
||||||
callbacks: IConnectionComponentCallbacks,
|
callbacks: IConnectionComponentCallbacks,
|
||||||
providerName: string,
|
providerName: string,
|
||||||
@@ -122,7 +122,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
|||||||
@IAccountManagementService private _accountManagementService: IAccountManagementService,
|
@IAccountManagementService private _accountManagementService: IAccountManagementService,
|
||||||
@ILogService protected _logService: ILogService,
|
@ILogService protected _logService: ILogService,
|
||||||
@IErrorMessageService private _errorMessageService: IErrorMessageService,
|
@IErrorMessageService private _errorMessageService: IErrorMessageService,
|
||||||
@IConfigurationService configurationService: IConfigurationService
|
@IConfigurationService private _configurationService: IConfigurationService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this._callbacks = callbacks;
|
this._callbacks = callbacks;
|
||||||
@@ -142,7 +142,6 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
|||||||
}
|
}
|
||||||
this._providerName = providerName;
|
this._providerName = providerName;
|
||||||
this._connectionStringOptions = this._connectionManagementService.getProviderProperties(this._providerName).connectionStringOptions;
|
this._connectionStringOptions = this._connectionManagementService.getProviderProperties(this._providerName).connectionStringOptions;
|
||||||
this.configurationService = configurationService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getAuthTypeDefault(option: azdata.ConnectionOption, os: OperatingSystem): string {
|
protected getAuthTypeDefault(option: azdata.ConnectionOption, os: OperatingSystem): string {
|
||||||
@@ -691,7 +690,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
|||||||
let oldSelection = this._azureAccountDropdown.value;
|
let oldSelection = this._azureAccountDropdown.value;
|
||||||
const accounts = await this._accountManagementService.getAccounts();
|
const accounts = await this._accountManagementService.getAccounts();
|
||||||
const updatedAccounts = accounts.filter(a => a.key.providerId.startsWith('azure'));
|
const updatedAccounts = accounts.filter(a => a.key.providerId.startsWith('azure'));
|
||||||
const authLibrary: AuthLibrary = this.configurationService.getValue('azure.authenticationLibrary');
|
const authLibrary: AuthLibrary = getAuthLibrary(this._configurationService);
|
||||||
if (authLibrary) {
|
if (authLibrary) {
|
||||||
this._azureAccountList = filterAccounts(updatedAccounts, authLibrary);
|
this._azureAccountList = filterAccounts(updatedAccounts, authLibrary);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user