示例#1
0
        /// <summary>
        /// Creates a new CombinerParameterElement using the XmlReader instance provided.
        /// </summary>
        /// <param name="reader">The XmlReader instance positioned at the CombinerParameterElement node.</param>
        /// <param name="nodeName">The name of the node for this combiner parameter item.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        protected CombinerParameterElement(XmlReader reader, string nodeName, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.LocalName == nodeName &&
                ValidateSchema(reader, schemaVersion))
            {
                // Read the attributes
                if (reader.HasAttributes)
                {
                    // Load all the attributes
                    while (reader.MoveToNextAttribute())
                    {
                        if (reader.LocalName == Consts.Schema2.CombinerParameterElement.ParameterName)
                        {
                            _parameterName = reader.GetAttribute(Consts.Schema2.CombinerParameterElement.ParameterName);
                        }
                        else
                        {
                            AttributeFound(reader);
                        }
                    }
                    reader.MoveToElement();
                }

                // Read the rule contents.
                while (reader.Read())
                {
                    switch (reader.LocalName)
                    {
                    case Consts.Schema2.CombinerParameterElement.AttributeValue:
                        _attributeValue = new AttributeValueElement(reader, schemaVersion);
                        break;
                    }
                    if (reader.LocalName == Consts.Schema2.CombinerParameterElement.CombinerParameter &&
                        reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }
            else
            {
                throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
            }
        }
示例#2
0
 /// <summary>
 /// Creates a new RuleCombinerParameter using the provided argument values.
 /// </summary>
 /// <param name="parameterName">The parameter name.</param>
 /// <param name="attributeValue">The attribute value.</param>
 /// <param name="ruleIdRef">The rule Id reference.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public RuleCombinerParameterElement(string parameterName, AttributeValueElement attributeValue, Uri ruleIdRef, XacmlVersion version)
     : base(parameterName, attributeValue, version)
 {
     _ruleIdRef = ruleIdRef;
 }
示例#3
0
 /// <summary>
 /// Creates a new PolicyCombinerParameter using the provided argument values.
 /// </summary>
 /// <param name="parameterName">The parameter name.</param>
 /// <param name="attributeValue">The attribute value.</param>
 /// <param name="policySetIdRef">The policy set Id reference.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public PolicySetCombinerParameterElement(string parameterName, AttributeValueElement attributeValue, Uri policySetIdRef, XacmlVersion version)
     : base(parameterName, attributeValue, version)
 {
     _policySetIdRef = policySetIdRef;
 }
 /// <summary>
 /// Creates a new PolicyCombinerParameter using the provided argument values.
 /// </summary>
 /// <param name="parameterName">The parameter name.</param>
 /// <param name="attributeValue">The attribute value.</param>
 /// <param name="policyIdRef">The policy Id reference.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public PolicyCombinerParameterElement(string parameterName, AttributeValueElement attributeValue, Uri policyIdRef, XacmlVersion version)
     : base(parameterName, attributeValue, version)
 {
     _policyIdRef = policyIdRef;
 }
 /// <summary>
 /// Creates a new RuleCombinerParameter using the provided argument values.
 /// </summary>
 /// <param name="parameterName">The parameter name.</param>
 /// <param name="attributeValue">The attribute value.</param>
 /// <param name="ruleIdRef">The rule Id reference.</param>
 /// <param name="version">The version of the schema that was used to validate.</param>
 public RuleCombinerParameterElement(string parameterName, AttributeValueElement attributeValue, Uri ruleIdRef, XacmlVersion version)
     : base(parameterName, attributeValue, version)
 {
     _ruleIdRef = ruleIdRef;
 }
示例#6
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 (IExpression arg in ApplyDefinition.Arguments)
                {
                    if (arg is 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.
                        var childApply = new Apply((ApplyElement)arg);

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

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

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

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

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

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

                        var attrSel = (AttributeSelectorElement)arg;
                        var bag = new BagValue(EvaluationEngine.GetDataType(attrSel.DataType));
                        return new EvaluationValue(bag, bag.GetType(context));
                    }
                }
                throw new NotSupportedException("internal error");
            }
            finally
            {
                context.TraceContextValues();
                context.RemoveIndent();
            }
        }
示例#7
0
 /// <summary>
 /// Creates a new CombinerParameter using the provided argument values.
 /// </summary>
 /// <param name="parameterName">The parameter name.</param>
 /// <param name="attributeValue">The attribute value.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public CombinerParameterElement(string parameterName, AttributeValueElement attributeValue, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _parameterName  = parameterName;
     _attributeValue = attributeValue;
 }
        /// <summary>
        /// Creates a new CombinerParameterElement using the XmlReader instance provided.
        /// </summary>
        /// <param name="reader">The XmlReader instance positioned at the CombinerParameterElement node.</param>
        /// <param name="nodeName">The name of the node for this combiner parameter item.</param>
        /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
        protected CombinerParameterElement(XmlReader reader, string nodeName, XacmlVersion schemaVersion)
            : base(XacmlSchema.Policy, schemaVersion)
        {
            if (reader == null) throw new ArgumentNullException("reader");
            if (reader.LocalName == nodeName &&
                ValidateSchema(reader, schemaVersion))
            {
                // Read the attributes
                if (reader.HasAttributes)
                {
                    // Load all the attributes
                    while (reader.MoveToNextAttribute())
                    {
                        if (reader.LocalName == Consts.Schema2.CombinerParameterElement.ParameterName)
                        {
                            _parameterName = reader.GetAttribute(Consts.Schema2.CombinerParameterElement.ParameterName);
                        }
                        else
                        {
                            AttributeFound(reader);
                        }
                    }
                    reader.MoveToElement();
                }

                // Read the rule contents.
                while (reader.Read())
                {
                    switch (reader.LocalName)
                    {
                        case Consts.Schema2.CombinerParameterElement.AttributeValue:
                            _attributeValue = new AttributeValueElement(reader, schemaVersion);
                            break;
                    }
                    if (reader.LocalName == Consts.Schema2.CombinerParameterElement.CombinerParameter &&
                        reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }
            else
            {
                throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
            }
        }
 /// <summary>
 /// Creates a new CombinerParameter using the provided argument values.
 /// </summary>
 /// <param name="parameterName">The parameter name.</param>
 /// <param name="attributeValue">The attribute value.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public CombinerParameterElement(string parameterName, AttributeValueElement attributeValue, XacmlVersion schemaVersion)
     : base(XacmlSchema.Policy, schemaVersion)
 {
     _parameterName = parameterName;
     _attributeValue = attributeValue;
 }