Skip to content

Commit 7808bf5

Browse files
committed
Add Authentication method
1 parent 138732c commit 7808bf5

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

dotnet/src/dotnetcore/Providers/Messaging/GXAzureServiceBus/AzureServiceBus.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private void Initialize(GXService providerService)
4646
_connectionString = serviceSettings.GetEncryptedPropertyValue(PropertyConstants.QUEUE_CONNECTION_STRING);
4747
_subscriptionName = serviceSettings.GetEncryptedPropertyValue(PropertyConstants.TOPIC_SUBSCRIPTION);
4848
_fullyqualifiedNamespace = serviceSettings.GetEncryptedPropertyValue(PropertyConstants.FULLYQUALIFIEDNAMESPACE);
49+
string authenticationMethod = serviceSettings.GetEncryptedPropertyValue(PropertyConstants.AUTHENTICATION_METHOD);
4950

5051
string sessionEnabled = serviceSettings.GetEncryptedOptPropertyValue(PropertyConstants.SESSION_ENABLED);
5152

@@ -63,8 +64,7 @@ private void Initialize(GXService providerService)
6364
//TO DO Consider connection options here
6465
//https://docs.microsoft.com/en-us/javascript/api/@azure/service-bus/servicebusclientoptions?view=azure-node-latest#@azure-service-bus-servicebusclientoptions-websocketoptions
6566

