public void WriteRequest_11() { var s = new XacmlContextSubject(new XacmlContextAttribute(new Uri("uri:action"), new Uri("uri:type"), new XacmlContextAttributeValue())); var r = new XacmlContextResource(new XacmlContextAttribute(new Uri("uri:action"), new Uri("uri:type"), new XacmlContextAttributeValue())); var a = new XacmlContextAction(new XacmlContextAttribute(new Uri("uri:action"), new Uri("uri:type"), new XacmlContextAttributeValue())); var request = new XacmlContextRequest(r, a, s); StringBuilder builder = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(builder)) { var serializer = new Xacml10ProtocolSerializer(); serializer.WriteContextRequest(writer, request); } string xml = builder.ToString(); ValidateMessage(xml, @"..\..\_Data\cs-xacml-schema-context-01.xsd"); }
public void WritePolicy_11() { var subject = new XacmlSubject( new XacmlSubjectMatch[] { new XacmlSubjectMatch( new Uri("http://www.MatchId.www"), new XacmlAttributeValue(new Uri("http://www.DataType.www")), new XacmlSubjectAttributeDesignator(new Uri("http://www.AttributeId.www"), new Uri("http://www.DataType.www")) { Issuer = "String", MustBePresent = false, Category = new Uri("http://www.subjectCategory.www") }) }); var target = new XacmlTarget(subject, null, null); XacmlPolicySet xacmlPolicySet = new XacmlPolicySet(new Uri("http://www.PolicySetId.www"), new Uri("http://www.PolicyCombiningAlgId.www"), target); xacmlPolicySet.Description = "description string"; xacmlPolicySet.XPathVersion = Xacml10Constants.XPathVersions.Xpath10; XacmlPolicy xacmlPolicy = new XacmlPolicy(new Uri("http://www.PolicyId.www"), new Uri("http://www.RuleCombiningAlgId.www"), new XacmlTarget()) { Description = "description string", XPathVersion = Xacml10Constants.XPathVersions.Xpath10, }; XacmlRule xacmlRule = new XacmlRule("http://www.RuleId.www", XacmlEffectType.Permit) { Description = "xacmlRule description" }; xacmlPolicy.Rules.Add(xacmlRule); XacmlAttributeAssignment xacmlAttributeAssignment = new XacmlAttributeAssignment(new Uri("http://www.AttributeId.www"), new Uri("http://www.DataType.www")); XacmlObligation xacmlObligation = new XacmlObligation(new Uri("http://www.ObligationId.www"), XacmlEffectType.Permit, new XacmlAttributeAssignment[] { xacmlAttributeAssignment }); xacmlPolicy.Obligations.Add(xacmlObligation); xacmlPolicySet.Policies.Add(xacmlPolicy); StringBuilder builder = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(builder)) { var serializer = new Xacml10ProtocolSerializer(); serializer.WritePolicySet(writer, xacmlPolicySet); } string xml = builder.ToString(); ValidateMessage(xml, @"..\..\_Data\cs-xacml-schema-policy-01.xsd"); }
public void ReadPolicy_11() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"..\..\_Data\XACML_Samples\1.1\Example_1\Rule_1.xml"); var serialize = new Xacml10ProtocolSerializer(); using (XmlReader reader = XmlReader.Create(new StringReader(xmlDoc.OuterXml))) { var data = serialize.ReadPolicy(reader); Assert.IsNotNull(data); } }
public void ReadResponse_11() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"..\..\_Data\XACML_Samples\1.1\Example_1\Response.xml"); var serialize = new Xacml10ProtocolSerializer(); using (XmlReader reader = XmlReader.Create(new StringReader(xmlDoc.OuterXml))) { var data = serialize.ReadContextResponse(reader); Assert.IsNotNull(data); Assert.AreEqual(1, data.Results.Count); Assert.AreEqual(XacmlContextDecision.NotApplicable, data.Results.First().Decision); } }
public void ReadRequest_11() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"..\..\_Data\XACML_Samples\1.1\Example_1\Request.xml"); var serialize = new Xacml10ProtocolSerializer(); using (XmlReader reader = XmlReader.Create(new StringReader(xmlDoc.OuterXml))) { var data = serialize.ReadContextRequest(reader); Assert.IsNotNull(data); // Subject Assert.AreEqual(1, data.Subjects.Count); { var subject = data.Subjects.First(); Assert.AreEqual(new Uri("urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"), subject.SubjectCategory); Assert.AreEqual(1, subject.Attributes.Count); { var att = subject.Attributes.First(); Assert.AreEqual(new Uri("urn:oasis:names:tc:xacml:1.0:subject:subject-id"), att.AttributeId); Assert.AreEqual(new Uri("urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name"), att.DataType); Assert.AreEqual(1, att.AttributeValues.Count); Assert.AreEqual("*****@*****.**", att.AttributeValues.First().Value); } } // Resource Assert.AreEqual(1, data.Resources.Count); { var resource = data.Resources.First(); Assert.AreEqual(1, resource.Attributes.Count); { var att = resource.Attributes.First(); Assert.AreEqual(new Uri("urn:oasis:names:tc:xacml:1.0:resource:ufspath"), att.AttributeId); Assert.AreEqual(new Uri("http://www.w3.org/2001/XMLSchema#anyURI"), att.DataType); Assert.AreEqual(1, att.AttributeValues.Count); Assert.AreEqual("/medico/record/patient/BartSimpson", att.AttributeValues.First().Value); } } // Action var action = data.Action; Assert.AreEqual(1, action.Attributes.Count); { var att = action.Attributes.First(); Assert.AreEqual(new Uri("urn:oasis:names:tc:xacml:1.0:action:action-id"), att.AttributeId); Assert.AreEqual(new Uri("http://www.w3.org/2001/XMLSchema#string"), att.DataType); Assert.AreEqual(1, att.AttributeValues.Count); Assert.AreEqual("read", att.AttributeValues.First().Value); } } }