Skip to content

Commit 4b55fbc

Browse files
authored
Adding Active Directory Default support (#21828)
* Initial changes * Hiding irrelevant "user" field back * loc * Updating STS and showing/hiding userId appropriately for AD Default * Beefing up telemetry
1 parent f37de66 commit 4b55fbc

19 files changed

Lines changed: 138 additions & 28 deletions

extensions/mssql/l10n/bundle.l10n.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,7 @@
17831783
"Integrated": "Integrated",
17841784
"SQL Login": "SQL Login",
17851785
"Microsoft Entra Id - Universal w/ MFA Support": "Microsoft Entra Id - Universal w/ MFA Support",
1786+
"Microsoft Entra Id - Default": "Microsoft Entra Id - Default",
17861787
"Azure Code Grant": "Azure Code Grant",
17871788
"Azure Device Code": "Azure Device Code",
17881789
"MSSQL - Azure Auth Logs": "MSSQL - Azure Auth Logs",
@@ -2267,8 +2268,8 @@
22672268
"Clear cache and refresh token": "Clear cache and refresh token",
22682269
"Clear token cache": "Clear token cache",
22692270
"No workspaces found. Please change Fabric account or tenant to view available workspaces.": "No workspaces found. Please change Fabric account or tenant to view available workspaces.",
2270-
"Unsupported authentication type in connection string: {0}. Only SQL Login, Integrated, and Azure MFA authentication are supported./{0} is the authentication type": {
2271-
"message": "Unsupported authentication type in connection string: {0}. Only SQL Login, Integrated, and Azure MFA authentication are supported.",
2271+
"Unsupported authentication type in connection string: {0}. Only SQL Login, Integrated, Azure MFA, and Active Directory Default authentication are supported./{0} is the authentication type": {
2272+
"message": "Unsupported authentication type in connection string: {0}. Only SQL Login, Integrated, Azure MFA, and Active Directory Default authentication are supported.",
22722273
"comment": ["{0} is the authentication type"]
22732274
},
22742275
"Add Firewall Rule to {0}/{0} is the server name": {

extensions/mssql/src/connectionconfig/connectionDialogWebviewController.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ export class ConnectionDialogWebviewController extends FormWebviewController<
541541
AuthenticationType.SqlLogin,
542542
AuthenticationType.Integrated,
543543
AuthenticationType.AzureMFA,
544+
AuthenticationType.ActiveDirectoryDefault,
544545
];
545546

546547
if (
@@ -925,9 +926,24 @@ export class ConnectionDialogWebviewController extends FormWebviewController<
925926
async updateItemVisibility() {
926927
let hiddenProperties: (keyof IConnectionDialogProfile)[] = [];
927928

929+
if (
930+
this.state.connectionProfile.authenticationType !== AuthenticationType.SqlLogin &&
931+
this.state.connectionProfile.authenticationType !==
932+
AuthenticationType.ActiveDirectoryDefault
933+
) {
934+
hiddenProperties.push("user");
935+
}
928936
if (this.state.connectionProfile.authenticationType !== AuthenticationType.SqlLogin) {
929-
hiddenProperties.push("user", "password", "savePassword");
937+
hiddenProperties.push("password", "savePassword");
930938
}
939+
940+
const userComponent = this.state.formComponents["user"];
941+
if (userComponent) {
942+
// userId is required for SQL Login, optional for AD Default, and hidden (above) for everything else
943+
userComponent.required =
944+
this.state.connectionProfile.authenticationType === AuthenticationType.SqlLogin;
945+
}
946+
931947
if (this.state.connectionProfile.authenticationType !== AuthenticationType.AzureMFA) {
932948
hiddenProperties.push("accountId", "tenantId");
933949
}

extensions/mssql/src/constants/locConstants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export let authTypeName = l10n.t("authenticationType");
176176
export let authTypeIntegrated = l10n.t("Integrated");
177177
export let authTypeSql = l10n.t("SQL Login");
178178
export let authTypeAzureActiveDirectory = l10n.t("Microsoft Entra Id - Universal w/ MFA Support");
179+
export let authTypeAzureActiveDirectoryDefault = l10n.t("Microsoft Entra Id - Default");
179180
export let azureAuthTypeCodeGrant = l10n.t("Azure Code Grant");
180181
export let azureAuthTypeDeviceCode = l10n.t("Azure Device Code");
181182
export let azureLogChannelName = l10n.t("MSSQL - Azure Auth Logs");
@@ -1036,7 +1037,7 @@ export class ConnectionDialog {
10361037
public static unsupportedAuthType(authenticationType: string) {
10371038
return l10n.t({
10381039
message:
1039-
"Unsupported authentication type in connection string: {0}. Only SQL Login, Integrated, and Azure MFA authentication are supported.",
1040+
"Unsupported authentication type in connection string: {0}. Only SQL Login, Integrated, Azure MFA, and Active Directory Default authentication are supported.",
10401041
args: [authenticationType],
10411042
comment: ["{0} is the authentication type"],
10421043
});

extensions/mssql/src/controllers/connectionManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,8 @@ export default class ConnectionManager {
13331333
connectionSource: connectionSource,
13341334
},
13351335
undefined,
1336+
credentials,
1337+
undefined,
13361338
true, // include call stack
13371339
);
13381340

@@ -1404,7 +1406,7 @@ export default class ConnectionManager {
14041406
*/
14051407
connectionActivity.endFailed(
14061408
error,
1407-
false, // Do not include error message as it might contain sensitive info
1409+
false, // includeErrorMessage
14081410
);
14091411
return false;
14101412
}

extensions/mssql/src/controllers/queryRunner.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,12 @@ export default class QueryRunner {
238238
const cancelQueryActivity = startActivity(
239239
TelemetryViews.QueryEditor,
240240
TelemetryActions.CancelQuery,
241-
undefined,
242-
undefined,
243-
undefined,
244-
true, // Include call stack
241+
undefined, // correlationId
242+
undefined, // startActivityAdditionalProps
243+
undefined, // startActivityAdditionalMeasurements
244+
undefined, // connectionInfo
245+
undefined, // serverInfo
246+
true, // include callstack in telemetry
245247
);
246248
const cancelParams: QueryCancelParams = { ownerUri: this._ownerUri };
247249
let cancelRequestCompleted = false;
@@ -316,12 +318,14 @@ export default class QueryRunner {
316318
const runStatementActivity = startActivity(
317319
TelemetryViews.QueryEditor,
318320
TelemetryActions.RunQuery,
319-
undefined,
321+
undefined, // correlationId
320322
{
321323
executionType: "statement",
322324
hasExecutionPlan: executionPlanOptions ? "true" : "false",
323325
},
324-
undefined,
326+
undefined, // startActivityAdditionalMeasurements
327+
undefined, // connectionInfo
328+
undefined, // serverInfo
325329
true, // Include call stack
326330
);
327331
let runStatementRequestCompleted = false;
@@ -392,7 +396,9 @@ export default class QueryRunner {
392396
executionType: queryType,
393397
hasExecutionPlan: executionPlanOptions ? "true" : "false",
394398
},
395-
undefined,
399+
undefined, // startActivityAdditionalMeasurements
400+
undefined, // connectionInfo
401+
undefined, // serverInfo
396402
true, // Include call stack
397403
);
398404

@@ -640,11 +646,13 @@ export default class QueryRunner {
640646
const rowsFetchActivity = startActivity(
641647
TelemetryViews.QueryEditor,
642648
TelemetryActions.GetResultRowsSubset,
643-
undefined,
644-
undefined,
649+
undefined, // correlationId
650+
undefined, // startActivityAdditionalProps
645651
{
646652
rowCount: bucketizeRowCount(numberOfRows),
647653
},
654+
undefined, // connectionInfo
655+
undefined, // serverInfo
648656
true, // Include call stack
649657
);
650658
try {

extensions/mssql/src/controllers/webviewBaseController.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,14 @@ export abstract class WebviewBaseController<State, Reducers> implements vscode.D
366366
const reducerActivity = startActivity(
367367
TelemetryViews.WebviewController,
368368
TelemetryActions.Reducer,
369-
undefined,
369+
undefined, // correlationId
370370
{
371371
type: action.type as string,
372372
webviewId: this._sourceFile,
373373
},
374-
undefined,
374+
undefined, // startActivityAdditionalMeasurements
375+
undefined, // connectionInfo
376+
undefined, // serverInfo
375377
true, // include call stack
376378
);
377379
const reducer = this._reducerHandlers.get(action.type);
@@ -440,12 +442,14 @@ export abstract class WebviewBaseController<State, Reducers> implements vscode.D
440442
const handlerActivity = startActivity(
441443
TelemetryViews.WebviewController,
442444
TelemetryActions.OnRequest,
443-
undefined,
445+
undefined, // correlationId
444446
{
445447
type: type.method,
446448
webviewId: this._sourceFile,
447449
},
448-
undefined,
450+
undefined, // startActivityAdditionalMeasurements
451+
undefined, // connectionInfo
452+
undefined, // serverInfo
449453
true, // include call stack
450454
);
451455
try {

extensions/mssql/src/models/connectionCredentials.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ export class ConnectionCredentials implements IConnectionInfo {
243243
name: LocalizedConstants.authTypeAzureActiveDirectory,
244244
value: utils.authTypeToString(AuthenticationTypes.AzureMFA),
245245
},
246+
{
247+
name: LocalizedConstants.authTypeAzureActiveDirectoryDefault,
248+
value: utils.authTypeToString(AuthenticationTypes.ActiveDirectoryDefault),
249+
},
246250
];
247251

248252
return choices;

extensions/mssql/src/models/connectionProfile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export class ConnectionProfile extends ConnectionCredentials implements IConnect
6666
if (this.authenticationType) {
6767
if (
6868
this.authenticationType === AuthenticationTypes[AuthenticationTypes.Integrated] ||
69-
this.authenticationType === AuthenticationTypes[AuthenticationTypes.AzureMFA]
69+
this.authenticationType === AuthenticationTypes[AuthenticationTypes.AzureMFA] ||
70+
this.authenticationType ===
71+
AuthenticationTypes[AuthenticationTypes.ActiveDirectoryDefault]
7072
) {
7173
return utils.isNotEmpty(this.server);
7274
} else {

extensions/mssql/src/models/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export enum AuthenticationTypes {
3131
Integrated = 1,
3232
SqlLogin = 2,
3333
AzureMFA = 3,
34+
ActiveDirectoryDefault = 4,
3435
}
3536

3637
export enum EncryptOptions {

extensions/mssql/src/objectExplorer/objectExplorerService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ export class ObjectExplorerService {
762762
);
763763
if (choice === LocalizedConstants.ObjectExplorer.FailedOEConnectionErrorSignIn) {
764764
try {
765-
await VsCodeAzureHelper.signIn(); // User chose to sign in to the missing account; try again.
765+
await VsCodeAzureHelper.signIn(true); // User chose to sign in to the missing account; try again.
766766
return await prepareConnectionProfile();
767767
} catch (retryError) {
768768
this._logger.error(

0 commit comments

Comments
 (0)