Пример #1
0
		/// <summary>
		/// Creates an instance of a TargetMatchBase with the values specified.
		/// </summary>
		/// <param name="matchId">The match id</param>
		/// <param name="attributeValue">The attribute value instance.</param>
		/// <param name="attributeReference">An attribute reference instance.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		protected TargetMatchBaseReadWrite( string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion schemaVersion )
			: base( XacmlSchema.Policy, schemaVersion )
		{
			_id = matchId;
			_attributeValue = attributeValue;
			_attributeReference = attributeReference;
		}
 /// <summary>
 /// Creates an instance of a TargetMatchBase with the values specified.
 /// </summary>
 /// <param name="matchId">The match id</param>
 /// <param name="attributeValue">The attribute value instance.</param>
 /// <param name="attributeReference">An attribute reference instance.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 protected TargetMatchBaseReadWrite(string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _id                 = matchId;
     _attributeValue     = attributeValue;
     _attributeReference = attributeReference;
 }
Пример #3
0
        private void CreateAttributeValue(object sender, EventArgs args)
        {
            pol.AttributeValueElementReadWrite attr = new pol.AttributeValueElementReadWrite(InternalDataTypes.XsdString, "TODO: Add content", XacmlVersion.Version11);
            AttributeValue node = new AttributeValue(attr);

            tvwCondition.Nodes.Add(node);
            _condition.Arguments.Add(attr);
        }
Пример #4
0
        private void CreateAttributeValueFromFunction(object sender, EventArgs args)
        {
            FunctionExecution func = (FunctionExecution)tvwCondition.SelectedNode;

            pol.ApplyBaseReadWrite parentApply = func.ApplyBaseDefinition;

            pol.AttributeValueElementReadWrite attr = new pol.AttributeValueElementReadWrite(InternalDataTypes.XsdString, "TODO: Add content", XacmlVersion.Version11);
            AttributeValue node = new AttributeValue(attr);

            func.Nodes.Add(node);
            parentApply.Arguments.Add(attr);
        }
 /// <summary>
 /// Creates an instance of the TargetMatchBase class using the XmlReader specified, the name of the node that defines
 /// the match (the name of the node changes depending on the target item that defines it) and the attribute
 /// designator node name which also changes depending on the target item that defines the match.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the "matchNodeName" node.</param>
 /// <param name="matchNodeName">The name of the match node for this target item.</param>
 /// <param name="attributeDesignatorNode">The name of the attribute designator node for this target item.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 protected TargetMatchBaseReadWrite(XmlReader reader, string matchNodeName, string attributeDesignatorNode, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (reader.LocalName == matchNodeName && ValidateSchema(reader, schemaVersion))
     {
         _id = reader.GetAttribute(MatchElement.MatchId);
         while (reader.Read())
         {
             if (reader.LocalName == PolicySchema1.AttributeValueElement.AttributeValue &&
                 ValidateSchema(reader, schemaVersion) &&
                 reader.NodeType != XmlNodeType.EndElement)
             {
                 _attributeValue = new AttributeValueElementReadWrite(reader, schemaVersion);
             }
             else if (reader.LocalName == attributeDesignatorNode &&
                      ValidateSchema(reader, schemaVersion) &&
                      reader.NodeType != XmlNodeType.EndElement)
             {
                 _attributeReference = CreateAttributeDesignator(reader);
             }
             else if (reader.LocalName == PolicySchema1.AttributeSelectorElement.AttributeSelector &&
                      ValidateSchema(reader, schemaVersion) &&
                      reader.NodeType != XmlNodeType.EndElement)
             {
                 _attributeReference = new AttributeSelectorElement(reader, schemaVersion);
             }
             else if (reader.LocalName == matchNodeName &&
                      reader.NodeType == XmlNodeType.EndElement)
             {
                 break;
             }
         }
     }
     else
     {
         throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, reader.LocalName]);
     }
 }
Пример #6
0
 /// <summary>
 /// Creates an instance of the ResourceMatch class using the specified arguments.
 /// </summary>
 /// <param name="matchId">The function id for this match.</param>
 /// <param name="attributeValue">The attribute value to use as the first parameter to the function.</param>
 /// <param name="attributeReference">The attribute reference in the context document.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public ResourceMatchElementReadWrite(string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion version) :
     base(matchId, attributeValue, attributeReference, version)
 {
 }
