/// <summary> /// Gets the index of the given IExpression in the collection /// </summary> /// <param name="expression"></param> /// <returns></returns> public int GetIndex( inf.IExpression expression ) { for( int i=0; i<this.Count; i++ ) { if( this.List[i] == expression ) { return i; } } return -1; }
/// <summary> /// Creates a new evaluation value specifying the data type. /// </summary> /// <param name="value">The value to hold in the evaluation value.</param> /// <param name="dataType">The data type for the value.</param> public EvaluationValue( object value, inf.IDataType dataType ) { if (dataType == null) throw new ArgumentNullException("dataType"); if( value is EvaluationValue ) { _value = ((EvaluationValue)value)._value; _dataType = ((EvaluationValue)value)._dataType; } else if( value is BagValue ) { _value = value; _dataType = dataType; } else if(value is inf.IFunctionParameter ) { _value = ((inf.IFunctionParameter)value).GetTypedValue( dataType, 0 ); _dataType = dataType; } else { _value = value; _dataType = dataType; } }
/// <summary> /// Evaluates a function and also validates it's return value and parameter data types /// </summary> /// <param name="context">The evaluation context instance.</param> /// <param name="functionInstance">The function to call</param> /// <param name="arguments">The function arguments</param> /// <returns>The return value of the function</returns> public static EvaluationValue EvaluateFunction( EvaluationContext context, inf.IFunction functionInstance, params inf.IFunctionParameter[] arguments ) { if (context == null) throw new ArgumentNullException("context"); // If the caller is in a missing attribute state the function should not be called if( context.IsMissingAttribute ) { context.Trace( "There's a missing attribute in the parameters" ); //TODO: resources return EvaluationValue.Indeterminate; } else { // Validate function defined arguments int functionArgumentIdx; for( functionArgumentIdx = 0; functionArgumentIdx < functionInstance.Arguments.Length; functionArgumentIdx++ ) { // Validate the value is not an Indeterminate value if( arguments[ functionArgumentIdx ] is EvaluationValue && ((EvaluationValue)arguments[ functionArgumentIdx ]).IsIndeterminate ) { if( !context.IsMissingAttribute ) { context.ProcessingError = true; } context.Trace( "There's a parameter with Indeterminate value" ); return EvaluationValue.Indeterminate; } // Compare the function and the value data type if( ( ( functionInstance.Arguments[ functionArgumentIdx ] != arguments[ functionArgumentIdx ].GetType( context ) ) && ( ( functionInstance.Arguments[ functionArgumentIdx ] != DataTypeDescriptor.Bag ) && (arguments[ functionArgumentIdx ] is BagValue) ) ) ) { context.ProcessingError = true; context.Trace( "There's a parameter with an invalid datatype" ); //TODO: resources return EvaluationValue.Indeterminate; } } //If the function supports variable arguments, the last datatype is used to validate the //rest of the parameters if( functionInstance.VarArgs ) { functionArgumentIdx--; for( int argumentValueIdx = functionArgumentIdx; argumentValueIdx < arguments.Length; argumentValueIdx++ ) { // Validate the value is not an Indeterminate value if( arguments[ argumentValueIdx ] is EvaluationValue && ((EvaluationValue)arguments[ argumentValueIdx ]).IsIndeterminate ) { if( !context.IsMissingAttribute ) { context.ProcessingError = true; } context.Trace( "There's a parameter with Indeterminate value" ); //TODO: resources return EvaluationValue.Indeterminate; } // Compare the function and the value data type if( ( functionInstance.Arguments[ functionArgumentIdx ] != arguments[ argumentValueIdx ].GetType( context ) ) && ( (arguments[ argumentValueIdx ] is BagValue) && ( functionInstance.Arguments[ functionArgumentIdx ] != DataTypeDescriptor.Bag ) ) ) { context.ProcessingError = true; context.Trace( "There's a parameter with an invalid datatype" ); //TODO: resources return EvaluationValue.Indeterminate; } } } StringBuilder sb = new StringBuilder(); // Call the function in a controlled evironment to capture any exception try { sb.Append( functionInstance.Id ); sb.Append( "( " ); bool isFirst = true; foreach( inf.IFunctionParameter param in arguments ) { if( isFirst ) { isFirst = false; } else { sb.Append( ", " ); } sb.Append( param.ToString() ); } sb.Append( " )" ); sb.Append( " = " ); EvaluationValue returnValue = functionInstance.Evaluate( context, arguments ); sb.Append( returnValue.ToString() ); context.Trace( sb.ToString() ); return returnValue; } catch( EvaluationException e ) { context.Trace( sb.ToString() ); context.ProcessingError = true; context.Trace( "Error: {0}", e.Message ); //TODO: resources return EvaluationValue.Indeterminate; } } }
/// <summary> /// Creates a new RuleCombinerParameter using the provided argument values. /// </summary> /// <param name="id">The variable id.</param> /// <param name="expression">The expression for the variable definition.</param> /// <param name="schemaVersion">The version of the schema that was used to validate.</param> public VariableDefinitionElement( string id, inf.IExpression expression, XacmlVersion schemaVersion ) : base( XacmlSchema.Policy, schemaVersion ) { _id = id; _expression = expression; }
/// <summary> /// Creates a new empty bag for the given data type. /// </summary> /// <param name="dataType">The data type of the bag.</param> public BagValue( inf.IDataType dataType ) { _dataType = dataType; }
/// <summary> /// Gets the value as a generic object. /// </summary> /// <param name="dataType">The expected data type of the value.</param> /// <param name="parNo">THe number of parameter used only for error notification.</param> /// <returns></returns> public object GetTypedValue( inf.IDataType dataType, int parNo ) { if( dataType != DataTypeDescriptor.Bag ) { throw new EvaluationException( "invalid datatype." ); } return this; }
/// <summary> /// Returns the value of the argument in the index specified of the type int. /// </summary> /// <param name="args">The arguments list</param> /// <param name="index">The index</param> /// <returns>The integer value.</returns> protected static int GetIntegerArgument( inf.IFunctionParameter[] args, int index ) { if (args == null) throw new ArgumentNullException("args"); return (int)args[ index ].GetTypedValue( DataTypeDescriptor.Integer, index ); }
/// <summary> /// Adds an object to the end of the CollectionBase. /// </summary> /// <param name="value">The Object to be added to the end of the CollectionBase. </param> /// <returns>The CollectionBase index at which the value has been added.</returns> public virtual int Add( inf.IExpression value ) { return( List.Add( value ) ); }
/// <summary> /// Returns the value of the argument in the index specified of the type DnsName. /// </summary> /// <param name="args">The arguments list</param> /// <param name="index">The index</param> /// <returns>The DnsName value.</returns> protected static typ.DnsNameDataType GetDnsNameArgument( inf.IFunctionParameter[] args, int index ) { if (args == null) throw new ArgumentNullException("args"); return (typ.DnsNameDataType)args[ index ].GetTypedValue( DataTypeDescriptor.DnsName, index ); }
/// <summary> /// Returns the value of the argument in the index specified of the type YearMonthDuration. /// </summary> /// <param name="args">The arguments list</param> /// <param name="index">The index</param> /// <returns>The YearMonthDuration value.</returns> protected static typ.YearMonthDuration GetYearMonthDurationArgument( inf.IFunctionParameter[] args, int index ) { if (args == null) throw new ArgumentNullException("args"); if (args == null) throw new ArgumentNullException("args"); return (typ.YearMonthDuration)args[ index ].GetTypedValue( DataTypeDescriptor.YearMonthDuration, index ); }
/// <summary> /// Returns the value of the argument in the index specified of the type HexBinary. /// </summary> /// <param name="args">The arguments list</param> /// <param name="index">The index</param> /// <returns>The HexBinary value.</returns> protected static typ.HexBinary GetHexBinaryArgument( inf.IFunctionParameter[] args, int index ) { if (args == null) throw new ArgumentNullException("args"); return (typ.HexBinary)args[ index ].GetTypedValue( DataTypeDescriptor.HexBinary, index ); }
/// <summary> /// Returns the value of the argument in the index specified of the type String. /// </summary> /// <param name="args">The arguments list</param> /// <param name="index">The index</param> /// <returns>The String value.</returns> protected static string GetStringArgument( inf.IFunctionParameter[] args, int index ) { if (args == null) throw new ArgumentNullException("args"); return (string)args[ index ].GetTypedValue( DataTypeDescriptor.String, index ); }
/// <summary> /// Returns the value of the argument in the index specified of the type AnyUri. /// </summary> /// <param name="args">The arguments list</param> /// <param name="index">The index</param> /// <returns>The Uri value.</returns> protected static Uri GetAnyUriArgument( inf.IFunctionParameter[] args, int index ) { if (args == null) throw new ArgumentNullException("args"); return (Uri)args[ index ].GetTypedValue( DataTypeDescriptor.AnyUri, index ); }
/// <summary> /// Returns the value of the argument in the index specified of the type bool. /// </summary> /// <param name="args">The arguments list</param> /// <param name="index">The index</param> /// <returns>The bool value.</returns> protected static bool GetBooleanArgument( inf.IFunctionParameter[] args, int index ) { if (args == null) throw new ArgumentNullException("args"); return (bool)args[ index ].GetTypedValue( DataTypeDescriptor.Boolean, index ); }
/// <summary> /// Gets the value as a generic object. /// </summary> /// <param name="dataType">The expected data type of the value.</param> /// <param name="parNo">THe number of parameter used only for error notification.</param> /// <returns></returns> public object GetTypedValue( inf.IDataType dataType, int parNo ) { if( dataType != _dataType ) { throw new EvaluationException( Resource.ResourceManager[ Resource.MessageKey.exc_type_mismatch, dataType, _dataType ] ); } return _value; }
/// <summary> /// Returns the typed value for this string value. /// </summary> /// <param name="dataType">The expected data type of the value.</param> /// <param name="parNo">The parameter number used only for error reporing.</param> /// <returns>The typed value as an object.</returns> public object GetTypedValue( inf.IDataType dataType, int parNo ) { if (dataType == null) throw new ArgumentNullException("dataType"); if( IsBag ) { return this; } else { if( DataTypeValue != dataType.DataTypeName ) { throw new EvaluationException( "invalid data type" ); //TODO: make the error more clear. } if( DataTypeValue != null ) { if( DataTypeValue != dataType.DataTypeName ) { throw new EvaluationException( Resource.ResourceManager[ Resource.MessageKey.exc_invalid_datatype_in_stringvalue, parNo, DataTypeValue ] ); } } return dataType.Parse( Value, parNo ); //TODO: this exception is possible? //throw new EvaluationException( cor.Resource.ResourceManager[ cor.Resource.MessageKey.exc_invalid_datatype_in_stringvalue, parNo, DataTypeValue ] ); } }
/// <summary> /// Returns the value of the argument in the index specified of the type IPAddress. /// </summary> /// <param name="args">The arguments list</param> /// <param name="index">The index</param> /// <returns>The IPAddress value.</returns> protected static typ.IPAddress GetIPAddressArgument( inf.IFunctionParameter[] args, int index ) { if (args == null) throw new ArgumentNullException("args"); return (typ.IPAddress)args[ index ].GetTypedValue( DataTypeDescriptor.IPAddress, index ); }
/// <summary> /// Gets the value as a generic object. /// </summary> /// <param name="dataType">The expected data type of the value.</param> /// <param name="parNo">The number of parameter used only for error notification.</param> /// <returns></returns> public virtual object GetTypedValue( inf.IDataType dataType, int parNo) { return this; }
/// <summary> /// Adds an object to the end of the CollectionBase. /// </summary> /// <param name="value">The Object to be added to the end of the CollectionBase. </param> /// <returns>The CollectionBase index at which the value has been added.</returns> public int Add( inf.IFunctionParameter value ) { return( List.Add( value ) ); }