/// <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); }
/// <summary> /// Returns a policy set document using the PolicySetRefereneId specified. /// </summary> /// <param name="policySetReference">The policy set reference with the Id of the policy set searched.</param> /// <returns>The policy set document.</returns> public pol.PolicySetElement GetPolicySet(pol.PolicySetIdReferenceElement policySetReference) { if (policySetReference == null) { throw new ArgumentNullException("policySetReference"); } pol.PolicyDocument doc = _policySets[policySetReference.PolicySetId] as pol.PolicyDocument; if (doc != null) { return((pol.PolicySetElement)doc.PolicySet); //TODO: check if we have to return a read write or a read only policy here. } return(null); }
/// <summary> /// Method called by the EvaluationEngine when the evaluation is executed without a policy document, this /// method search in the policy repository and return the first policy that matches its target with the /// context document specified. /// </summary> /// <param name="context">The evaluation context instance.</param> /// <returns>The policy document ready to be used by the evaluation engine.</returns> public pol.PolicyDocument Match(rtm.EvaluationContext context) { if (context == null) { throw new ArgumentNullException("context"); } pol.PolicyDocument polEv = null; //Search if there is a policySet which target matches the context document foreach (pol.PolicyDocument policy in _policySets.Values) { rtm.PolicySet tempPolicy = new rtm.PolicySet(context.Engine, (pol.PolicySetElement)policy.PolicySet); rtm.EvaluationContext tempContext = new rtm.EvaluationContext(context.Engine, policy, context.ContextDocument); // Match the policy set target with the context document if (tempPolicy.Match(tempContext) == rtm.TargetEvaluationValue.Match) { if (polEv == null) { polEv = policy; } else { throw new EvaluationException(Resource.ResourceManager[Resource.MessageKey.exc_duplicated_policy_in_repository]); } } } //Search if there is a policy which target matches the context document foreach (pol.PolicyDocument policy in _policies.Values) { rtm.Policy tempPolicy = new rtm.Policy((pol.PolicyElement)policy.Policy); rtm.EvaluationContext tempContext = new rtm.EvaluationContext(context.Engine, policy, context.ContextDocument); // Match the policy target with the context document if (tempPolicy.Match(tempContext) == rtm.TargetEvaluationValue.Match) { if (polEv == null) { polEv = policy; } else { throw new EvaluationException(Resource.ResourceManager[Resource.MessageKey.exc_duplicated_policy_in_repository]); } } } return(polEv); }
/// <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 ); }