mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Prevent reconnects for mssql provider (#22825)
This commit is contained in:
@@ -116,14 +116,15 @@ export class MsalCachePluginProvider {
|
|||||||
*/
|
*/
|
||||||
public async writeTokenToLocalCache(token: Token): Promise<void> {
|
public async writeTokenToLocalCache(token: Token): Promise<void> {
|
||||||
let updateCount = 0;
|
let updateCount = 0;
|
||||||
|
let indexToUpdate = -1;
|
||||||
let cache: LocalAccountCache;
|
let cache: LocalAccountCache;
|
||||||
cache = JSON.parse(await this.readCache(this._localCacheConfiguration)) as LocalAccountCache;
|
cache = JSON.parse(await this.readCache(this._localCacheConfiguration)) as LocalAccountCache;
|
||||||
if (cache?.tokens) {
|
if (cache?.tokens) {
|
||||||
cache.tokens.forEach(t => {
|
cache.tokens.forEach((t, i) => {
|
||||||
if (t.key === token.key && t.tenantId === token.tenantId && t.resource === token.resource
|
if (t.key === token.key && t.tenantId === token.tenantId && t.resource === token.resource
|
||||||
) {
|
) {
|
||||||
// Update token
|
// Update token
|
||||||
t = token;
|
indexToUpdate = i;
|
||||||
updateCount++;
|
updateCount++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -139,6 +140,9 @@ export class MsalCachePluginProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (updateCount === 1) {
|
if (updateCount === 1) {
|
||||||
|
if (indexToUpdate !== -1) {
|
||||||
|
cache.tokens[indexToUpdate] = token;
|
||||||
|
}
|
||||||
await this.writeCache(JSON.stringify(cache), this._localCacheConfiguration);
|
await this.writeCache(JSON.stringify(cache), this._localCacheConfiguration);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ export const defaultEngine = 'defaultEngine';
|
|||||||
|
|
||||||
export const passwordChars = '***************';
|
export const passwordChars = '***************';
|
||||||
|
|
||||||
|
export const enableSqlAuthenticationProviderConfig = 'mssql.enableSqlAuthenticationProvider';
|
||||||
|
|
||||||
|
|
||||||
/* default authentication type setting name*/
|
/* default authentication type setting name*/
|
||||||
export const defaultAuthenticationType = 'defaultAuthenticationType';
|
export const defaultAuthenticationType = 'defaultAuthenticationType';
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||||
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||||
import * as sqlExtHostTypes from 'sql/workbench/api/common/sqlExtHostTypes'
|
import * as sqlExtHostTypes from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||||
|
|
||||||
// CONSTANTS //////////////////////////////////////////////////////////////////////////////////////
|
// CONSTANTS //////////////////////////////////////////////////////////////////////////////////////
|
||||||
const msInH = 3.6e6;
|
const msInH = 3.6e6;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import { VIEWLET_ID as ExtensionsViewletID } from 'vs/workbench/contrib/extensio
|
|||||||
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
|
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||||
import { IErrorDiagnosticsService } from 'sql/workbench/services/diagnostics/common/errorDiagnosticsService';
|
import { IErrorDiagnosticsService } from 'sql/workbench/services/diagnostics/common/errorDiagnosticsService';
|
||||||
import { PasswordChangeDialog } from 'sql/workbench/services/connection/browser/passwordChangeDialog';
|
import { PasswordChangeDialog } from 'sql/workbench/services/connection/browser/passwordChangeDialog';
|
||||||
|
import { enableSqlAuthenticationProviderConfig, mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||||
|
|
||||||
export class ConnectionManagementService extends Disposable implements IConnectionManagementService {
|
export class ConnectionManagementService extends Disposable implements IConnectionManagementService {
|
||||||
|
|
||||||
@@ -1141,6 +1142,12 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
|
|
||||||
// We expect connectionProfile to be defined
|
// We expect connectionProfile to be defined
|
||||||
if (connectionProfile && connectionProfile.authenticationType === Constants.AuthenticationType.AzureMFA) {
|
if (connectionProfile && connectionProfile.authenticationType === Constants.AuthenticationType.AzureMFA) {
|
||||||
|
// We do not need to reconnect for MSSQL Provider, if 'SQL Authentication Provider' setting is enabled.
|
||||||
|
// Update the token in case it needs refreshing/reauthentication.
|
||||||
|
if (connectionProfile.providerName === mssqlProviderName && this.getEnableSqlAuthenticationProviderConfig()) {
|
||||||
|
await this.fillInOrClearToken(connectionProfile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const expiry = connectionProfile.options.expiresOn;
|
const expiry = connectionProfile.options.expiresOn;
|
||||||
if (typeof expiry === 'number' && !Number.isNaN(expiry)) {
|
if (typeof expiry === 'number' && !Number.isNaN(expiry)) {
|
||||||
const currentTime = new Date().getTime() / 1000;
|
const currentTime = new Date().getTime() / 1000;
|
||||||
@@ -1172,8 +1179,13 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getEnableSqlAuthenticationProviderConfig(): boolean {
|
||||||
|
return this._configurationService.getValue(enableSqlAuthenticationProviderConfig) ?? true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request Senders
|
// Request Senders
|
||||||
@@ -1598,10 +1610,9 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async listDatabases(connectionUri: string): Promise<azdata.ListDatabasesResult | undefined> {
|
public async listDatabases(connectionUri: string): Promise<azdata.ListDatabasesResult | undefined> {
|
||||||
const self = this;
|
|
||||||
await this.refreshAzureAccountTokenIfNecessary(connectionUri);
|
await this.refreshAzureAccountTokenIfNecessary(connectionUri);
|
||||||
if (self.isConnected(connectionUri)) {
|
if (this.isConnected(connectionUri)) {
|
||||||
return self.sendListDatabasesRequest(connectionUri);
|
return this.sendListDatabasesRequest(connectionUri);
|
||||||
}
|
}
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user