private static XElement CreateXmlAccessRule(AccessRule accessRule)
        {
            var xmlRule = new XElement(_authorizationRuleXName, new XAttribute(XName.Get("type", _xmlSchemaInstanceNamespace), "AllowRule"));
            xmlRule.Add(new XElement(XName.Get("IssuerName", _serviceBusXmlNamespace), accessRule.ServiceBusNamespace));
            xmlRule.Add(new XElement(XName.Get("ClaimType", _serviceBusXmlNamespace), _nameClaimType));
            xmlRule.Add(new XElement(XName.Get("ClaimValue", _serviceBusXmlNamespace), accessRule.UserName));

            var xmlAccessRights = new XElement(XName.Get("Rights", _serviceBusXmlNamespace));
            foreach (AccessRight right in accessRule.Permissions)
            {
                xmlAccessRights.Add(new XElement(XName.Get("AccessRights", _serviceBusXmlNamespace), right.ToString()));
            }

            xmlRule.Add(xmlAccessRights);

            return xmlRule;
        }
Beispiel #2
0
        public void CreateTopic()
        {
            var rule2 = new AccessRule { UserName = TestUsers.User2.UserName, ServiceBusNamespace = _serviceBusNamespace };
            rule2.Permissions.Add(AccessRight.Listen);

            var rule3 = new AccessRule { UserName = TestUsers.User3.UserName, ServiceBusNamespace = _serviceBusNamespace };
            rule3.Permissions.Add(AccessRight.Send);

            var rules = new List<AccessRule> { rule2, rule3 };

            XElement topicDescription = ObjectDescriptionBuilder.CreateTopicDescription(rules);

            HttpWebRequest createRequest = _requestFactory.CreateWebRequestWithData("PUT", _topicUri, topicDescription.ToString());

            _webClient.ThrowOnHttpError = true;
            HttpWebResponse response = _webClient.SendRequest(createRequest);
            _webClient.ThrowOnHttpError = false;
        }
        public void CreateQueue()
        {
            var rule1 = new AccessRule { UserName = TestUsers.User1.UserName, ServiceBusNamespace = _serviceBusNamespace };
            rule1.Permissions.Add(AccessRight.Listen);
            rule1.Permissions.Add(AccessRight.Send);

            var rule2 = new AccessRule { UserName = TestUsers.User2.UserName, ServiceBusNamespace = _serviceBusNamespace };
            rule2.Permissions.Add(AccessRight.Listen);

            var rule3 = new AccessRule { UserName = TestUsers.User3.UserName, ServiceBusNamespace = _serviceBusNamespace };
            rule3.Permissions.Add(AccessRight.Send);

            var rules = new List<AccessRule> { rule1, rule2, rule3 };

            XElement queueDescription = ObjectDescriptionBuilder.CreateQueueDescription(rules);

            WebRequestFactory requestFactory = ServiceBusHelper.GetWebRequestFactory();
            HttpWebRequest request = requestFactory.CreateWebRequestWithData("PUT", _queueUri, queueDescription.ToString());

            var webClient = new WebClientWrapper { ThrowOnHttpError = true };
            HttpWebResponse repsonse = webClient.SendRequest(request);
        }