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

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

            XacmlContextResource result = new XacmlContextResource();

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

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

            // Read elements
            result.ResourceContent = this.ReadOptional(XacmlConstants.ElementNames.ResourceContent, this.Version.NamespaceContext, this.ReadContextResourceContent, reader);

            this.ReadList(result.Attributes, XacmlConstants.ElementNames.Attribute, this.Version.NamespaceContext, this.ReadContextAttribute, reader, isRequired: false);

            reader.ReadEndElement();

            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor user only for XACML 2.0
 /// </summary>
 /// <param name="resources">The resource.</param>
 /// <param name="action">The action.</param>
 /// <param name="subjects">The subject.</param>
 /// <param name="environment">The environment.</param>
 public XacmlContextRequest(XacmlContextResource resource, XacmlContextAction action, XacmlContextSubject subject, XacmlContextEnvironment environment) :
     this(new List<XacmlContextResource> { resource }, action, new List<XacmlContextSubject> { subject }, environment) {
     Contract.Requires<ArgumentNullException>(resource != null);
     Contract.Requires<ArgumentNullException>(action != null);
     Contract.Requires<ArgumentNullException>(subject != null);
     Contract.Requires<ArgumentNullException>(environment != null);
 }
Ejemplo n.º 3
0
        protected virtual void WriteContextResource(XmlWriter writer, XacmlContextResource resource)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

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

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

            // ResourceContent
            if (resource.ResourceContent != null)
            {
                this.WriteContextResourceContent(writer, resource.ResourceContent);
            }

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

            writer.WriteEndElement();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor user only for XACML 1.0/1.1/2.0
        /// </summary>
        /// <param name="resource">The resource.</param>
        /// <param name="action">The action.</param>
        /// <param name="subjects">The subjects.</param>
        public XacmlContextRequest(XacmlContextResource resource, XacmlContextAction action, IEnumerable<XacmlContextSubject> subjects) {
            Contract.Requires<ArgumentNullException>(resource != null);
            Contract.Requires<ArgumentNullException>(action != null);
            Contract.Requires<ArgumentNullException>(subjects != null);

            this.resources.Add(resource);
            this.action = action;
           
            foreach (var item in subjects) {
                this.subjects.Add(item);
            }
        }
        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");
        }
        protected virtual void WriteContextResource(XmlWriter writer, XacmlContextResource resource) {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(resource != null);

            writer.WriteStartElement(XacmlConstants.Prefixes.Context, XacmlConstants.ElementNames.Resource, this.version.NamespaceContext);

            // ResourceContent
            if (resource.ResourceContent != null) {
                this.WriteContextResourceContent(writer, resource.ResourceContent);
            }

            foreach (var attr in resource.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"));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructor user only for XACML 1.0/1.1/2.0
 /// </summary>
 /// <param name="resource">The resource.</param>
 /// <param name="action">The action.</param>
 /// <param name="subjects">The subjects.</param>
 public XacmlContextRequest(XacmlContextResource resource, XacmlContextAction action, XacmlContextSubject subject)
     : this(resource, action, new List<XacmlContextSubject> { subject }) {
     Contract.Requires<ArgumentNullException>(resource != null);
     Contract.Requires<ArgumentNullException>(action != null);
     Contract.Requires<ArgumentNullException>(subject != null);
 }
        protected virtual XacmlContextResource ReadContextResource(XmlReader reader) {
            Contract.Requires<ArgumentNullException>(reader != null, "reader");
            Contract.Requires<XmlException>(reader.IsStartElement(XacmlConstants.ElementNames.Resource, this.version.NamespaceContext));

            XacmlContextResource result = new XacmlContextResource();
            // Read attributes

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

            reader.ReadStartElement(XacmlConstants.ElementNames.Resource, this.version.NamespaceContext);
            // Read elements

            result.ResourceContent = this.ReadOptional(XacmlConstants.ElementNames.ResourceContent, this.version.NamespaceContext, this.ReadContextResourceContent, reader);

            this.ReadList(result.Attributes, XacmlConstants.ElementNames.Attribute, this.version.NamespaceContext, this.ReadContextAttribute, reader, isRequired: false);

            reader.ReadEndElement();

            return result;
        }