/// <summary> /// Initializes a new instance of the <see cref="XacmlAttributeAssignmentExpression"/> class. /// </summary> /// <param name="attributeId">The attribute identifier.</param> /// <param name="expressionElement">The expression element.</param> public XacmlAttributeAssignmentExpression(Uri attributeId, IXacmlApply expressionElement) { Contract.Requires<ArgumentNullException>(attributeId != null); Contract.Requires<ArgumentNullException>(expressionElement != null); this.attributeId = attributeId; this.Property = expressionElement; }
/// <summary> /// Initializes a new instance of the <see cref="XacmlAttributeAssignmentExpression"/> class. /// </summary> /// <param name="attributeId">The attribute identifier.</param> /// <param name="expressionElement">The expression element.</param> public XacmlAttributeAssignmentExpression(Uri attributeId, IXacmlApply expressionElement) { if (attributeId == null) { throw new ArgumentNullException(nameof(attributeId)); } if (expressionElement == null) { throw new ArgumentNullException(nameof(expressionElement)); } this.attributeId = attributeId; this.Property = expressionElement; }
protected virtual object ExpressionEvaluate(IXacmlApply expression) { Contract.Requires<ArgumentNullException>(expression != null); object result = null; Type applyElemType = expression.GetType(); if (applyElemType == typeof(XacmlVariableReference)) { XacmlVariableReference reference = expression as XacmlVariableReference; XacmlVariableDefinition definition = this.currentEvaluatingPolicy.VariableDefinitions.Where(o => o.VariableId == reference.VariableReference).SingleOrDefault(); if (definition == null) { throw Diagnostic.DiagnosticTools.ExceptionUtil.ThrowHelperError(new XacmlInvalidSyntaxException("Missing Variable definition " + reference.VariableReference)); } // Cache value if (definition.CalculatedValue != null) { result = definition.CalculatedValue; } else { result = this.ExpressionEvaluate(definition.Property); definition.CalculatedValue = result; } } else if (applyElemType == typeof(XacmlAttributeSelector)) { result = this.GetAttributeSelector(expression as XacmlAttributeSelector); } else if (applyElemType == typeof(XacmlResourceAttributeDesignator)) { XacmlResourceAttributeDesignator design = expression as XacmlResourceAttributeDesignator; IEnumerable<string> designatorsNames = this.GetResourceAttributeDesignator(design); if (designatorsNames == null) { throw new XacmlIndeterminateException("XacmlResourceAttributeDesignator indeterminate"); } TypeConverterWrapper typeConverter = this.types[design.DataType.ToString()]; result = typeConverter.ConvertEnumerable(designatorsNames.Select(o => typeConverter.ConvertFromString(o, design))); } else if (applyElemType == typeof(XacmlActionAttributeDesignator)) { XacmlActionAttributeDesignator design = expression as XacmlActionAttributeDesignator; IEnumerable<string> designatorsNames = this.GetActionAttributeDesignator(design); if (designatorsNames == null) { throw Diagnostic.DiagnosticTools.ExceptionUtil.ThrowHelperError(new XacmlIndeterminateException("XacmlActionAttributeDesignator indeterminate")); } TypeConverterWrapper typeConverter = this.types[design.DataType.ToString()]; result = typeConverter.ConvertEnumerable(designatorsNames.Select(o => typeConverter.ConvertFromString(o, design))); } else if (applyElemType == typeof(XacmlEnvironmentAttributeDesignator)) { XacmlEnvironmentAttributeDesignator design = expression as XacmlEnvironmentAttributeDesignator; IEnumerable<string> designatorsNames = this.GetEnvironmentAttributeDesignator(design); if (designatorsNames == null) { throw new XacmlIndeterminateException("XacmlEnvironmentAttributeDesignator indeterminate"); } TypeConverterWrapper typeConverter = this.types[design.DataType.ToString()]; result = typeConverter.ConvertEnumerable(designatorsNames.Select(o => typeConverter.ConvertFromString(o, design))); } else if (applyElemType == typeof(XacmlSubjectAttributeDesignator)) { XacmlSubjectAttributeDesignator design = expression as XacmlSubjectAttributeDesignator; IEnumerable<string> designatorsNames = this.GetSubjectAttributeDesignator(design); if (designatorsNames == null) { throw new XacmlIndeterminateException("XacmlSubjectAttributeDesignator indeterminate"); } TypeConverterWrapper typeConverter = this.types[design.DataType.ToString()]; result = typeConverter.ConvertEnumerable(designatorsNames.Select(o => typeConverter.ConvertFromString(o, design))); } else if (applyElemType == typeof(XacmlAttributeValue)) { XacmlAttributeValue attributeValue = expression as XacmlAttributeValue; result = this.types[attributeValue.DataType.ToString()].ConvertFromString(attributeValue.Value, attributeValue); } else if (applyElemType == typeof(XacmlFunction)) { XacmlFunction functionDelegate = expression as XacmlFunction; result = this.functions[functionDelegate.FunctionId.ToString()]; } else if (applyElemType == typeof(XacmlApply)) { result = this.ApplyEvaluate(expression as XacmlApply); } return result; }