Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XacmlMatch"/> class.
        /// </summary>
        /// <param name="matchId">The match identifier.</param>
        /// <param name="attributeValue">The attribute value.</param>
        /// <param name="attributeDesignator">The attribute designator.</param>
        public XacmlMatch(Uri matchId, XacmlAttributeValue attributeValue, XacmlAttributeDesignator attributeDesignator) {
            Contract.Requires<ArgumentNullException>(matchId != null);
            Contract.Requires<ArgumentNullException>(attributeValue != null);
            Contract.Requires<ArgumentNullException>(attributeDesignator != null);

            this.matchId = matchId;
            this.attributeValue = attributeValue;
            this.attributeDesignator = attributeDesignator;
        }
        /// <summary>
        /// Writes the attribute designator.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="data">The data.</param>
        protected override void WriteAttributeDesignator(XmlWriter writer, XacmlAttributeDesignator data) {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(data != null);

            writer.WriteStartElement(XacmlConstants.Prefixes.Policy, XacmlConstants.ElementNames.AttributeDesignator, this.version.NamespacePolicy);

            writer.WriteAttributeString(XacmlConstants.AttributeNames.Category, data.Category.OriginalString);
            writer.WriteAttributeString(XacmlConstants.AttributeNames.AttributeId, data.AttributeId.OriginalString);
            writer.WriteAttributeString(XacmlConstants.AttributeNames.DataType, data.DataType.OriginalString);
            writer.WriteAttributeString(XacmlConstants.AttributeNames.MustBePresent, XmlConvert.ToString(data.MustBePresent.HasValue && data.MustBePresent.Value));

            if (!string.IsNullOrEmpty(data.Issuer)) {
                writer.WriteAttributeString(XacmlConstants.AttributeNames.Issuer, data.Issuer);
            }

            writer.WriteEndElement();
        }
        protected IEnumerable<string> GetAttributeDesignator(XacmlAttributeDesignator designator) {
            Contract.Requires<ArgumentNullException>(designator != null);

            IEnumerable<string> attributeBag = this.pip.GetAttributeDesignatorValues(
                    designator.AttributeId,
                    designator.DataType,
                    designator.Issuer,
                    designator.Category
                    );

            if (attributeBag.Count() == 0) {
                if (designator.MustBePresent.HasValue && designator.MustBePresent.Value) {
                    // return "Indeterminate”
                    return null;
                }
            }

            return attributeBag;
        }
        /// <summary>
        /// Writes the attribute designator.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="data">The data.</param>
        protected virtual void WriteAttributeDesignator(XmlWriter writer, XacmlAttributeDesignator data) {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(data != null);

            Action<string, dynamic, bool> action = (designatorType, attributeDesignator, writeSubjectCategory) => {
                writer.WriteStartElement(XacmlConstants.Prefixes.Policy, designatorType, this.version.NamespacePolicy);
                writer.WriteAttributeString(XacmlConstants.AttributeNames.AttributeId, attributeDesignator.AttributeId.OriginalString);
                writer.WriteAttributeString(XacmlConstants.AttributeNames.DataType, attributeDesignator.DataType.OriginalString);

                if (attributeDesignator.Issuer != null) {
                    writer.WriteAttributeString(XacmlConstants.AttributeNames.Issuer, attributeDesignator.Issuer);
                }

                if (attributeDesignator.MustBePresent != null) {
                    writer.WriteAttributeString(XacmlConstants.AttributeNames.MustBePresent, XmlConvert.ToString(attributeDesignator.MustBePresent));
                }

                if (writeSubjectCategory == true && attributeDesignator.Category != null) {
                    writer.WriteAttributeString(XacmlConstants.AttributeNames.SubjectCategory, attributeDesignator.Category.OriginalString);
                }

                writer.WriteEndElement();
            };

            var subjectAttributeDesignator = data as XacmlSubjectAttributeDesignator;
            if (subjectAttributeDesignator != null) {
                action(XacmlConstants.ElementNames.SubjectAttributeDesignator, subjectAttributeDesignator, true);
            }

            var resourceAttributeDesignator = data as XacmlResourceAttributeDesignator;
            if (resourceAttributeDesignator != null) {
                action(XacmlConstants.ElementNames.ResourceAttributeDesignator, resourceAttributeDesignator, false);
            }

            var actionAttributeDesignator = data as XacmlActionAttributeDesignator;
            if (actionAttributeDesignator != null) {
                action(XacmlConstants.ElementNames.ActionAttributeDesignator, actionAttributeDesignator, false);
            }
        }
        /// <summary>
        /// Writes the attribute designator.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="data">The data.</param>
        protected override void WriteAttributeDesignator(XmlWriter writer, XacmlAttributeDesignator data) {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(data != null);

            Action<string, dynamic, bool> action = (designatorType, attributeDesignator, writeSubjectCategory) => {
                writer.WriteStartElement(XacmlConstants.Prefixes.Policy, designatorType, this.version.NamespacePolicy);
                writer.WriteAttributeString(XacmlConstants.AttributeNames.AttributeId, attributeDesignator.AttributeId.OriginalString);
                writer.WriteAttributeString(XacmlConstants.AttributeNames.DataType, attributeDesignator.DataType.OriginalString);

                if (attributeDesignator.Issuer != null) {
                    writer.WriteAttributeString(XacmlConstants.AttributeNames.Issuer, attributeDesignator.Issuer);
                }

                if (attributeDesignator.MustBePresent != null) {
                    writer.WriteAttributeString(XacmlConstants.AttributeNames.MustBePresent, XmlConvert.ToString(attributeDesignator.MustBePresent));
                }

                writer.WriteEndElement();
            };

            var environmentAttributeDesignator = data as XacmlEnvironmentAttributeDesignator;
            if (environmentAttributeDesignator != null) {
                action(XacmlConstants.ElementNames.EnvironmentAttributeDesignator, environmentAttributeDesignator, false);
            }
            else {
                base.WriteAttributeDesignator(writer, data);
            }
        }