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: articles/service-bus-messaging/service-bus-migrate-azure-credentials.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,12 +20,26 @@ Application requests to Azure Service Bus must be authenticated using either acc
20
20
21
21
The following code example demonstrates how to connect to Azure Service Bus using a connection string that includes an access key. When you create a Service Bus, Azure generates these keys and connection strings automatically. Many developers gravitate towards this solution because it feels familiar to options they've worked with in the past. If your application currently uses connection strings, consider migrating to passwordless connections using the steps described in this document.
Connection strings should be used with caution. Developers must be diligent to never expose the keys in an unsecure location. Anyone who gains access to the key is able to authenticate. For example, if an account key is accidentally checked into source control, sent through an unsecure email, pasted into the wrong chat, or viewed by someone who shouldn't have permission, there's risk of a malicious user accessing the application. Instead, consider updating your application to use passwordless connections.
30
44
31
45
## Migrate to passwordless connections
@@ -48,6 +62,8 @@ For local development, make sure you're authenticated with the same Azure AD acc
48
62
49
63
Next you'll need to update your code to use passwordless connections.
50
64
65
+
# [C#](#tab/csharp)
66
+
51
67
1. To use `DefaultAzureCredential` in a .NET application, add the **Azure.Identity** NuGet package to your application.
52
68
53
69
```dotnetcli
@@ -77,6 +93,42 @@ Next you'll need to update your code to use passwordless connections.
77
93
78
94
1. Make sure to update the Service Bus namespace in the URI of your `ServiceBusClient`. You can find the namespace on the overview page of the Azure portal.
79
95
96
+
# [Java - JMS](#tab/java-jms)
97
+
98
+
1. To use `DefaultAzureCredential` in a JMS application, add at least version **1.0.0** of the **azure-servicebus-jms** package to your application.
99
+
100
+
```xml
101
+
<dependency>
102
+
<groupId>com.microsoft.azure</groupId>
103
+
<artifactId>azure-servicebus-jms</artifactId>
104
+
<version>1.0.0</version>
105
+
</dependency>
106
+
```
107
+
108
+
2. At the top of your file, add the following `import` statements:
3. Identify the locations in your code that currently create a `ServiceBusJmsConnectionFactory` to connect to Azure Service Bus. Update your code to match the following example:
116
+
117
+
```java
118
+
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder()
119
+
.build();
120
+
121
+
ServiceBusJmsConnectionFactorySettings connFactorySettings = new ServiceBusJmsConnectionFactorySettings();
//TODO: Replace the "<SERVICE-BUS-NAMESPACE-NAME>" placeholder.
125
+
ConnectionFactory factory = new ServiceBusJmsConnectionFactory(tokenCredential, "<SERVICE-BUS-NAMESPACE-NAME>.servicebus.windows.net", connFactorySettings);
126
+
```
127
+
128
+
4. Make sure to update the Service Bus namespace in the URI of your `ServiceBusJmsConnectionFactory`. You can find the namespace on the overview page of the Azure portal.
129
+
130
+
---
131
+
80
132
#### Run the app locally
81
133
82
134
After making these code changes, run your application locally. The new configuration should pick up your local credentials, such as the Azure CLI, Visual Studio, or IntelliJ. The roles you assigned to your local dev user in Azure will allow your app to connect to the Azure service locally.
0 commit comments