66-
//First try authenticating using Azure Active Directory
67-
if (!string.IsNullOrEmpty(_fullyqualifiedNamespace))
67+
if (authenticationMethod.Equals(AuthenticationMethod.ActiveDirectory.ToString()))
6868
{
6969
_serviceBusClient = new ServiceBusClient(_fullyqualifiedNamespace, new DefaultAzureCredential());
7070
GXLogging.Debug(logger, "Authenticate to Azure Service Bus using Active Directory authentication.");

dotnet/src/dotnetcore/Providers/Messaging/GXAzureServiceBus/ServiceBusMessageBrokerProvider.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public MessageQueue Authenticate(string queueName, string fullyQualifiedNamespac
2727
{ PropertyConstants.PREFETCH_COUNT, options.PrefetchCount.ToString() },
2828
{ PropertyConstants.RECEIVER_IDENTIFIER, options.Identifier },
2929
{ PropertyConstants.RECEIVER_SESSIONID, options.SessionId },
30-
{ PropertyConstants.SENDER_IDENTIFIER, senderIdentifier }
30+
{ PropertyConstants.SENDER_IDENTIFIER, senderIdentifier },
31+
{ PropertyConstants.AUTHENTICATION_METHOD, AuthenticationMethod.ActiveDirectory.ToString()}
3132
};
3233

3334
MessageQueue messageQueue = messageBrokerProvider.Connect(PropertyConstants.AZURESERVICEBUS, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
@@ -51,6 +52,7 @@ public MessageQueue Authenticate(string topicName, string subcriptionName, strin
5152
properties.Add(PropertyConstants.RECEIVER_IDENTIFIER, options.Identifier);
5253
properties.Add(PropertyConstants.RECEIVER_SESSIONID, options.SessionId);
5354
properties.Add(PropertyConstants.SENDER_IDENTIFIER, senderIdentifier);
55+
properties.Add(PropertyConstants.AUTHENTICATION_METHOD, AuthenticationMethod.ActiveDirectory.ToString());
5456

5557
MessageQueue messageQueue = messageBrokerProvider.Connect(PropertyConstants.AZURESERVICEBUS, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
5658
errorMessages = errorMessagesConnect;
@@ -64,7 +66,8 @@ public MessageQueue Authenticate(string queueName, string fullyQualifiedNamespac
6466
GXProperties properties = new GXProperties
6567
{
6668
{ PropertyConstants.MESSAGEBROKER_AZURESB_QUEUENAME, queueName },
67-
{ PropertyConstants.MESSAGEBROKER_AZURESB_FULLYQUALIFIEDNAMESPACE, fullyQualifiedNamespace }
69+
{ PropertyConstants.MESSAGEBROKER_AZURESB_FULLYQUALIFIEDNAMESPACE, fullyQualifiedNamespace },
70+
{ PropertyConstants.AUTHENTICATION_METHOD, AuthenticationMethod.ActiveDirectory.ToString()}
6871
};
6972

7073
MessageQueue messageQueue = messageBrokerProvider.Connect(PropertyConstants.AZURESERVICEBUS, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
@@ -79,7 +82,8 @@ public MessageQueue Authenticate(string topicName, string subcriptionName, strin
7982
{
8083
{ PropertyConstants.MESSAGEBROKER_AZURESB_QUEUENAME, topicName },
8184
{ PropertyConstants.MESSAGEBROKER_AZURESB_SUBSCRIPTION_NAME, subcriptionName },
82-
{ PropertyConstants.MESSAGEBROKER_AZURESB_FULLYQUALIFIEDNAMESPACE, fullyQualifiedNamespace }
85+
{ PropertyConstants.MESSAGEBROKER_AZURESB_FULLYQUALIFIEDNAMESPACE, fullyQualifiedNamespace },
86+
{ PropertyConstants.AUTHENTICATION_METHOD, AuthenticationMethod.ActiveDirectory.ToString()}
8387
};
8488

8589
MessageQueue messageQueue = messageBrokerProvider.Connect(PropertyConstants.AZURESERVICEBUS, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
@@ -96,7 +100,9 @@ public MessageQueue Connect(string queueName, string connectionString, out GXBas
96100
GXProperties properties = new GXProperties
97101
{
98102
{ PropertyConstants.MESSAGEBROKER_AZURESB_QUEUENAME, queueName },
99-
{ PropertyConstants.MESSAGEBROKER_AZURESB_CONNECTIONSTRING, connectionString }
103+
{ PropertyConstants.MESSAGEBROKER_AZURESB_CONNECTIONSTRING, connectionString },
104+
{ PropertyConstants.AUTHENTICATION_METHOD, AuthenticationMethod.Password.ToString()}
105+
100106
};
101107

102108
MessageQueue messageQueue = messageBrokerProvider.Connect(PropertyConstants.AZURESERVICEBUS, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
@@ -112,7 +118,8 @@ public MessageQueue Connect(string topicName, string subcriptionName, string con
112118
{
113119
{ PropertyConstants.MESSAGEBROKER_AZURESB_QUEUENAME, topicName },
114120
{ PropertyConstants.MESSAGEBROKER_AZURESB_SUBSCRIPTION_NAME, subcriptionName },
115-
{ PropertyConstants.MESSAGEBROKER_AZURESB_CONNECTIONSTRING, connectionString }
121+
{ PropertyConstants.MESSAGEBROKER_AZURESB_CONNECTIONSTRING, connectionString },
122+
{ PropertyConstants.AUTHENTICATION_METHOD, AuthenticationMethod.Password.ToString()}
116123
};
117124

118125
MessageQueue messageQueue = messageBrokerProvider.Connect(PropertyConstants.AZURESERVICEBUS, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
@@ -135,7 +142,8 @@ public MessageQueue Connect(string queueName, string connectionString, bool sess
135142
{ PropertyConstants.PREFETCH_COUNT, options.PrefetchCount.ToString() },
136143
{ PropertyConstants.RECEIVER_IDENTIFIER, options.Identifier },
137144
{ PropertyConstants.RECEIVER_SESSIONID, options.SessionId },
138-
{ PropertyConstants.SENDER_IDENTIFIER, senderIdentifier }
145+
{ PropertyConstants.SENDER_IDENTIFIER, senderIdentifier },
146+
{ PropertyConstants.AUTHENTICATION_METHOD, AuthenticationMethod.Password.ToString()}
139147
};
140148

141149
MessageQueue messageQueue = messageBrokerProvider.Connect(PropertyConstants.AZURESERVICEBUS, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
@@ -159,6 +167,7 @@ public MessageQueue Connect(string topicName, string subcriptionName, string con
159167
properties.Add(PropertyConstants.RECEIVER_IDENTIFIER, options.Identifier);
160168
properties.Add(PropertyConstants.RECEIVER_SESSIONID, options.SessionId);
161169
properties.Add(PropertyConstants.SENDER_IDENTIFIER, senderIdentifier);
170+
properties.Add(PropertyConstants.AUTHENTICATION_METHOD, AuthenticationMethod.Password.ToString());
162171

163172
MessageQueue messageQueue = messageBrokerProvider.Connect(PropertyConstants.AZURESERVICEBUS, properties, out GXBaseCollection<SdtMessages_Message> errorMessagesConnect, out bool successConnect);
164173
errorMessages = errorMessagesConnect;

dotnet/src/dotnetcore/Providers/Messaging/GXMessageBroker/MessageBrokerProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private static void Preprocess(string name, GXProperties properties)
7676
SetEncryptedProperty(properties, PropertyConstants.MESSAGEBROKER_AZURESB_SUBSCRIPTION_NAME);
7777
SetEncryptedProperty(properties, PropertyConstants.MESSAGEBROKER_AZURESB_CONNECTIONSTRING);
7878
SetEncryptedProperty(properties, PropertyConstants.MESSAGEBROKER_AZURESB_FULLYQUALIFIEDNAMESPACE);
79+
SetEncryptedProperty(properties, PropertyConstants.AUTHENTICATION_METHOD);
7980
if (string.IsNullOrEmpty(providerService.ClassName) || !providerService.ClassName.Contains(className))
8081
{
8182
providerService.ClassName = PropertyConstants.AZURE_SB_PROVIDER_CLASSNAME;

dotnet/src/dotnetcore/Providers/Messaging/GXMessageBroker/PropertyConstants.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,12 @@ public static class PropertyConstants
2323
public const string TOPIC_SUBSCRIPTION = "SUBSCRIPTION";
2424
public const string MESSAGE_BROKER = "MESSAGEBROKER";
2525
public const string SESSION_ENABLED = "SESSION_ENABLED";
26+
27+
public const string AUTHENTICATION_METHOD = "AUTHENTICATION_METHOD";
2628
}
29+
public enum AuthenticationMethod
30+
{
31+
ActiveDirectory,
32+
Password
33+
}
2734
}

0 commit comments

Comments
 (0)