public virtual ExtendedAuthorizationRule CreateSharedAccessAuthorization(
string namespaceName,
string entityName,
ServiceBusEntityType entityType,
string ruleName,
string primaryKey,
string secondaryKey,
params AccessRights[] permissions)
{
// Create the SAS authorization rule
SharedAccessAuthorizationRule rule = new SharedAccessAuthorizationRule(
ruleName,
string.IsNullOrEmpty(primaryKey) ? SharedAccessAuthorizationRule.GenerateRandomKey() : primaryKey,
secondaryKey,
permissions);
// Create namespace manager
NamespaceManager namespaceManager = CreateNamespaceManager(namespaceName);
// Add the SAS rule and update the entity
switch (entityType)
{
case ServiceBusEntityType.Queue:
QueueDescription queue = namespaceManager.GetQueue(entityName);
queue.Authorization.Add(rule);
namespaceManager.UpdateQueue(queue);
break;
case ServiceBusEntityType.Topic:
TopicDescription topic = namespaceManager.GetTopic(entityName);
topic.Authorization.Add(rule);
namespaceManager.UpdateTopic(topic);
break;
case ServiceBusEntityType.Relay:
RelayDescription relay = namespaceManager.GetRelayAsync(entityName).Result;
relay.Authorization.Add(rule);
namespaceManager.UpdateRelayAsync(relay).Wait();
break;
case ServiceBusEntityType.NotificationHub:
NotificationHubDescription notificationHub = namespaceManager.GetNotificationHub(entityName);
notificationHub.Authorization.Add(rule);
namespaceManager.UpdateNotificationHub(notificationHub);
break;
default:
throw new Exception(string.Format(Resources.ServiceBusEntityTypeNotFound, entityType.ToString()));
}
return CreateExtendedAuthorizationRule(rule, namespaceName, entityName, entityType);
}