Ejemplo n.º 1
0
        /// <summary>
        /// Updates shared access signature authorization for the service bus namespace. This authorization works on
        /// public Microsoft Azure environments and Windows Azure Pack on prim as well.
        /// </summary>
        /// <param name="namespaceName">The service bus namespace name</param>
        /// <param name="ruleName">The SAS authorization rule name</param>
        /// <param name="primaryKey">The SAS primary key. It'll be generated if empty</param>
        /// <param name="secondaryKey">The SAS secondary key</param>
        /// <param name="permissions">Set of permissions given to the rule</param>
        /// <returns>The created Shared Access Signature authorization rule</returns>
        public virtual ExtendedAuthorizationRule UpdateSharedAccessAuthorization(
            string namespaceName,
            string ruleName,
            string primaryKey,
            string secondaryKey,
            params AccessRights[] permissions)
        {
            ExtendedAuthorizationRule oldRule = GetAuthorizationRule(namespaceName, ruleName);

            if (null == oldRule)
            {
                throw new ArgumentException(Resources.ServiceBusAuthorizationRuleNotFound);
            }

            SharedAccessAuthorizationRule rule = (SharedAccessAuthorizationRule)oldRule.Rule;

            // Update the rule
            rule.Rights       = permissions ?? rule.Rights;
            rule.PrimaryKey   = string.IsNullOrEmpty(primaryKey) ? rule.PrimaryKey : primaryKey;
            rule.SecondaryKey = string.IsNullOrEmpty(secondaryKey) ? rule.SecondaryKey : secondaryKey;

            // In case that there's nothing to update then assume user asks for primary key renewal
            if (permissions == null && string.IsNullOrEmpty(secondaryKey) && string.IsNullOrEmpty(primaryKey))
            {
                rule.PrimaryKey = SharedAccessAuthorizationRule.GenerateRandomKey();
            }

            rule = ServiceBusClient.Namespaces.UpdateAuthorizationRule(
                namespaceName,
                rule.ToServiceBusSharedAccessAuthorizationRule())
                   .AuthorizationRule.ToSharedAccessAuthorizationRule();

            return(CreateExtendedAuthorizationRule(rule, namespaceName));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates new Windows authorization rule for Service Bus. This works on Windows Azure Pack on prim only.
        /// </summary>
        /// <param name="namespaceName">The service bus namespace name</param>
        /// <param name="ruleName">The authorization rule name</param>
        /// <param name="username">The user principle name</param>
        /// <param name="permissions">Set of permissions given to the rule</param>
        /// <returns>The created Windows authorization rule</returns>
        /// Comment for now we will need this part in the future when adding Katal Authentication Rules.
        //public virtual AllowRule CreateWindowsAuthorization(
        //    string namespaceName,
        //    string ruleName,
        //    string username,
        //    params AccessRights[] permissions)
        //{
        //    AllowRule rule = new AllowRule(
        //        string.Empty,
        //        "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn",
        //        username,
        //        permissions);

        //    using (HttpClient client = CreateServiceBusHttpClient())
        //    {
        //        rule = client.PostJson(UriElement.GetNamespaceAuthorizationRulesPath(namespaceName), rule, Logger);
        //    }

        //    return rule;
        //}

        /// <summary>
        /// Creates shared access signature authorization for the service bus namespace. This authorization works on
        /// public Microsoft Azure environments and Windows Azure Pack on prim as well.
        /// </summary>
        /// <param name="namespaceName">The service bus namespace name</param>
        /// <param name="ruleName">The SAS authorization rule name</param>
        /// <param name="primaryKey">The SAS primary key. It'll be generated if empty</param>
        /// <param name="secondaryKey">The SAS secondary key</param>
        /// <param name="permissions">Set of permissions given to the rule</param>
        /// <returns>The created Shared Access Signature authorization rule</returns>
        public virtual ExtendedAuthorizationRule CreateSharedAccessAuthorization(
            string namespaceName,
            string ruleName,
            string primaryKey,
            string secondaryKey,
            params AccessRights[] permissions)
        {
            SharedAccessAuthorizationRule rule = new SharedAccessAuthorizationRule(
                ruleName,
                string.IsNullOrEmpty(primaryKey) ? SharedAccessAuthorizationRule.GenerateRandomKey() : primaryKey,
                secondaryKey,
                permissions);

            rule = ServiceBusClient.Namespaces.CreateAuthorizationRule(
                namespaceName,
                rule.ToServiceBusSharedAccessAuthorizationRule())
                   .AuthorizationRule.ToSharedAccessAuthorizationRule();

            return(CreateExtendedAuthorizationRule(rule, namespaceName));
        }
        /// <summary>
        /// Creates shared access signature authorization for the service bus namespace. This authorization works on
        /// public Microsoft Azure environments and Windows Azure Pack on prim as well.
        /// </summary>
        /// <param name="namespaceName">The service bus namespace name</param>
        /// <param name="ruleName">The SAS authorization rule name</param>
        /// <param name="primaryKey">The SAS primary key. It'll be generated if empty</param>
        /// <param name="secondaryKey">The SAS secondary key</param>
        /// <param name="permissions">Set of permissions given to the rule</param>
        /// <returns>The created Shared Access Signature authorization rule</returns>
        public virtual ExtendedAuthorizationRule CreateSharedAccessAuthorization(
            string namespaceName,
            string ruleName,
            string primaryKey,
            string secondaryKey,
            params AccessRights[] permissions)
        {
            SharedAccessAuthorizationRule rule = new SharedAccessAuthorizationRule(
                ruleName,
                string.IsNullOrEmpty(primaryKey) ? SharedAccessAuthorizationRule.GenerateRandomKey() : primaryKey,
                secondaryKey,
                permissions);

            rule = ServiceBusClient.Namespaces.CreateAuthorizationRule(
                namespaceName,
                rule.ToServiceBusSharedAccessAuthorizationRule())
                .AuthorizationRule.ToSharedAccessAuthorizationRule();
            
            return CreateExtendedAuthorizationRule(rule, namespaceName);
        }