Пример #7
0
        /// <summary>
        /// Evaluates the variable into a value.
        /// </summary>
        /// <param name="context">The contex of the evaluation.</param>
        /// <returns>The value of the function.</returns>
        public EvaluationValue Evaluate(EvaluationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            context.Trace("Evaluating variable");
            context.AddIndent();

            try
            {
                if (_variableDefinition.Expression is pol.ApplyElement)
                {
                    context.Trace("Apply within condition.");

                    // There is a nested apply un this policy a new Apply will be created and also
                    // evaluated. It's return value will be used as the processed argument.
                    Apply _childApply = new Apply((pol.ApplyElement)_variableDefinition.Expression);

                    // Evaluate the Apply
                    _value = _childApply.Evaluate(context);

                    context.TraceContextValues();
                    return(_value);
                }
                else if (_variableDefinition.Expression is pol.FunctionElement)
                {
                    throw new NotImplementedException("FunctionElement");                       //TODO:
                }
                else if (_variableDefinition.Expression is pol.VariableReferenceElement)
                {
                    pol.VariableReferenceElement variableRef = _variableDefinition.Expression as pol.VariableReferenceElement;
                    VariableDefinition           variableDef = context.CurrentPolicy.VariableDefinition[variableRef.VariableId] as VariableDefinition;

                    context.TraceContextValues();

                    if (!variableDef.IsEvaluated)
                    {
                        return(variableDef.Evaluate(context));
                    }
                    else
                    {
                        return(variableDef.Value);
                    }
                }
                else if (_variableDefinition.Expression is pol.AttributeValueElementReadWrite)
                {
                    // The AttributeValue does not need to be processed
                    context.Trace("Attribute value {0}", _variableDefinition.Expression.ToString());

                    pol.AttributeValueElementReadWrite att            = (pol.AttributeValueElementReadWrite)_variableDefinition.Expression;
                    pol.AttributeValueElement          attributeValue = new pol.AttributeValueElement(att.DataType, att.Contents, att.SchemaVersion);

                    _value = new EvaluationValue(
                        attributeValue.GetTypedValue(attributeValue.GetType(context), 0),
                        attributeValue.GetType(context));
                    return(_value);
                }
                else if (_variableDefinition.Expression is pol.AttributeDesignatorBase)
                {
                    // Resolve the AttributeDesignator using the EvaluationEngine public methods.
                    context.Trace("Processing attribute designator: {0}", _variableDefinition.Expression.ToString());

                    pol.AttributeDesignatorBase attrDes = (pol.AttributeDesignatorBase)_variableDefinition.Expression;
                    BagValue bag = EvaluationEngine.Resolve(context, attrDes);

                    // If the attribute was not resolved by the EvaluationEngine search the
                    // attribute in the context document, also using the EvaluationEngine public
                    // methods.
                    if (bag.BagSize == 0)
                    {
                        if (_variableDefinition.Expression is pol.SubjectAttributeDesignatorElement)
                        {
                            ctx.AttributeElement attrib = EvaluationEngine.GetAttribute(context, attrDes);
                            if (attrib != null)
                            {
                                context.Trace("Adding subject attribute designator: {0}", attrib.ToString());
                                bag.Add(attrib);
                            }
                        }
                        else if (_variableDefinition.Expression is pol.ResourceAttributeDesignatorElement)
                        {
                            ctx.AttributeElement attrib = EvaluationEngine.GetAttribute(context, attrDes);
                            if (attrib != null)
                            {
                                context.Trace("Adding resource attribute designator {0}", attrib.ToString());
                                bag.Add(attrib);
                            }
                        }
                        else if (_variableDefinition.Expression is pol.ActionAttributeDesignatorElement)
                        {
                            ctx.AttributeElement attrib = EvaluationEngine.GetAttribute(context, attrDes);
                            if (attrib != null)
                            {
                                context.Trace("Adding action attribute designator {0}", attrib.ToString());
                                bag.Add(attrib);
                            }
                        }
                        else if (_variableDefinition.Expression is pol.EnvironmentAttributeDesignatorElement)
                        {
                            ctx.AttributeElement attrib = EvaluationEngine.GetAttribute(context, attrDes);
                            if (attrib != null)
                            {
                                context.Trace("Adding environment attribute designator {0}", attrib.ToString());
                                bag.Add(attrib);
                            }
                        }
                    }

                    // If the argument was not found and the attribute must be present this is
                    // a MissingAttribute situation so set the flag. Otherwise add the attribute
                    // to the processed arguments.
                    if (bag.BagSize == 0 && attrDes.MustBePresent)
                    {
                        context.Trace("Attribute is missing");
                        context.IsMissingAttribute = true;
                        context.AddMissingAttribute(attrDes);
                        _value = EvaluationValue.Indeterminate;
                    }
                    else
                    {
                        _value = new EvaluationValue(bag, bag.GetType(context));
                    }
                    return(_value);
                }
                else if (_variableDefinition.Expression is pol.AttributeSelectorElement)
                {
                    // Resolve the XPath query using the EvaluationEngine public methods.
                    context.Trace("Attribute selector");
                    try
                    {
                        pol.AttributeSelectorElement attributeSelector = (pol.AttributeSelectorElement)_variableDefinition.Expression;
                        BagValue bag = EvaluationEngine.Resolve(context, attributeSelector);
                        if (bag.Elements.Count == 0 && attributeSelector.MustBePresent)
                        {
                            context.Trace("Attribute is missing");
                            context.IsMissingAttribute = true;
                            context.AddMissingAttribute(attributeSelector);
                            _value = EvaluationValue.Indeterminate;
                        }
                        else
                        {
                            _value = new EvaluationValue(bag, bag.GetType(context));
                        }
                    }
                    catch (EvaluationException e)
                    {
                        context.Trace("ERR: {0}", e.Message);
                        context.ProcessingError = true;
                        _value = EvaluationValue.Indeterminate;
                    }
                    return(_value);
                }
                throw new NotSupportedException("internal error");
            }
            finally
            {
                _isEvaluated = true;
                context.RemoveIndent();
            }
        }
