Пример #1
0
        protected virtual void WriteContextStatus(XmlWriter writer, XacmlContextStatus xacmlContextStatus)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

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

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

            this.WriteContextStatusCode(writer, xacmlContextStatus.StatusCode);

            if (!string.IsNullOrEmpty(xacmlContextStatus.StatusMessage))
            {
                writer.WriteElementString(XacmlConstants.Prefixes.Context, XacmlConstants.ElementNames.StatusMessage, this.Version.NamespaceContext, xacmlContextStatus.StatusMessage);
            }

            if (xacmlContextStatus.StatusDetail.Count > 0)
            {
                writer.WriteStartElement(XacmlConstants.Prefixes.Context, XacmlConstants.ElementNames.StatusDetail, this.Version.NamespaceContext);

                foreach (XmlElement element in xacmlContextStatus.StatusDetail)
                {
                    element.WriteTo(writer);
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Пример #2
0
        private static void WriteContextStatus(XmlWriter writer, XacmlContextStatus xacmlContextStatus)
        {
            Guard.ArgumentNotNull(writer, nameof(writer));
            Guard.ArgumentNotNull(xacmlContextStatus, nameof(xacmlContextStatus));

            writer.WriteStartElement(XacmlConstants.Prefixes.Xacml, XacmlConstants.ElementNames.Status, Xacml30Constants.NameSpaces.Policy);

            WriteContextStatusCode(writer, xacmlContextStatus.StatusCode);

            if (!string.IsNullOrEmpty(xacmlContextStatus.StatusMessage))
            {
                writer.WriteElementString(XacmlConstants.Prefixes.Xacml, XacmlConstants.ElementNames.StatusMessage, Xacml30Constants.NameSpaces.Policy, xacmlContextStatus.StatusMessage);
            }

            if (xacmlContextStatus.StatusDetail.Count > 0)
            {
                writer.WriteStartElement(XacmlConstants.Prefixes.Xacml, XacmlConstants.ElementNames.StatusDetail, Xacml30Constants.NameSpaces.Policy);

                foreach (XmlElement element in xacmlContextStatus.StatusDetail)
                {
                    element.WriteTo(writer);
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Пример #3
0
 private static void AssertEqual(XacmlContextStatus expected, XacmlContextStatus actual)
 {
     if (expected != null)
     {
         Assert.NotNull(actual);
         Assert.Equal(expected.StatusCode.StatusCode, actual.StatusCode.StatusCode);
     }
 }
        protected virtual XacmlContextStatus ReadContextStatus(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

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

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

            // Read elements
            XacmlContextStatus result = new XacmlContextStatus(this.ReadRequired(XacmlConstants.ElementNames.StatusCode, this.Version.NamespaceContext, ReadContextStatusCode, reader));

            result.StatusMessage = this.ReadOptional(XacmlConstants.ElementNames.StatusMessage, this.Version.NamespaceContext, ReadContextStatusMessage, reader);

            if (reader.IsStartElement(XacmlConstants.ElementNames.StatusDetail, this.Version.NamespaceContext))
            {
                bool isEmptyElement = reader.IsEmptyElement;

                // XmlUtil.ValidateXsiType(reader, XacmlConstants.XmlTypes.StatusDetailType, this.Version.NamespaceContext);

                if (isEmptyElement)
                {
                    reader.Read();
                }
                else
                {
                    XmlDocument document = new XmlDocument();
                    document.PreserveWhitespace = true;
                    document.Load(reader.ReadSubtree());
                    foreach (XmlElement element in document.DocumentElement.ChildNodes)
                    {
                        result.StatusDetail.Add(element);
                    }

                    reader.ReadEndElement();
                }
            }

            reader.ReadEndElement();

            return(result);
        }