/// <summary> /// /// </summary> /// <param name="request"></param> public Request( con.RequestElementReadWrite request ) { _request = request; this.Text = "Request"; this.SelectedImageIndex = 1; this.ImageIndex = 1; if( _request.Action != null ) { this.Nodes.Add( new Action( _request.Action ) ); } if( _request.Environment != null ) { this.Nodes.Add( new Environment( _request.Environment ) ) ; } if( _request.Resources != null ) { foreach( con.ResourceElementReadWrite resource in _request.Resources ) { this.Nodes.Add( new Resource( resource ) ); } } if( _request.Subjects != null ) { foreach( con.SubjectElementReadWrite subject in _request.Subjects ) { this.Nodes.Add( new Subject( subject ) ); } } this.ExpandAll(); }
/// <summary> /// /// </summary> /// <param name="attribute"></param> public Attribute( con.AttributeElementReadWrite attribute ) { _attribute = attribute; this.Text = "Attribute"; this.SelectedImageIndex = 3; this.ImageIndex = 3; }
/// <summary> /// /// </summary> /// <param name="action"></param> public Action( con.ActionElementReadWrite action ) { _action = action; this.Text = "Action"; this.SelectedImageIndex = 2; this.ImageIndex = 2; foreach( con.AttributeElementReadWrite attr in _action.Attributes ) { this.Nodes.Add( new Attribute( attr ) ); } }
/// <summary> /// /// </summary> /// <param name="subject"></param> public Subject( con.SubjectElementReadWrite subject ) { _subject = subject; this.Text = "Subject"; this.SelectedImageIndex = 2; this.ImageIndex = 2; foreach( con.AttributeElementReadWrite attr in _subject.Attributes ) { this.Nodes.Add( new Attribute( attr ) ); } }
/// <summary> /// /// </summary> /// <param name="environment"></param> public Environment( con.EnvironmentElementReadWrite environment ) { _environment = environment; this.Text = "Environment"; this.SelectedImageIndex = 2; this.ImageIndex = 2; foreach( con.AttributeElementReadWrite attr in _environment.Attributes ) { this.Nodes.Add( new Attribute( attr ) ); } }
/// <summary> /// /// </summary> /// <param name="resource"></param> public Resource( con.ResourceElementReadWrite resource ) { _resource = resource; this.Text = "Resource"; this.SelectedImageIndex = 2; this.ImageIndex = 2; foreach( con.AttributeElementReadWrite attr in _resource.Attributes ) { this.Nodes.Add( new Attribute( attr ) ); } }
/// <summary> /// /// </summary> /// <param name="context"></param> public Context( con.ContextDocumentReadWrite context ) { _context = context; this.Text = "Context Document"; this.SelectedImageIndex = 0; this.ImageIndex = 0; if( _context.Request != null ) { this.Nodes.Add( new Request( _context.Request ) ); } this.ExpandAll(); }
/// <summary> /// Evaluates the target items and return wether the target applies to the context or not. /// </summary> /// <param name="context">The evaluation context instance.</param> /// <param name="targetItem">The target item in the context document.</param> /// <returns></returns> public TargetEvaluationValue Evaluate( EvaluationContext context, ctx.TargetItemBase targetItem ) { if (context == null) throw new ArgumentNullException(nameof(context)); if (_targetItems.IsAny) { context.Trace("IsAny"); return TargetEvaluationValue.Match; } _evaluationValue = TargetEvaluationValue.NoMatch; //Match TargetItem foreach( pol.TargetItemBase polItem in _targetItems.ItemsList ) { foreach( pol.TargetMatchBase match in polItem.Match ) { _evaluationValue = TargetEvaluationValue.NoMatch; context.Trace( "Using function: {0}", match.MatchId ); inf.IFunction matchFunction = EvaluationEngine.GetFunction( match.MatchId ); if( matchFunction == null ) { context.Trace( "ERR: function not found {0}", match.MatchId ); context.ProcessingError = true; return TargetEvaluationValue.Indeterminate; } if( matchFunction.Returns == null ) { // Validates the function return value context.Trace( "ERR: The function '{0}' does not defines it's return value", match.MatchId ); context.ProcessingError = true; return TargetEvaluationValue.Indeterminate; } if( matchFunction.Returns != DataTypeDescriptor.Boolean ) { context.Trace( "ERR: Function does not return Boolean a value" ); context.ProcessingError = true; return TargetEvaluationValue.Indeterminate; } ctx.AttributeElement attribute = EvaluationEngine.Resolve( context, match, targetItem ); if( attribute != null ) { context.Trace( "Attribute found, evaluating match function" ); try { EvaluationValue returnValue = EvaluationEngine.EvaluateFunction( context, matchFunction, match.AttributeValue, attribute ); _evaluationValue = returnValue.BoolValue ? TargetEvaluationValue.Match : TargetEvaluationValue.NoMatch; } catch( EvaluationException e ) { context.Trace( Resource.TRACE_ERROR, e.Message ); _evaluationValue = TargetEvaluationValue.Indeterminate; } } // Validate MustBePresent if( match.AttributeReference.MustBePresent ) { if( context.IsMissingAttribute ) { context.Trace( "Attribute not found and must be present" ); _evaluationValue = TargetEvaluationValue.Indeterminate; } } // Do not iterate if the value was found if( _evaluationValue != TargetEvaluationValue.Match ) { break; } } // Do not iterate if the value was found if( _evaluationValue == TargetEvaluationValue.Match ) { return _evaluationValue; } } return _evaluationValue; }
/// <summary> /// Creates a new instance of the evaluaion context. /// </summary> /// <param name="engine">The engine instance.</param> /// <param name="policyDocument">The policy document instance.</param> /// <param name="contextDocument">The context document instance.</param> public EvaluationContext( EvaluationEngine engine, pol.PolicyDocument policyDocument, ctx.ContextDocument contextDocument ) : this() { ctx.AttributeReadWriteCollection attributes = new ctx.AttributeReadWriteCollection(); foreach( ctx.AttributeElementReadWrite attribute in contextDocument.Request.Resources[0].Attributes ) { attributes.Add( new ctx.AttributeElementReadWrite( attribute ) ); } ctx.ResourceContentElement resourceContent = null; if( contextDocument.Request.Resources[0].ResourceContent != null ) { resourceContent = new ctx.ResourceContentElement( contextDocument.Request.Resources[0].ResourceContent.XmlDocument, contextDocument.Request.Resources[0].ResourceContent.SchemaVersion ); } _engine = engine; _policyDocument = policyDocument; _contextDocument = contextDocument; _currentResource = new ctx.ResourceElementReadWrite( resourceContent, contextDocument.Request.Resources[0].ResourceScopeValue, attributes, contextDocument.Request.Resources[0].SchemaVersion ); }