/// <summary> /// Creates a new runtime policy evaluation. /// </summary> /// <param name="policy">The policy document.</param> public Policy( pol.PolicyElement policy ) { if (policy == null) throw new ArgumentNullException("policy"); _policy = policy; // Chechs the target for this policy. if( policy.Target != null ) { _target = new Target( (pol.TargetElement)policy.Target ); // Load all the resources for this policy. foreach( pol.ResourceElement resource in policy.Target.Resources.ItemsList ) { foreach( pol.ResourceMatchElement rmatch in resource.Match ) { if( !_allResources.Contains( rmatch.AttributeValue.Contents ) ) { _allResources.Add( rmatch.AttributeValue.Contents ); } } } } // Load all the Rules and creates a new runtime rule. foreach( pol.RuleElement rule in policy.Rules ) { Rule ruleEv = new Rule( rule ); _rules.Add( ruleEv ); foreach( string rName in ruleEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } } }
/// <summary> /// Creates a new instance of the Rule using the rule defined in the policy document. /// </summary> /// <param name="rule">The rule defined in the policy document.</param> public Rule( pol.RuleElement rule ) { if (rule == null) throw new ArgumentNullException("rule"); _rule = rule; if( _rule.SchemaVersion == XacmlVersion.Version10 || _rule.SchemaVersion == XacmlVersion.Version11 ) { _condition = new Condition( (pol.ConditionElement)_rule.Condition ); } else if( _rule.SchemaVersion == XacmlVersion.Version20 ) { _condition = new Condition2( (pol.ConditionElement)_rule.Condition ); } if( rule.Target != null ) { _target = new Target( (pol.TargetElement)rule.Target ); // Load all the resources for the elements within this rule. foreach( pol.ResourceElement resource in rule.Target.Resources.ItemsList ) { foreach( pol.ResourceMatchElement rmatch in resource.Match ) { if( !_allResources.Contains( rmatch.AttributeValue.Contents ) ) { _allResources.Add( rmatch.AttributeValue.Contents ); } } } } }
/// <summary> /// Creates a new runtime policy set evaluation. /// </summary> /// <param name="engine">The evaluation engine.</param> /// <param name="policySet">The policy set defined in the policy document.</param> public PolicySet( EvaluationEngine engine, pol.PolicySetElement policySet ) { if (engine == null) throw new ArgumentNullException("engine"); if (policySet == null) throw new ArgumentNullException("policySet"); _policySet = policySet; // Create a runtime target of this policy set. if( policySet.Target != null ) { _target = new Target( (pol.TargetElement)policySet.Target ); foreach( pol.ResourceElement resource in policySet.Target.Resources.ItemsList ) { foreach( pol.ResourceMatchElement rmatch in resource.Match ) { if( !_allResources.Contains( rmatch.AttributeValue.Contents ) ) { _allResources.Add( rmatch.AttributeValue.Contents ); } } } } // Add all the policies (or policy set) inside this policy set. foreach( object child in policySet.Policies ) { pol.PolicySetElement childPolicySet = child as pol.PolicySetElement; pol.PolicyElement childPolicyElement = child as pol.PolicyElement; pol.PolicySetIdReferenceElement childPolicySetIdReference = child as pol.PolicySetIdReferenceElement; pol.PolicyIdReferenceElement childPolicyIdReferenceElement = child as pol.PolicyIdReferenceElement; if (childPolicySet != null) { PolicySet policySetEv = new PolicySet(engine, childPolicySet); foreach( string rName in policySetEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } _policies.Add( policySetEv ); } else if (childPolicyElement!=null) { Policy policyEv = new Policy(childPolicyElement); foreach( string rName in policyEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } _policies.Add( policyEv ); } else if (childPolicySetIdReference!=null) { pol.PolicySetElement policySetDefinition = EvaluationEngine.Resolve(childPolicySetIdReference); if( policySetDefinition != null ) { PolicySet policySetEv = new PolicySet( engine, policySetDefinition ); foreach( string rName in policySetEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } _policies.Add( policySetEv ); } else { throw new EvaluationException( Resource.ResourceManager[ Resource.MessageKey.exc_policyset_reference_not_resolved, ((pol.PolicySetIdReferenceElement)child).PolicySetId ] ); } } else if (childPolicyIdReferenceElement!=null) { pol.PolicyElement policyDefinition = EvaluationEngine.Resolve(childPolicyIdReferenceElement); if( policyDefinition != null ) { Policy policyEv = new Policy( policyDefinition ); foreach( string rName in policyEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } _policies.Add( policyEv ); } else { throw new EvaluationException( Resource.ResourceManager[ Resource.MessageKey.exc_policy_reference_not_resolved, ((pol.PolicyIdReferenceElement)child).PolicyId ] ); } } } }