创建和删除Azure Service Bus主题的订阅的最低权限?

时间:2017-05-10 17:49:43

标签: .net azure permissions azure-servicebus-topics

我正在创建一个应用程序,需要在azure服务总线中创建和删除已创建主题的订阅。

我的共享访问令牌是否需要管理该主题的权限才能创建和删除订阅?我做了一些初步的谷歌搜索,我找不到的文章都没有显示三个角色(管理,发送,收听)与订阅实体的相关性。

谢谢!

更新 我已直接在该主题上创建了共享访问策略,然后我编写了以下代码以接触主题,创建订阅,然后通过IDisposable接口取消/处理它们:

public class SubscriptionHandler : IDisposable
{
    protected NamespaceManager SubManager { get; set; }
    protected SubscriptionDescription SubDetails { get; set; }
    public SubscriptionClient Client { get; }

    public SubscriptionHandler(AuthDetails details)
    {
        try
        {
            var connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
            SubManager = NamespaceManager.CreateFromConnectionString(connectionString);
            SubDetails = new SubscriptionDescription("topic", $"record{details.ID}.Other{details.OtherID}");
            if (!SubManager.SubscriptionExists(SubDetails.TopicPath, SubDetails.Name))
            {   //setting subscription to receive all bookings that are for the given businessID
                SubManager.CreateSubscription(SubDetails, new SqlFilter($"ID = {details.ID}"));
            }

            Client = SubscriptionClient.CreateFromConnectionString(connectionString, SubDetails.TopicPath, SubDetails.Name);
        }catch (Exception ex)
        {
            throw;
        }
    }

    public void Dispose()
    {
        if(Client != null)
        {
            Client.Close(); // telling subscription we are no longer going to recieve messages
        }

        if (SubManager != null && SubManager.SubscriptionExists(SubDetails.TopicPath, SubDetails.Name))
        {
            SubManager.DeleteSubscription(SubDetails.TopicPath, SubDetails.Name);
        }
    }

然而,我仍然在

上抛出未经授权的异常
  

SubManager.CreateSubscription(SubDetails,new SqlFilter($" ID = {details.ID}"));   呼叫。我从SharedAccessPolicy连接字符串复制了连接字符串,然后删除了EntityPath名称值对....我做错了什么?

1 个答案:

答案 0 :(得分:1)

  

我的共享访问令牌是否需要管理该主题的权限才能创建和删除订阅?

正如官方文档中提到的Rights required for Service Bus operationsCreate a subscriptionDelete subscription操作需要管理权限。

如果没有Manage权限,当您处理Create / Delete订阅操作时,您将得到如下的401响应:

enter image description here