Пример #8
0
		private void CreateAttributeValue( object sender, EventArgs args )
		{
			pol.AttributeValueElementReadWrite attr = new pol.AttributeValueElementReadWrite( InternalDataTypes.XsdString, "TODO: Add content", XacmlVersion.Version11 );
			AttributeValue node = new AttributeValue( attr );

			tvwCondition.Nodes.Add( node );
			_condition.Arguments.Add( attr );
		}
Пример #9
0
		private void CreateAttributeValueFromFunction( object sender, EventArgs args )
		{
			FunctionExecution func = (FunctionExecution)tvwCondition.SelectedNode;
			pol.ApplyBaseReadWrite parentApply = func.ApplyBaseDefinition;

			pol.AttributeValueElementReadWrite attr = new pol.AttributeValueElementReadWrite( InternalDataTypes.XsdString, "TODO: Add content", XacmlVersion.Version11 );
			AttributeValue node = new AttributeValue( attr );

			func.Nodes.Add( node );
			parentApply.Arguments.Add( attr );
		}
Пример #10
0
		/// <summary>
		/// Creates an instance of the TargetMatchBase class using the XmlReader specified, the name of the node that defines
		/// the match (the name of the node changes depending on the target item that defines it) and the attribute
		/// designator node name which also changes depending on the target item that defines the match.
		/// </summary>
		/// <param name="reader">The XmlReader positioned at the "matchNodeName" node.</param>
		/// <param name="matchNodeName">The name of the match node for this target item.</param>
		/// <param name="attributeDesignatorNode">The name of the attribute designator node for this target item.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		protected TargetMatchBaseReadWrite( XmlReader reader, string matchNodeName, string attributeDesignatorNode, XacmlVersion schemaVersion )
			: base( XacmlSchema.Policy, schemaVersion )
		{
            if (reader == null) throw new ArgumentNullException("reader");
			if( reader.LocalName == matchNodeName && ValidateSchema( reader, schemaVersion ) )
			{
				_id = reader.GetAttribute( MatchElement.MatchId );
				while( reader.Read() )
				{
					if( reader.LocalName == PolicySchema1.AttributeValueElement.AttributeValue && 
						ValidateSchema( reader, schemaVersion ) && 
						reader.NodeType != XmlNodeType.EndElement )
					{
						_attributeValue = new AttributeValueElementReadWrite( reader, schemaVersion );
					}
					else if( reader.LocalName == attributeDesignatorNode && 
						ValidateSchema( reader, schemaVersion ) && 
						reader.NodeType != XmlNodeType.EndElement )
					{
						_attributeReference = CreateAttributeDesignator( reader );
					}
					else if( reader.LocalName == PolicySchema1.AttributeSelectorElement.AttributeSelector && 
						ValidateSchema( reader, schemaVersion ) && 
						reader.NodeType != XmlNodeType.EndElement )
					{
						_attributeReference = new AttributeSelectorElement( reader, schemaVersion );
					}
					else if( reader.LocalName == matchNodeName && 
						reader.NodeType == XmlNodeType.EndElement )
					{
						break;
					}
				}
			}
			else
			{
				throw new Exception( Resource.ResourceManager[ Resource.MessageKey.exc_invalid_node_name, reader.LocalName ] );
			}
		}
