You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/connect/jdbc/connecting-using-azure-active-directory-authentication.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Connecting using Azure Active Directory authentication
3
3
description: Learn how to develop Java applications that use the Azure Active Directory authentication feature with the Microsoft JDBC Driver for SQL Server.
4
4
ms.custom: ""
5
-
ms.date: 04/14/2021
5
+
ms.date: 05/24/2021
6
6
ms.reviewer: ""
7
7
ms.prod: sql
8
8
ms.prod_service: connectivity
@@ -33,7 +33,7 @@ Connection properties to support Azure Active Directory authentication in the Mi
33
33
-**ActiveDirectoryInteractive**
34
34
- Supported since driver version **v9.2**, `authentication=ActiveDirectoryInteractive` can be used to connect to an Azure SQL Database/Synapse Analytics using an interactive authentication flow (multi-factor authentication).
35
35
-**ActiveDirectoryServicePrincipal**
36
-
- Supported since driver version **v9.2**, `authentication=ActiveDirectoryServicePrincipal` can be used to connect to an Azure SQL Database/Synapse Analytics using the client ID and secret of a service principal identity.
36
+
- Supported since driver version **v9.2**, `authentication=ActiveDirectoryServicePrincipal` can be used to connect to an Azure SQL Database/Synapse Analytics using the application/client ID and secret of a service principal identity.
37
37
-**SqlPassword**
38
38
- Use `authentication=SqlPassword` to connect to a SQL Server using userName/user and password properties.
39
39
-**NotSpecified**
@@ -326,9 +326,9 @@ public class AADInteractive {
326
326
SQLServerDataSource ds =newSQLServerDataSource();
327
327
ds.setServerName("aad-managed-demo.database.windows.net"); // Replace with your server name
328
328
ds.setDatabaseName("demo"); // Replace with your database
ds.setUser("bob@cqclinic.onmicrosoft.com"); // Replace with your user name
333
333
334
334
try (Connection connection = ds.getConnection();
@@ -370,17 +370,19 @@ The following example shows how to use `authentication=ActiveDirectoryServicePri
370
370
Before building and running the example:
371
371
372
372
1. On the client machine (on which, you want to run the example), download the [Microsoft Authentication Library (MSAL) for Java](https://github.com/AzureAD/microsoft-authentication-library-for-java) and its dependencies for JDBC Driver 9.1 and above, or [Microsoft Azure Active Directory Authentication Library (ADAL) for Java](https://github.com/AzureAD/azure-activedirectory-library-for-java) and its dependencies for driver versions prior to JDBC Driver 9.1, and include them in the Java build path
373
+
373
374
2. Locate the following lines of code and replace the server/database name with your server/database name.
374
375
375
376
```java
376
377
ds.setServerName("aad-managed-demo.database.windows.net"); // replace 'aad-managed-demo' with your server name
377
378
ds.setDatabaseName("demo"); // replace with your database name
378
379
```
379
380
380
-
3.Locate the following lines of code and replace user name, with the name of the AzureADuser you want to connect as.
381
+
3.Locate the following lines of code and replace principalId with the ApplicationID/ClientIDof the AzureADservice principal you want to connect as.
381
382
382
383
```java
383
-
ds.setUser("bob@cqclinic.onmicrosoft.com"); // replace with your user name
384
+
String principalId ="1846943b-ad04-4808-aa13-4702d908b5c1"; // Replace with your AAD service principal ID.
385
+
String principalSecret ="..."; // Replace with your AAD principal secret.
384
386
```
385
387
386
388
The example to use ActiveDirectoryInteractive authentication mode:
@@ -421,11 +420,11 @@ public class AADServicePrincipal {
421
420
If a connection is established, you should see the following message as output:
422
421
423
422
```output
424
-
You have successfully logged on as: <your user name>
423
+
You have successfully logged on as: <your app/client ID>
425
424
```
426
425
427
426
> [!NOTE]
428
-
> A contained user database must exist and a contained database user representing the specified Azure AD user or one of the groups the specified Azure AD user belongs to, must exist in the database and must have the CONNECT permission (except for an Azure Active Directory server admin or group)
427
+
> A contained user database must exist and a contained database user representing the specified Azure AD principal or one of the groups the specified Azure AD principal belongs to, must exist in the database and must have the CONNECT permission (except for an Azure Active Directory server admin or group)
429
428
430
429
## Connecting using access token
431
430
@@ -486,19 +485,19 @@ public class AADTokenBased {
486
485
String clientId ="1846943b-ad04-4808-aa13-4702d908b5c1"; // Replace with your client ID.
487
486
String clientSecret ="..."; // Replace with your client secret.
0 commit comments