protected virtual XacmlContextSubject ReadContextSubject(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (!reader.IsStartElement(XacmlConstants.ElementNames.Subject, this.Version.NamespaceContext))
            {
                throw ThrowHelperXml(reader, "XML message is not valid.");
            }

            XacmlContextSubject result = new XacmlContextSubject();

            result.SubjectCategory = this.ReadAttribute <Uri>(reader, XacmlConstants.AttributeNames.SubjectCategory, isRequered: false);

            // Read attributes
            if (reader.IsEmptyElement)
            {
                reader.Read();
                return(result);
            }

            reader.ReadStartElement(XacmlConstants.ElementNames.Subject, this.Version.NamespaceContext);

            // Read elements
            this.ReadList(result.Attributes, XacmlConstants.ElementNames.Attribute, this.Version.NamespaceContext, this.ReadContextAttribute, reader);

            reader.ReadEndElement();

            return(result);
        }
Exemple #2
0
        protected virtual void WriteContextSubject(XmlWriter writer, XacmlContextSubject subject)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (subject == null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            writer.WriteStartElement(XacmlConstants.Prefixes.Context, XacmlConstants.ElementNames.Subject, this.Version.NamespaceContext);

            if (subject.SubjectCategory != null)
            {
                writer.WriteAttributeString(XacmlConstants.AttributeNames.SubjectCategory, subject.SubjectCategory.ToString());
            }

            foreach (var attr in subject.Attributes)
            {
                this.WriteContextAttribute(writer, attr);
            }

            writer.WriteEndElement();
        }
        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, Path.Combine(TestCasePath, "cs-xacml-schema-context-01.xsd"));
        }