public void ParseXACMLPolicy_IIIA030Policy()
        {
            XmlDocument policyDocument = new XmlDocument();

            policyDocument.Load(Path.Combine(GetConformanceTestPath(), "IIIA030Policy.xml"));

            XacmlPolicy result;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
            {
                result = XacmlParser.ParseXacmlPolicy(reader);
            }

            Assert.NotNull(result);
            Assert.Equal(2, result.Rules.Count);

            XacmlRule firstRule = result.Rules.Where(r => r.RuleId.Equals("urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:rule1")).FirstOrDefault();

            Assert.NotNull(firstRule);
            Assert.Equal(XacmlEffectType.Deny, firstRule.Effect);
            Assert.Equal("A subject whose name is J. Hibbert may not\n            read Bart Simpson's medical record.  NOTAPPLICABLE", firstRule.Description.Trim());
            Assert.NotNull(firstRule.Target);
            Assert.Equal(1, firstRule.Target.AnyOf.Count);

            XacmlRule secondRule = result.Rules.Where(r => r.RuleId.Equals("urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:rule2")).FirstOrDefault();

            Assert.NotNull(secondRule);
            Assert.Equal(XacmlEffectType.Permit, secondRule.Effect);
            Assert.Equal("A subject who is at least 5 years older than Bart\n            Simpson may read Bart Simpson's medical record. PERMIT.", secondRule.Description.Trim());
            Assert.Null(secondRule.Target);
        }
        public void ParseXACMLPolicy_IIA001Policy()
        {
            XmlDocument policyDocument = new XmlDocument();

            policyDocument.Load(Path.Combine(GetConformanceTestPath(), "IIA001Policy.xml"));

            XacmlPolicy result;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
            {
                result = XacmlParser.ParseXacmlPolicy(reader);
            }

            Assert.NotNull(result);
            Assert.Equal("Policy for Conformance Test IIA001.", result.Description.Trim());
            Assert.Equal(1, result.Rules.Count);

            XacmlRule firstRule = result.Rules.Where(r => r.RuleId.Equals("urn:oasis:names:tc:xacml:2.0:conformance-test:IIA1:rule")).FirstOrDefault();

            Assert.NotNull(firstRule);

            Assert.Equal(XacmlEffectType.Permit, firstRule.Effect);
            Assert.Equal("Julius Hibbert can read or write Bart Simpson's medical record.", firstRule.Description.Trim());
            Assert.NotNull(firstRule.Target);

            Assert.Equal(3, firstRule.Target.AnyOf.Count);
        }
Exemplo n.º 3
0
        public void ParseXACMLPolicy_Rule1()
        {
            XmlDocument policyDocument = new XmlDocument();

            policyDocument.Load(Path.Combine(GetSpecExamplesTestPath(), "Rule1.xml"));

            XacmlPolicy result;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
            {
                result = XacmlParser.ParseXacmlPolicy(reader);
            }

            Assert.NotNull(result);
            Assert.Null(result.Description);
            Assert.Equal(1, result.Rules.Count);

            XacmlRule firstRule = result.Rules.Where(r => r.RuleId.Equals("urn:oasis:names:tc:xacml:3.0:example:ruleid:1")).FirstOrDefault();

            Assert.NotNull(firstRule);

            Assert.Equal(XacmlEffectType.Permit, firstRule.Effect);
            Assert.Equal("A person may read any medical record in the\n      http://www.med.example.com/schemas/record.xsd namespace\n      for which he or she is the designated patient", firstRule.Description.Trim());
            Assert.NotNull(firstRule.Target);

            Assert.Equal(2, firstRule.Target.AnyOf.Count);
        }
Exemplo n.º 4
0
        public void SerializedXACMLPolicy_ShouldBeEqual()
        {
            XmlDocument policyDocument = new XmlDocument();

            policyDocument.Load(Path.Combine(GetAltinnAppsPath(), "AltinnApps0001Policy.xml"));

            XacmlPolicy originalPolicy;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
            {
                originalPolicy = XacmlParser.ParseXacmlPolicy(reader);
            }

            MemoryStream dataStream = new MemoryStream();
            XmlWriter    writer     = XmlWriter.Create(dataStream);

            XacmlSerializer.WritePolicy(writer, originalPolicy);

            writer.Flush();
            dataStream.Position = 0;

            XacmlPolicy serializedPolicy;

            using (XmlReader reader = XmlReader.Create(dataStream))
            {
                serializedPolicy = XacmlParser.ParseXacmlPolicy(reader);
            }

            AssertionUtil.AssertPolicyEqual(originalPolicy, serializedPolicy);
        }
Exemplo n.º 5
0
        public static XacmlPolicy ParsePolicyContent(string policyContent)
        {
            XacmlPolicy policy;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyContent)))
            {
                policy = XacmlParser.ParseXacmlPolicy(reader);
            }

            return(policy);
        }
Exemplo n.º 6
0
        private static XacmlPolicy ParsePolicy(Stream stream)
        {
            stream.Position = 0;
            XacmlPolicy policy;

            using (XmlReader reader = XmlReader.Create(stream))
            {
                policy = XacmlParser.ParseXacmlPolicy(reader);
            }

            return(policy);
        }
