Exemplo n.º 1
0
        private List <T> GetAuthorizationRuleCore <T>(string namespaceName) where T : class
        {
            List <T> rules = null;

            using (HttpClient client = CreateServiceBusHttpClient())
            {
                rules = client.GetJson <List <T> >(
                    UriElement.GetNamespaceAuthorizationRulesPath(namespaceName),
                    Logger);
            }

            return(rules);
        }
Exemplo 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>
        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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates shared access signature authorization for the service bus namespace. This authorization works on
        /// public Windows 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);

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

            return(CreateExtendedAuthorizationRule(rule, namespaceName));
        }