Exemple #1
0
 /// <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);
 }
Exemple #2
0
        /// <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]);
                    }
                }
            }
        }