Exemple #1
0
        /// <summary>Resolves policy based on evidence for the policy level, and returns the resulting <see cref="T:System.Security.Policy.PolicyStatement" />.</summary>
        /// <returns>The resulting <see cref="T:System.Security.Policy.PolicyStatement" />.</returns>
        /// <param name="evidence">The <see cref="T:System.Security.Policy.Evidence" /> used to resolve the <see cref="T:System.Security.Policy.PolicyLevel" />. </param>
        /// <exception cref="T:System.Security.Policy.PolicyException">The policy level contains multiple matching code groups marked as exclusive. </exception>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="evidence" /> parameter is null. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
        /// </PermissionSet>
        public PolicyStatement Resolve(Evidence evidence)
        {
            if (evidence == null)
            {
                throw new ArgumentNullException("evidence");
            }
            PolicyStatement policyStatement = this.root_code_group.Resolve(evidence);

            return((policyStatement == null) ? PolicyStatement.Empty() : policyStatement);
        }
        public PolicyStatement Resolve(Evidence evidence)
        {
            if (evidence == null)
            {
                throw new ArgumentNullException("evidence");
            }

            PolicyStatement ps = root_code_group.Resolve(evidence);

            return((ps != null) ? ps : PolicyStatement.Empty());
        }
Exemple #3
0
        public override PolicyStatement Resolve(Evidence evidence)
        {
            if (null == evidence)
            {
                throw new ArgumentNullException("evidence");
            }

            if (!MembershipCondition.Check(evidence))
            {
                return(null);
            }

            PermissionSet ps = null;

            if (this.PolicyStatement == null)
            {
                ps = new PermissionSet(PermissionState.None);
            }
            else
            {
                ps = this.PolicyStatement.PermissionSet.Copy();
            }

            if (this.Children.Count > 0)
            {
                foreach (CodeGroup child_cg in this.Children)
                {
                    PolicyStatement child_pst = child_cg.Resolve(evidence);
                    if (child_pst != null)
                    {
                        ps = ps.Union(child_pst.PermissionSet);
                    }
                }
            }

            PolicyStatement pst = null;

            if (this.PolicyStatement != null)
            {
                pst = this.PolicyStatement.Copy();
            }
            else
            {
                pst = PolicyStatement.Empty();
            }
            pst.PermissionSet = ps;
            return(pst);
        }
        /// <summary>Resolves policy for the code group and its descendants for a set of evidence.</summary>
        /// <returns>A policy statement consisting of the permissions granted by the code group with optional attributes, or null if the code group does not apply (the membership condition does not match the specified evidence).</returns>
        /// <param name="evidence">The evidence for the assembly. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="evidence" /> parameter is null. </exception>
        /// <exception cref="T:System.Security.Policy.PolicyException">The current policy is null.-or- More than one code group (including the parent code group and all child code groups) is marked <see cref="F:System.Security.Policy.PolicyStatementAttribute.Exclusive" />. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" />
        /// </PermissionSet>
        public override PolicyStatement Resolve(Evidence evidence)
        {
            if (evidence == null)
            {
                throw new ArgumentNullException("evidence");
            }
            if (!base.MembershipCondition.Check(evidence))
            {
                return(null);
            }
            PermissionSet permissionSet = null;

            if (base.PolicyStatement == null)
            {
                permissionSet = new PermissionSet(PermissionState.None);
            }
            else
            {
                permissionSet = base.PolicyStatement.PermissionSet.Copy();
            }
            if (base.Children.Count > 0)
            {
                foreach (object obj in base.Children)
                {
                    CodeGroup       codeGroup       = (CodeGroup)obj;
                    PolicyStatement policyStatement = codeGroup.Resolve(evidence);
                    if (policyStatement != null)
                    {
                        permissionSet = permissionSet.Union(policyStatement.PermissionSet);
                    }
                }
            }
            PolicyStatement policyStatement2;

            if (base.PolicyStatement != null)
            {
                policyStatement2 = base.PolicyStatement.Copy();
            }
            else
            {
                policyStatement2 = PolicyStatement.Empty();
            }
            policyStatement2.PermissionSet = permissionSet;
            return(policyStatement2);
        }