Пример #11
0
 /// <summary>
 /// Creates an instance of a TargetMatchBase with the values specified.
 /// </summary>
 /// <param name="matchId">The match id</param>
 /// <param name="attributeValue">The attribute value instance.</param>
 /// <param name="attributeReference">An attribute reference instance.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 protected TargetMatchBase(string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion schemaVersion)
     : base(matchId, attributeValue, attributeReference, schemaVersion)
 {
 }
		/// <summary>
		/// Creates an instance of the EnvironmentMatch class using the specified arguments.
		/// </summary>
		/// <param name="matchId">The function id for this match.</param>
		/// <param name="attributeValue">The attribute value to use as the first parameter to the function.</param>
		/// <param name="attributeReference">The attribute reference in the context document.</param>
		/// <param name="version">The version of the schema that was used to validate.</param>
		public EnvironmentMatchElementReadWrite( string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion version ) : 
			base( matchId, attributeValue, attributeReference, version )
		{
		}
Пример #13
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="attributeValue"></param>
		public AttributeValue( pol.AttributeValueElementReadWrite attributeValue )
		{
			_attributeValue = attributeValue;

			this.Text = "[" + attributeValue.DataType + "] " + attributeValue.Contents;
		}
Пример #14
0
 /// <summary>
 /// Creates an instance of the EnvironmentMatch class using the specified arguments.
 /// </summary>
 /// <param name="matchId">The function id for this match.</param>
 /// <param name="attributeValue">The attribute value to use as the first parameter to the function.</param>
 /// <param name="attributeReference">The attribute reference in the context document.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public EnvironmentMatchElement(string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion version) :
     base(matchId, attributeValue, attributeReference, version)
 {
 }
Пример #15
0
		/// <summary>
		/// Creates an instance of a TargetMatchBase with the values specified.
		/// </summary>
		/// <param name="matchId">The match id</param>
		/// <param name="attributeValue">The attribute value instance.</param>
		/// <param name="attributeReference">An attribute reference instance.</param>
		/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
		protected TargetMatchBase( string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion schemaVersion )
			: base( matchId, attributeValue, attributeReference, schemaVersion )
		{
		}
Пример #16
0
		/// <summary>
		/// Creates an instance of the ResourceMatch class using the specified arguments.
		/// </summary>
		/// <param name="matchId">The function id for this match.</param>
		/// <param name="attributeValue">The attribute value to use as the first parameter to the function.</param>
		/// <param name="attributeReference">The attribute reference in the context document.</param>
		/// <param name="version">The version of the schema that was used to validate.</param>
		public ResourceMatchElement( string matchId, AttributeValueElementReadWrite attributeValue, AttributeReferenceBase attributeReference, XacmlVersion version ) : 
			base( matchId, attributeValue, attributeReference, version )
		{
		}
Пример #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="attributeValue"></param>
        public AttributeValue(pol.AttributeValueElementReadWrite attributeValue)
        {
            _attributeValue = attributeValue;

            this.Text = "[" + attributeValue.DataType + "] " + attributeValue.Contents;
        }