/// <summary> /// Writes the apply. /// </summary> /// <param name="writer">The writer.</param> /// <param name="apply">The apply.</param> protected virtual void WriteApply(XmlWriter writer, XacmlApply apply) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (apply == null) { throw new ArgumentNullException(nameof(apply)); } writer.WriteStartElement(XacmlConstants.Prefixes.Policy, XacmlConstants.ElementNames.Apply, this.Version.NamespacePolicy); this.WriteApplyType(writer, apply); writer.WriteEndElement(); }
/// <summary> /// Reads the condition. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> /// <exception cref="System.Xml.XmlException">Condition NotStartElement</exception> protected virtual XacmlExpression ReadCondition(XmlReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (!reader.IsStartElement(XacmlConstants.ElementNames.Condition, this.Version.NamespacePolicy)) { throw ThrowHelperXml(reader, "Condition NotStartElement"); } Uri functionId = this.ReadAttribute <Uri>(reader, XacmlConstants.AttributeNames.FunctionId); reader.ReadStartElement(XacmlConstants.ElementNames.Condition, this.Version.NamespacePolicy); XacmlApply apply = new XacmlApply(functionId); IDictionary <Tuple <string, string>, Action> dicts = new Dictionary <Tuple <string, string>, Action>() { { new Tuple <string, string>(XacmlConstants.ElementNames.Apply, this.Version.NamespacePolicy), () => apply.Parameters.Add(this.ReadApply(reader)) }, { new Tuple <string, string>(XacmlConstants.ElementNames.Function, this.Version.NamespacePolicy), () => apply.Parameters.Add(this.ReadFunction(reader)) }, { new Tuple <string, string>(XacmlConstants.ElementNames.AttributeValue, this.Version.NamespacePolicy), () => apply.Parameters.Add(this.ReadAttributeValue(reader)) }, { new Tuple <string, string>(XacmlConstants.ElementNames.SubjectAttributeDesignator, this.Version.NamespacePolicy), () => apply.Parameters.Add(this.ReadAttributeDesignator(reader)) }, { new Tuple <string, string>(XacmlConstants.ElementNames.ResourceAttributeDesignator, this.Version.NamespacePolicy), () => apply.Parameters.Add(this.ReadAttributeDesignator(reader)) }, { new Tuple <string, string>(XacmlConstants.ElementNames.ActionAttributeDesignator, this.Version.NamespacePolicy), () => apply.Parameters.Add(this.ReadAttributeDesignator(reader)) }, { new Tuple <string, string>(XacmlConstants.ElementNames.EnvironmentAttributeDesignator, this.Version.NamespacePolicy), () => apply.Parameters.Add(this.ReadAttributeDesignator(reader)) }, { new Tuple <string, string>(XacmlConstants.ElementNames.AttributeSelector, this.Version.NamespacePolicy), () => apply.Parameters.Add(this.ReadAttributeSelector(reader)) }, }; this.ReadChoiceMultiply(reader, dicts); reader.ReadEndElement(); return(new XacmlExpression() { Property = apply }); }
/// <summary> /// Write ApplyType (Not element!) /// </summary> /// <param name="writer"></param> /// <param name="apply"></param> private void WriteApplyType(XmlWriter writer, XacmlApply apply) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (apply == null) { throw new ArgumentNullException(nameof(apply)); } writer.WriteAttributeString(XacmlConstants.AttributeNames.FunctionId, apply.FunctionId.OriginalString); foreach (IXacmlApply applyElem in apply.Parameters) { Type applyElemType = applyElem.GetType(); if (applyElemType == typeof(XacmlAttributeSelector)) { XacmlAttributeSelector elem = applyElem as XacmlAttributeSelector; writer.WriteStartElement(XacmlConstants.Prefixes.Policy, XacmlConstants.ElementNames.AttributeSelector, this.Version.NamespacePolicy); writer.WriteAttributeString(XacmlConstants.AttributeNames.RequestContextPath, elem.Path); writer.WriteAttributeString(XacmlConstants.AttributeNames.DataType, elem.DataType.OriginalString); if (elem.MustBePresent.HasValue) { writer.WriteAttributeString(XacmlConstants.AttributeNames.DataType, XmlConvert.ToString(elem.MustBePresent.Value)); } writer.WriteEndElement(); } else if (applyElemType == typeof(XacmlResourceAttributeDesignator)) { this.WriteAttributeDesignator(writer, applyElem as XacmlResourceAttributeDesignator); } else if (applyElemType == typeof(XacmlActionAttributeDesignator)) { this.WriteAttributeDesignator(writer, applyElem as XacmlActionAttributeDesignator); } else if (applyElemType == typeof(XacmlEnvironmentAttributeDesignator)) { this.WriteAttributeDesignator(writer, applyElem as XacmlEnvironmentAttributeDesignator); } else if (applyElemType == typeof(XacmlSubjectAttributeDesignator)) { this.WriteAttributeDesignator(writer, applyElem as XacmlSubjectAttributeDesignator); } else if (applyElemType == typeof(XacmlAttributeValue)) { this.WriteAttributeValue(writer, applyElem as XacmlAttributeValue); } else if (applyElemType == typeof(XacmlFunction)) { writer.WriteStartElement(XacmlConstants.Prefixes.Policy, XacmlConstants.ElementNames.Function, this.Version.NamespacePolicy); writer.WriteAttributeString(XacmlConstants.AttributeNames.FunctionId, (applyElem as XacmlFunction).FunctionId.OriginalString); writer.WriteEndElement(); } else if (applyElemType == typeof(XacmlApply)) { this.WriteApply(writer, applyElem as XacmlApply); } } }