Exemplo n.º 7
0
        private async Task <ActionResult> AuthorizeXmlRequest(XacmlRequestApiModel model)
        {
            XacmlContextRequest request;

            using (XmlReader reader = XmlReader.Create(new StringReader(model.BodyContent)))
            {
                request = XacmlParser.ReadContextRequest(reader);
            }

            XacmlContextResponse xacmlContextResponse = await Authorize(request);

            return(CreateResponse(xacmlContextResponse));
        }
        public static XacmlPolicy ParsePolicy(string policyDocumentTitle, string policyPath)
        {
            XmlDocument policyDocument = new XmlDocument();

            policyDocument.Load(Path.Combine(policyPath, policyDocumentTitle));
            XacmlPolicy policy;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
            {
                policy = XacmlParser.ParseXacmlPolicy(reader);
            }

            return(policy);
        }
Exemplo n.º 9
0
        public static XacmlContextRequest ParseRequest(string requestDocumentTitle, string requestPath)
        {
            XmlDocument requestDocument = new XmlDocument();

            requestDocument.Load(Path.Combine(requestPath, requestDocumentTitle));
            XacmlContextRequest contextRequest;

            using (XmlReader reader = XmlReader.Create(new StringReader(requestDocument.OuterXml)))
            {
                contextRequest = XacmlParser.ReadContextRequest(reader);
            }

            return(contextRequest);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Parses a XACML Response document
        /// </summary>
        /// <param name="responseDocumentTitle">The response document title</param>
        /// <param name="responsePath">The response path</param>
        /// <returns></returns>
        public static XacmlContextResponse ParseResponse(string responseDocumentTitle, string responsePath)
        {
            XmlDocument responseDocument = new XmlDocument();

            responseDocument.Load(Path.Combine(responsePath, responseDocumentTitle));
            XacmlContextResponse contextResponeExpected;

            using (XmlReader reader = XmlReader.Create(new StringReader(responseDocument.OuterXml)))
            {
                contextResponeExpected = XacmlParser.ReadContextResponse(reader);
            }

            return(contextResponeExpected);
        }
        public void ParseXACMLRequest_IIA001Request()
        {
            XmlDocument policyDocument = new XmlDocument();

            policyDocument.Load(Path.Combine(GetConformanceTestPath(), "IIA001Request.xml"));

            XacmlContextRequest result;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
            {
                result = XacmlParser.ReadContextRequest(reader);
            }

            Assert.NotNull(result);
        }
Exemplo n.º 12
0
        public void ParseXACMLPolicy()
        {
            XmlDocument policyDocument = new XmlDocument();

            policyDocument.Load(Path.Combine(GetAltinnAppsPath(), "AltinnApps0001Policy.xml"));

            XacmlPolicy result;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
            {
                result = XacmlParser.ParseXacmlPolicy(reader);
            }

            Assert.NotNull(result);
            Assert.Equal(2, result.Rules.Count);
        }
Exemplo n.º 13
0
        public void SerializeXACMLPolicy_ShouldBeUnequal()
        {
            XmlDocument policyDocument = new XmlDocument();

            policyDocument.Load(Path.Combine(GetAltinnAppsPath(), "AltinnApps0001Policy.xml"));

            XacmlPolicy originalPolicy;

            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
            {
                originalPolicy = XacmlParser.ParseXacmlPolicy(reader);
            }

            MemoryStream dataStream = new MemoryStream();
            XmlWriter    writer     = XmlWriter.Create(dataStream);

            XacmlSerializer.WritePolicy(writer, originalPolicy);

            writer.Flush();
            dataStream.Position = 0;

            XacmlPolicy serializedPolicy;

            using (XmlReader reader = XmlReader.Create(dataStream))
            {
                serializedPolicy = XacmlParser.ParseXacmlPolicy(reader);
            }

            // Change a bottom node value on serialized policy model to verify that Assertion should fail
            string originalAttributeValue = originalPolicy.Rules.First().Target.AnyOf.First().AllOf.First().Matches.First().AttributeValue.Value;
            string actualAttributeValue   = "THIS IS NOT THE VALUE YOU ARE LOOKING FOR";

            serializedPolicy.Rules.First().Target.AnyOf.First().AllOf.First().Matches.First().AttributeValue.Value = actualAttributeValue;

            try
            {
                AssertionUtil.AssertPolicyEqual(originalPolicy, serializedPolicy);
            }
            catch (EqualException e)
            {
                Assert.Equal(e.Expected, originalAttributeValue);
                Assert.Equal(e.Actual, actualAttributeValue);
            }
        }
Exemplo n.º 14
0
        public static async Task <XacmlContextResponse> GetXacmlContextResponseAsync(HttpClient client, HttpRequestMessage httpRequestMessage)
        {
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            XacmlContextResponse contextResponse;

            XmlReaderSettings settings = new XmlReaderSettings
            {
                DtdProcessing = DtdProcessing.Parse
            };

            using (XmlReader reader2 = XmlReader.Create(new StringReader(responseContent), settings))
            {
                contextResponse = XacmlParser.ReadContextResponse(reader2);
            }

            return(contextResponse);
        }
Exemplo n.º 15
0
        private XacmlContextRequest ParseApiBody(XacmlRequestApiModel model)
        {
            XacmlContextRequest request = null;

            if (Request.ContentType.Contains("application/json"))
            {
                XacmlJsonRequestRoot jsonRequest;
                jsonRequest = (XacmlJsonRequestRoot)JsonConvert.DeserializeObject(model.BodyContent, typeof(XacmlJsonRequestRoot));
                request     = XacmlJsonXmlConverter.ConvertRequest(jsonRequest.Request);
            }
            else if (Request.ContentType.Contains("application/xml"))
            {
                using (XmlReader reader = XmlReader.Create(new StringReader(model.BodyContent)))
                {
                    request = XacmlParser.ReadContextRequest(reader);
                }
            }

            return(request);
        }