Skip to content

Commit 6200b71

Browse files
authored
Merge pull request #231230 from EldertGrootenboer/service-bus-aad-auth-jms
Added documentation for AAD authentication for Service Bus JMS API
2 parents 41c1bb8 + c495c63 commit 6200b71

File tree

2 files changed

+65
-14
lines changed

2 files changed

+65
-14
lines changed

articles/service-bus-messaging/jms-developer-guide.md

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.date: 02/12/2022
99

1010
This guide contains detailed information to help you succeed in communicating with Azure Service Bus using the Java Message Service (JMS) 2.0 API.
1111

12-
As a Java developer, if you are new to Azure Service Bus, please consider reading the below articles.
12+
As a Java developer, if you're new to Azure Service Bus, please consider reading the below articles.
1313

1414
| Getting started | Concepts |
1515
|----------------|-------|
@@ -51,24 +51,75 @@ The connection factory object is used by the client to connect with the JMS prov
5151

5252
Each connection factory is an instance of `ConnectionFactory`, `QueueConnectionFactory` or `TopicConnectionFactory` interface.
5353

54-
To simplify connecting with Azure Service Bus, these interfaces are implemented through `ServiceBusJmsConnectionFactory`, `ServiceBusJmsQueueConnectionFactory` and `ServiceBusJmsTopicConnectionFactory` respectively. The Connection factory can be instantiated with the below parameters -
54+
To simplify connecting with Azure Service Bus, these interfaces are implemented through `ServiceBusJmsConnectionFactory`, `ServiceBusJmsQueueConnectionFactory` and `ServiceBusJmsTopicConnectionFactory` respectively.
55+
56+
> [!IMPORTANT]
57+
> Java applications leveraging JMS 2.0 API can connect to Azure Service Bus using the connection string, or using a `TokenCredential` for leveraging Azure Active Directory (AAD) backed authentication.
58+
59+
# [System Assigned Managed Identity](#tab/system-assigned-managed-identity-backed-authentication)
60+
61+
Create a [system assigned managed identity](../active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm.md) on Azure, and use this identity to create a `TokenCredential`.
62+
63+
```java
64+
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
65+
```
66+
67+
The Connection factory can then be instantiated with the below parameters.-
68+
* Token credential - Represents a credential capable of providing an OAuth token.
69+
* Connection string - the connection string for the Azure Service Bus Premium tier namespace.
70+
* ServiceBusJmsConnectionFactorySettings property bag, which contains
71+
* connectionIdleTimeoutMS - idle connection timeout in milliseconds.
72+
* traceFrames - boolean flag to collect AMQP trace frames for debugging.
73+
* *other configuration parameters*
74+
75+
The factory can be created as shown here. The connection string is a required parameter, but the other properties are optional.
76+
77+
```java
78+
String host = "<YourNamespaceName>.servicebus.windows.net";
79+
ConnectionFactory factory = new ServiceBusJmsConnectionFactory(tokenCredential, host, null);
80+
```
81+
82+
# [User Assigned Managed Identity](#tab/user-assigned-managed-identity-backed-authentication)
83+
84+
Create a [user assigned managed identity](../active-directory/managed-identities-azure-resources/how-manage-user-assigned-managed-identities.md?pivots=identity-mi-methods-azp#create-a-user-assigned-managed-identity) on Azure, and use this identity to create a `TokenCredential`.
85+
86+
```java
87+
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder()
88+
.managedIdentityClientId("<clientIDOfUserAssignedIdentity>")
89+
.build();
90+
```
91+
92+
The Connection factory can then be instantiated with the below parameters.-
93+
* Token credential - Represents a credential capable of providing an OAuth token.
94+
* Connection string - the connection string for the Azure Service Bus Premium tier namespace.
95+
* ServiceBusJmsConnectionFactorySettings property bag, which contains
96+
* connectionIdleTimeoutMS - idle connection timeout in milliseconds.
97+
* traceFrames - boolean flag to collect AMQP trace frames for debugging.
98+
* *other configuration parameters*
99+
100+
The factory can be created as shown here. The connection string is a required parameter, but the other properties are optional.
101+
102+
```java
103+
String host = "<YourNamespaceName>.servicebus.windows.net";
104+
ConnectionFactory factory = new ServiceBusJmsConnectionFactory(tokenCredential, host, null);
105+
```
106+
107+
# [Connection string authentication](#tab/connection-string-authentication)
108+
109+
The Connection factory can be instantiated with the below parameters -
55110
* Connection string - the connection string for the Azure Service Bus Premium tier namespace.
56-
* ServiceBusJmsConnectionFactorySettings property bag which contains
111+
* ServiceBusJmsConnectionFactorySettings property bag, which contains
57112
* connectionIdleTimeoutMS - idle connection timeout in milliseconds.
58113
* traceFrames - boolean flag to collect AMQP trace frames for debugging.
59114
* *other configuration parameters*
60115

61-
The factory can be created as below. The connection string is a required parameter, but the additional properties are optional.
116+
The factory can be created as shown here. The connection string is a required parameter, but the other properties are optional.
62117

63118
```java
64119
ConnectionFactory factory = new ServiceBusJmsConnectionFactory(SERVICE_BUS_CONNECTION_STRING, null);
65120
```
66121

67-
> [!IMPORTANT]
68-
> Java applications leveraging JMS 2.0 API must connect to Azure Service Bus using the connection string only. Currently, authentication for JMS clients is only supported using the Connection string.
69-
>
70-
> Azure active directory (AAD) backed authentication is not currently supported.
71-
>
122+
---
72123

73124
### JMS destination
74125

@@ -78,7 +129,7 @@ Destinations map to entities in Azure Service Bus - queues (in point to point sc
78129

79130
### Connections
80131

81-
A connection encapsulates a virtual connection with a JMS provider. With Azure Service Bus,this represents a stateful connection between the application and Azure Service Bus over AMQP.
132+
A connection encapsulates a virtual connection with a JMS provider. With Azure Service Bus, this represents a stateful connection between the application and Azure Service Bus over AMQP.
82133

83134
A connection is created from the connection factory as shown below.
84135

@@ -107,7 +158,7 @@ A session can be created with any of the below modes.
107158
|**Session.DUPS_OK_ACKNOWLEDGE**|This acknowledgment mode instructs the session to lazily acknowledge the delivery of messages.|
108159
|**Session.SESSION_TRANSACTED**|This value may be passed as the argument to the method createSession(int sessionMode) on the Connection object to specify that the session should use a local transaction.|
109160

110-
When the session mode is not specified, the **Session.AUTO_ACKNOWLEDGE** is picked by default.
161+
When the session mode isn't specified, the **Session.AUTO_ACKNOWLEDGE** is picked by default.
111162

112163
### JMSContext
113164

@@ -129,13 +180,13 @@ Just like the **Session** object, the JMSContext can be created with the same ac
129180
JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE);
130181
```
131182

132-
When the mode is not specified, the **JMSContext.AUTO_ACKNOWLEDGE** is picked by default.
183+
When the mode isn't specified, the **JMSContext.AUTO_ACKNOWLEDGE** is picked by default.
133184

134185
### JMS message producers
135186

136187
A message producer is an object that is created using a JMSContext or a Session and used for sending messages to a destination.
137188

138-
It can be created either as a stand alone object as below -
189+
It can be created either as a stand-alone object as below -
139190

140191
```java
141192
JMSProducer producer = context.createProducer();

articles/service-bus-messaging/migrate-jms-activemq-to-servicebus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ As part of migrating and modifying your client applications to interact with Azu
5858

5959
#### Authentication and authorization
6060

61-
Azure role-based access control (Azure RBAC), backed by Azure Active Directory, is the preferred authentication mechanism for Service Bus. Because Azure RBAC, or claim-based authentication, isn't currently supported by Apache QPID JMS, however, you should use SAS keys for authentication.
61+
Azure role-based access control (Azure RBAC), backed by Azure Active Directory, is the preferred authentication mechanism for Service Bus. To enable role-based access control, please follow the steps in the [Azure Service Bus JMS 2.0 developer guide](jms-developer-guide.md).
6262

6363
## Pre-migration
6464

0 commit comments

Comments
 (0)