/// <summary>
 /// Method called by the EvaluationEngine when an attribute is not found.
 /// </summary>
 /// <param name="context">The evaluation context instance.</param>
 /// <param name="designator">The attribute designator.</param>
 /// <returns>An instance of an Attribute with it's value.</returns>
 public ctx.AttributeElement GetAttribute(rtm.EvaluationContext context, pol.AttributeDesignatorBase designator)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (designator == null)
     {
         throw new ArgumentNullException("designator");
     }
     foreach (ctx.AttributeElement attrib in _attributes)
     {
         if (attrib.AttributeId == designator.AttributeId)
         {
             if (designator.Issuer != null && designator.Issuer.Length != 0)
             {
                 if (designator.Issuer == attrib.Issuer)
                 {
                     return(attrib);
                 }
             }
             else
             {
                 return(attrib);
             }
         }
     }
     return(null);
 }
 /// <summary>
 /// Matches the designator within the values of this attribute element.
 /// </summary>
 /// <param name="attributeDesignator">The attribute designator instance.</param>
 /// <returns><c>true</c> if the designator matches with this attribute.</returns>
 public bool Match(pol.AttributeDesignatorBase attributeDesignator)
 {
     if (attributeDesignator == null)
     {
         throw new ArgumentNullException("attributeDesignator");
     }
     if (AttributeId == attributeDesignator.AttributeId && DataType == attributeDesignator.DataType)
     {
         if (attributeDesignator.Issuer != null && attributeDesignator.Issuer.Length != 0)
         {
             if (Issuer == attributeDesignator.Issuer)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Example #3
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();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="attributeDesignator"></param>
        public AttributeDesignator(pol.AttributeDesignatorBase attributeDesignator)
        {
            _attributeDesignator = attributeDesignator;

            this.Text = "[" + attributeDesignator.DataType + "]:" + attributeDesignator.AttributeId;
        }
Example #5
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="attributeDesignator"></param>
		public AttributeDesignator( pol.AttributeDesignatorBase attributeDesignator )
		{
			_attributeDesignator = attributeDesignator;

			this.Text = "[" + attributeDesignator.DataType + "]:" + attributeDesignator.AttributeId;
		}
Example #6
0
        /// <summary>
        /// THe argument processing method resolves all the attribute designators, attribute
        /// selectors. If there is an internal Apply it will be evaulated within this method.
        /// </summary>
        /// <remarks>All the processed arguments are converted into an IFunctionParameter instance
        /// because this is the only value that can be used to call a function.</remarks>
        /// <param name="context">The evaluation context instance.</param>
        /// <param name="arguments">The arguments to process.</param>
        /// <returns>A list of arguments ready to be used by a function.</returns>
        private IFunctionParameterCollection ProcessArguments(EvaluationContext context, pol.IExpressionCollection arguments)
        {
            context.Trace("Processing arguments");
            context.AddIndent();

            // Create a list to return the processed values.
            IFunctionParameterCollection processedArguments = new IFunctionParameterCollection();

            // Iterate through the arguments, the IExpressionType is a mark interface
            foreach (inf.IExpression arg in arguments)
            {
                if (arg is pol.ApplyElement)
                {
                    context.Trace("Nested apply");

                    // 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)arg);

                    // Evaluate the Apply
                    EvaluationValue retVal = _childApply.Evaluate(context);

                    context.TraceContextValues();

                    // If the results were Indeterminate the Indeterminate value will be placed in
                    // the processed arguments, later another method will validate the parameters
                    // and cancel the evaluation propperly.
                    if (!retVal.IsIndeterminate)
                    {
                        if (!context.IsMissingAttribute)
                        {
                            processedArguments.Add(retVal);
                        }
                    }
                    else
                    {
                        processedArguments.Add(retVal);
                    }
                }
                else if (arg is pol.FunctionElementReadWrite)
                {
                    // Search for the function and place it in the processed arguments.
                    pol.FunctionElement functionId = new pol.FunctionElement(((pol.FunctionElementReadWrite)arg).FunctionId, ((pol.FunctionElementReadWrite)arg).SchemaVersion);

                    context.Trace("Function {0}", functionId.FunctionId);
                    inf.IFunction function = EvaluationEngine.GetFunction(functionId.FunctionId);
                    if (function == null)
                    {
                        context.Trace("ERR: function not found {0}", _applyBase.FunctionId);
                        context.ProcessingError = true;
                        processedArguments.Add(EvaluationValue.Indeterminate);
                    }
                    else
                    {
                        processedArguments.Add(function);
                    }
                }
                else if (arg is pol.VariableReferenceElement)
                {
                    pol.VariableReferenceElement variableRef = arg as pol.VariableReferenceElement;
                    VariableDefinition           variableDef = context.CurrentPolicy.VariableDefinition[variableRef.VariableId] as VariableDefinition;

                    context.TraceContextValues();

                    if (!variableDef.IsEvaluated)
                    {
                        processedArguments.Add(variableDef.Evaluate(context));
                    }
                    else
                    {
                        processedArguments.Add(variableDef.Value);
                    }
                }
                else if (arg is pol.AttributeValueElementReadWrite)
                {
                    // The AttributeValue does not need to be processed
                    context.Trace("Attribute value {0}", arg.ToString());
                    processedArguments.Add(new pol.AttributeValueElement(((pol.AttributeValueElementReadWrite)arg).DataType, ((pol.AttributeValueElementReadWrite)arg).Contents, ((pol.AttributeValueElementReadWrite)arg).SchemaVersion));
                }
                else if (arg is pol.AttributeDesignatorBase)
                {
                    // Resolve the AttributeDesignator using the EvaluationEngine public methods.
                    context.Trace("Processing attribute designator: {0}", arg.ToString());

                    pol.AttributeDesignatorBase attrDes = (pol.AttributeDesignatorBase)arg;
                    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 (arg 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);
                                break;
                            }
                        }
                        else if (arg 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 (arg 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 (arg 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);
                    }
                    else
                    {
                        processedArguments.Add(bag);
                    }
                }
                else if (arg is pol.AttributeSelectorElement)
                {
                    // Resolve the XPath query using the EvaluationEngine public methods.
                    context.Trace("Attribute selector");
                    try
                    {
                        BagValue bag = EvaluationEngine.Resolve(context, (pol.AttributeSelectorElement)arg);
                        if (bag.Elements.Count == 0 && ((pol.AttributeSelectorElement)arg).MustBePresent)
                        {
                            context.Trace("Attribute is missing");
                            context.IsMissingAttribute = true;
                            context.AddMissingAttribute((pol.AttributeReferenceBase)arg);
                        }
                        else
                        {
                            processedArguments.Add(bag);
                        }
                    }
                    catch (EvaluationException e)
                    {
                        context.Trace(Resource.TRACE_ERROR, e.Message);
                        processedArguments.Add(EvaluationValue.Indeterminate);
                        context.ProcessingError = true;
                    }
                }
            }
            context.RemoveIndent();

            return(processedArguments);
        }
Example #7
0
        /// <summary>
        /// This method overrides the ApplyBase method in order to provide extra validations
        /// required in the condition evaluation, for example the final return value should be a
        /// boolean value.
        /// </summary>
        /// <param name="context">The evaluation context instance.</param>
        /// <returns>The EvaluationValue with the results of the condition evaluation.</returns>
        public override EvaluationValue Evaluate(EvaluationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            context.Trace("Evaluating condition");
            context.AddIndent();
            try
            {
                // Iterate through the arguments, the IExpressionType is a mark interface
                foreach (inf.IExpression arg in ApplyDefinition.Arguments)
                {
                    if (arg 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)arg);

                        // Evaluate the Apply
                        EvaluationValue retVal = _childApply.Evaluate(context);

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

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

                        pol.AttributeValueElement attributeValue = new pol.AttributeValueElement(((pol.AttributeValueElementReadWrite)arg).DataType, ((pol.AttributeValueElementReadWrite)arg).Contents, ((pol.AttributeValueElementReadWrite)arg).SchemaVersion);

                        return(new EvaluationValue(
                                   attributeValue.GetTypedValue(attributeValue.GetType(context), 0),
                                   attributeValue.GetType(context)));
                    }
                    else if (arg is pol.AttributeDesignatorBase)
                    {
                        // Returning an empty bag, since the condition is not supposed to work with a bag
                        context.Trace("Processing attribute designator: {0}", arg.ToString());

                        pol.AttributeDesignatorBase attrDes = (pol.AttributeDesignatorBase)arg;
                        BagValue bag = new BagValue(EvaluationEngine.GetDataType(attrDes.DataType));
                        return(new EvaluationValue(bag, bag.GetType(context)));
                    }
                    else if (arg is pol.AttributeSelectorElement)
                    {
                        // Returning an empty bag, since the condition is not supposed to work with a bag
                        context.Trace("Attribute selector");

                        pol.AttributeSelectorElement attrSel = (pol.AttributeSelectorElement)arg;
                        BagValue bag = new BagValue(EvaluationEngine.GetDataType(attrSel.DataType));
                        return(new EvaluationValue(bag, bag.GetType(context)));
                    }
                }
                throw new NotSupportedException("internal error");
            }
            finally
            {
                context.TraceContextValues();
                context.RemoveIndent();
            }
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="targetItem"></param>
        /// <param name="match"></param>
        /// <param name="index"></param>
        public Match(pol.TargetItemBaseReadWrite targetItem, pol.TargetMatchBaseReadWrite match, int index)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            LoadingData = true;

            foreach (FieldInfo field in typeof(InternalDataTypes).GetFields())
            {
                cmbASDataType.Items.Add(field.GetValue(null));
                cmbADDataType.Items.Add(field.GetValue(null));
                cmbAVDataType.Items.Add(field.GetValue(null));
            }

            foreach (FieldInfo field in typeof(InternalFunctions).GetFields())
            {
                cmbFunctions.Items.Add(field.GetValue(null));
            }

            txtSubjectCategory.Visible = false;
            lblSubjectCategory.Visible = false;

            _match = match;
            _index = index;

            if (targetItem is pol.ActionElementReadWrite)
            {
                _targetItemName = "Action";
            }
            else if (targetItem is pol.SubjectElementReadWrite)
            {
                _targetItemName            = "Subject";
                txtSubjectCategory.Visible = true;
                lblSubjectCategory.Visible = true;
            }
            else if (targetItem is pol.ResourceElementReadWrite)
            {
                _targetItemName = "Resource";
            }

            grpMatch.Text = _targetItemName + "Match";

            cmbFunctions.SelectedIndex = cmbFunctions.FindStringExact(_match.MatchId);
            cmbFunctions.DataBindings.Add("SelectedItem", _match, "MatchId");

            cmbAVDataType.SelectedIndex = cmbAVDataType.FindStringExact(match.AttributeValue.DataType);
            cmbAVDataType.DataBindings.Add("SelectedItem", _match.AttributeValue, "DataType");

            txtAttributeValue.Text = match.AttributeValue.Contents;
            txtAttributeValue.DataBindings.Add("Text", _match.AttributeValue, "Contents");

            if (match.AttributeReference is pol.AttributeDesignatorBase)
            {
                rdbAttributeDesignator.Checked = true;
                rdbAttributeSelector.Checked   = false;

                cmbADDataType.SelectedIndex = cmbADDataType.FindStringExact(match.AttributeReference.DataType);
                cmbADDataType.DataBindings.Add("SelectedItem", _match.AttributeReference, "DataType");

                chkADMustBePresent.Checked = match.AttributeReference.MustBePresent;
                chkADMustBePresent.DataBindings.Add("Checked", _match.AttributeReference, "MustBePresent");

                pol.AttributeDesignatorBase attributeDesignator = (pol.AttributeDesignatorBase)match.AttributeReference;
                txtAttributeId.Text = attributeDesignator.AttributeId;
                txtAttributeId.DataBindings.Add("Text", _match.AttributeReference, "AttributeId");

                txtIssuer.Text = attributeDesignator.Issuer;
                txtIssuer.DataBindings.Add("Text", _match.AttributeReference, "Issuer");
            }
            else if (match.AttributeReference is pol.AttributeSelectorElement)
            {
                rdbAttributeDesignator.Checked = false;
                rdbAttributeSelector.Checked   = true;

                cmbASDataType.SelectedIndex = cmbASDataType.FindStringExact(match.AttributeReference.DataType);
                cmbASDataType.DataBindings.Add("SelectedItem", _match.AttributeReference, "DataType");

                chkASMustBePresent.Checked = match.AttributeReference.MustBePresent;
                chkASMustBePresent.DataBindings.Add("Checked", _match.AttributeReference, "MustBePresent");

                txtRequestContextPath.Text = ((pol.AttributeSelectorElement)match.AttributeReference).RequestContextPath;
                txtRequestContextPath.DataBindings.Add("Text", _match.AttributeReference, "RequestContextPath");
            }

            LoadingData = false;
        }