From e7fcda7351b4cd344883450646ad33b79ae79ca2 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com> Date: Tue, 3 Jan 2023 20:16:08 -0800 Subject: [PATCH] Filter accounts based on Auth library in accounts management service (#21501) --- .../browser/accountManagementService.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sql/workbench/services/accountManagement/browser/accountManagementService.ts b/src/sql/workbench/services/accountManagement/browser/accountManagementService.ts index 1de52112b3..4f9faed4ce 100644 --- a/src/sql/workbench/services/accountManagement/browser/accountManagementService.ts +++ b/src/sql/workbench/services/accountManagement/browser/accountManagementService.ts @@ -36,6 +36,7 @@ export class AccountManagementService implements IAccountManagementService { public _providers: { [id: string]: AccountProviderWithMetadata } = {}; public _serviceBrand: undefined; private _accountStore: AccountStore; + private _authLibrary: AuthLibrary; private _accountDialogController?: AccountDialogController; private _autoOAuthDialogController?: AutoOAuthDialogController; private _mementoContext?: Memento; @@ -72,6 +73,10 @@ export class AccountManagementService implements IAccountManagementService { this._updateAccountListEmitter = new Emitter(); this.configurationService = configurationService; + // 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. + this._authLibrary = this.configurationService.getValue('azure.authenticationLibrary'); + _storageService.onWillSaveState(() => this.shutdown()); this.registerListeners(); } @@ -221,9 +226,11 @@ export class AccountManagementService implements IAccountManagementService { let self = this; // 1) Get the accounts from the store - // 2) Update our local cache of accounts + // 2) Filter the accounts based on the auth library + // 3) Update our local cache of accounts return this.doWithProvider(providerId, provider => { return self._accountStore.getAccountsByProvider(provider.metadata.id) + .then(accounts => this._authLibrary ? filterAccounts(accounts, this._authLibrary) : accounts) .then(accounts => { self._providers[providerId].accounts = accounts; return accounts; @@ -232,10 +239,11 @@ export class AccountManagementService implements IAccountManagementService { } /** - * Retrieves all the accounts registered with ADS. + * Retrieves all the accounts registered with ADS based on auth library in use. */ public getAccounts(): Promise { - return this._accountStore.getAllAccounts(); + return this._accountStore.getAllAccounts() + .then(accounts => this._authLibrary ? filterAccounts(accounts, this._authLibrary) : accounts); } /**