// Demonstrate the Copy method, which creates an identical
    // copy of the current permission.
    private bool CopyDemo()
    {
        Console.WriteLine(
            "************************************************************");
        //<Snippet2>
        GacMembershipCondition Gac1 = new GacMembershipCondition();

        Console.WriteLine("Original membership condition = ");
        Console.WriteLine(Gac1.ToXml().ToString());
        try
        {
            IMembershipCondition membershipCondition = Gac1.Copy();
            Console.WriteLine("Result of Copy = ");
            Console.WriteLine(
                ((GacMembershipCondition)membershipCondition).ToXml().ToString()
                );
        }
        catch (Exception e)
        {
            Console.WriteLine("Copy failed : " + Gac1.ToString() + e);
            return(false);
        }

        //</Snippet2>
        return(true);
    }
        // Token: 0x06001D76 RID: 7542 RVA: 0x00066A5C File Offset: 0x00064C5C
        internal static bool CanUseQuickCache(CodeGroup group)
        {
            ArrayList arrayList = new ArrayList();

            arrayList.Add(group);
            for (int i = 0; i < arrayList.Count; i++)
            {
                group = (CodeGroup)arrayList[i];
                IUnionSemanticCodeGroup unionSemanticCodeGroup = group as IUnionSemanticCodeGroup;
                if (unionSemanticCodeGroup == null)
                {
                    return(false);
                }
                if (!PolicyManager.TestPolicyStatement(group.PolicyStatement))
                {
                    return(false);
                }
                IMembershipCondition membershipCondition = group.MembershipCondition;
                if (membershipCondition != null && !(membershipCondition is IConstantMembershipCondition))
                {
                    return(false);
                }
                IList children = group.Children;
                if (children != null && children.Count > 0)
                {
                    foreach (object value in children)
                    {
                        arrayList.Add(value);
                    }
                }
            }
            return(true);
        }
Beispiel #3
0
 private bool ParseMembershipCondition(bool safeLoad)
 {
     lock (this)
     {
         IMembershipCondition condition = null;
         SecurityElement      el        = this.m_element.SearchForChildByTag("IMembershipCondition");
         if (el == null)
         {
             throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "IMembershipCondition", base.GetType().FullName }));
         }
         try
         {
             condition = XMLUtil.CreateMembershipCondition(el);
             if (condition == null)
             {
                 return(false);
             }
         }
         catch (Exception exception)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"), exception);
         }
         condition.FromXml(el, this.m_parentLevel);
         this.m_membershipCondition = condition;
         return(true);
     }
 }
        private bool ParseMembershipCondition(bool safeLoad)
        {
            lock (this)
            {
                IMembershipCondition membershipCondition   = null;
                SecurityElement      elMembershipCondition = m_element.SearchForChildByTag("IMembershipCondition");
                if (elMembershipCondition != null)
                {
                    try
                    {
                        membershipCondition = System.Security.Util.XMLUtil.CreateMembershipCondition(elMembershipCondition, safeLoad);

                        if (membershipCondition == null)
                        {
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"), ex);
                    }
                    membershipCondition.FromXml(elMembershipCondition, m_parentLevel);
                }
                else
                {
                    throw new ArgumentException(String.Format(Environment.GetResourceString("Argument_InvalidXMLElement"), "IMembershipCondition", this.GetType().FullName));
                }

                m_membershipCondition = membershipCondition;
                return(true);
            }
        }
Beispiel #5
0
        internal static bool CanUseQuickCache(CodeGroup group)
        {
            ArrayList arrayList = new ArrayList();

            arrayList.Add((object)group);
            for (int index = 0; index < arrayList.Count; ++index)
            {
                group = (CodeGroup)arrayList[index];
                if (!(group is IUnionSemanticCodeGroup) || !PolicyManager.TestPolicyStatement(group.PolicyStatement))
                {
                    return(false);
                }
                IMembershipCondition membershipCondition = group.MembershipCondition;
                if (membershipCondition != null && !(membershipCondition is IConstantMembershipCondition))
                {
                    return(false);
                }
                IList children = group.Children;
                if (children != null && children.Count > 0)
                {
                    foreach (object obj in (IEnumerable)children)
                    {
                        arrayList.Add(obj);
                    }
                }
            }
            return(true);
        }
Beispiel #6
0
 private bool ParseMembershipCondition(bool safeLoad)
 {
     lock (this)
     {
         SecurityElement local_3 = this.m_element.SearchForChildByTag("IMembershipCondition");
         if (local_3 == null)
         {
             throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), (object)"IMembershipCondition", (object)this.GetType().FullName));
         }
         IMembershipCondition local_2_1;
         try
         {
             local_2_1 = XMLUtil.CreateMembershipCondition(local_3);
             if (local_2_1 == null)
             {
                 return(false);
             }
         }
         catch (Exception exception_0)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"), exception_0);
         }
         local_2_1.FromXml(local_3, this.m_parentLevel);
         this.m_membershipCondition = local_2_1;
         return(true);
     }
 }
Beispiel #7
0
        private bool ParseMembershipCondition(bool safeLoad)
        {
            bool result;

            lock (this)
            {
                IMembershipCondition membershipCondition = null;
                SecurityElement      securityElement     = this.m_element.SearchForChildByTag("IMembershipCondition");
                if (securityElement == null)
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), "IMembershipCondition", base.GetType().FullName));
                }
                try
                {
                    membershipCondition = XMLUtil.CreateMembershipCondition(securityElement);
                    if (membershipCondition == null)
                    {
                        return(false);
                    }
                }
                catch (Exception innerException)
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"), innerException);
                }
                membershipCondition.FromXml(securityElement, this.m_parentLevel);
                this.m_membershipCondition = membershipCondition;
                result = true;
            }
            return(result);
        }
 internal CodeGroup()
 {
     m_membershipCondition = null;
     m_children = null;
     m_policy = null;
     m_element = null;
     m_parentLevel = null;
 }
 internal CodeGroup()
 {
     m_membershipCondition = null;
     m_children            = null;
     m_policy      = null;
     m_element     = null;
     m_parentLevel = null;
 }
Beispiel #10
0
        /// <summary>Reconstructs a security object with a given state and policy level from an XML encoding.</summary>
        /// <param name="e">The XML encoding to use to reconstruct the security object. </param>
        /// <param name="level">The policy level within which the code group exists. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="e" /> parameter is null. </exception>
        public void FromXml(SecurityElement e, PolicyLevel level)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            string        text = e.Attribute("PermissionSetName");
            PermissionSet permissionSet;

            if (text != null && level != null)
            {
                permissionSet = level.GetNamedPermissionSet(text);
            }
            else
            {
                SecurityElement securityElement = e.SearchForChildByTag("PermissionSet");
                if (securityElement != null)
                {
                    Type type = Type.GetType(securityElement.Attribute("class"));
                    permissionSet = (PermissionSet)Activator.CreateInstance(type, true);
                    permissionSet.FromXml(securityElement);
                }
                else
                {
                    permissionSet = new PermissionSet(new PermissionSet(PermissionState.None));
                }
            }
            this.m_policy = new PolicyStatement(permissionSet);
            this.m_children.Clear();
            if (e.Children != null && e.Children.Count > 0)
            {
                foreach (object obj in e.Children)
                {
                    SecurityElement securityElement2 = (SecurityElement)obj;
                    if (securityElement2.Tag == "CodeGroup")
                    {
                        this.AddChild(CodeGroup.CreateFromXml(securityElement2, level));
                    }
                }
            }
            this.m_membershipCondition = null;
            SecurityElement securityElement3 = e.SearchForChildByTag("IMembershipCondition");

            if (securityElement3 != null)
            {
                string text2 = securityElement3.Attribute("class");
                Type   type2 = Type.GetType(text2);
                if (type2 == null)
                {
                    type2 = Type.GetType("System.Security.Policy." + text2);
                }
                this.m_membershipCondition = (IMembershipCondition)Activator.CreateInstance(type2, true);
                this.m_membershipCondition.FromXml(securityElement3, level);
            }
            this.m_name        = e.Attribute("Name");
            this.m_description = e.Attribute("Description");
            this.ParseXml(e, level);
        }
Beispiel #11
0
//		PolicyLevel m_level;

		protected CodeGroup (IMembershipCondition membershipCondition, PolicyStatement policy)
		{
			if (null == membershipCondition)
				throw new ArgumentNullException ("membershipCondition");

			if (policy != null)
				m_policy = policy.Copy ();
			m_membershipCondition = membershipCondition.Copy ();
		}
Beispiel #12
0
 internal CodeGroup(IMembershipCondition membershipCondition, PermissionSet permSet)
 {
     this.m_membershipCondition = membershipCondition;
     this.m_policy = new System.Security.Policy.PolicyStatement();
     this.m_policy.SetPermissionSetNoCopy(permSet);
     this.m_children    = ArrayList.Synchronized(new ArrayList());
     this.m_element     = null;
     this.m_parentLevel = null;
 }
 internal CodeGroup(IMembershipCondition membershipCondition, PermissionSet permSet)
 {
     this.m_membershipCondition = membershipCondition;
     this.m_policy = new System.Security.Policy.PolicyStatement();
     this.m_policy.SetPermissionSetNoCopy(permSet);
     this.m_children = ArrayList.Synchronized(new ArrayList());
     this.m_element = null;
     this.m_parentLevel = null;
 }
 internal static bool CheckMembershipCondition(IMembershipCondition membershipCondition, Evidence evidence, out object usedEvidence)
 {
     IReportMatchMembershipCondition condition = membershipCondition as IReportMatchMembershipCondition;
     if (condition != null)
     {
         return condition.Check(evidence, out usedEvidence);
     }
     usedEvidence = null;
     evidence.MarkAllEvidenceAsUsed();
     return membershipCondition.Check(evidence);
 }
Beispiel #15
0
 // Constructors.
 public CodeGroup(IMembershipCondition membershipCondition,
                  PolicyStatement policy)
 {
     if (membershipCondition == null)
     {
         throw new ArgumentNullException("membershipCondition");
     }
     this.membershipCondition = membershipCondition;
     this.policy   = policy;
     this.children = new ArrayList();
 }
	// Constructors.
	public CodeGroup(IMembershipCondition membershipCondition,
					 PolicyStatement policy)
			{
				if(membershipCondition == null)
				{
					throw new ArgumentNullException("membershipCondition");
				}
				this.membershipCondition = membershipCondition;
				this.policy = policy;
				this.children = new ArrayList();
			}
        internal CodeGroup( IMembershipCondition membershipCondition, PermissionSet permSet )
        {
            BCLDebug.Assert( membershipCondition != null, "membershipCondition != null" );
            BCLDebug.Assert( permSet != null, "permSet != null" );

            m_membershipCondition = membershipCondition;
            m_policy = new PolicyStatement();
            m_policy.SetPermissionSetNoCopy( permSet );
            m_children = ArrayList.Synchronized( new ArrayList() );
            m_element = null;
            m_parentLevel = null;
        }
        internal CodeGroup(IMembershipCondition membershipCondition, PermissionSet permSet)
        {
            Contract.Assert(membershipCondition != null, "membershipCondition != null");
            Contract.Assert(permSet != null, "permSet != null");

            m_membershipCondition = membershipCondition;
            m_policy = new PolicyStatement();
            m_policy.SetPermissionSetNoCopy(permSet);
            m_children    = ArrayList.Synchronized(new ArrayList());
            m_element     = null;
            m_parentLevel = null;
        }
Beispiel #19
0
 /// <summary>Initializes a new instance of <see cref="T:System.Security.Policy.CodeGroup" />.</summary>
 /// <param name="membershipCondition">A membership condition that tests evidence to determine whether this code group applies policy. </param>
 /// <param name="policy">The policy statement for the code group in the form of a permission set and attributes to grant code that matches the membership condition. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="membershipCondition" /> parameter is null. </exception>
 /// <exception cref="T:System.ArgumentException">The type of the <paramref name="membershipCondition" /> parameter is not valid.-or- The type of the <paramref name="policy" /> parameter is not valid. </exception>
 protected CodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy)
 {
     if (membershipCondition == null)
     {
         throw new ArgumentNullException("membershipCondition");
     }
     if (policy != null)
     {
         this.m_policy = policy.Copy();
     }
     this.m_membershipCondition = membershipCondition.Copy();
 }
        internal static bool CheckMembershipCondition(IMembershipCondition membershipCondition, Evidence evidence, out object usedEvidence)
        {
            IReportMatchMembershipCondition condition = membershipCondition as IReportMatchMembershipCondition;

            if (condition != null)
            {
                return(condition.Check(evidence, out usedEvidence));
            }
            usedEvidence = null;
            evidence.MarkAllEvidenceAsUsed();
            return(membershipCondition.Check(evidence));
        }
Beispiel #21
0
        /// <summary>初始化 <see cref="T:System.Security.Policy.CodeGroup" /> 的新实例。</summary>
        /// <param name="membershipCondition">成员条件,它测试证据以确定此代码组是否应用策略。</param>
        /// <param name="policy">形式为权限集和特性的代码组的策略声明,这些权限集和特性将被授予匹配成员条件的代码。</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="membershipCondition" /> 参数为 null。</exception>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="membershipCondition" /> 参数的类型无效。- 或 -<paramref name="policy" /> 参数的类型无效。</exception>
        protected CodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy)
        {
            if (membershipCondition == null)
            {
                throw new ArgumentNullException("membershipCondition");
            }
            this.m_policy = policy != null?policy.Copy() : (PolicyStatement)null;

            this.m_membershipCondition = membershipCondition.Copy();
            this.m_children            = (IList)ArrayList.Synchronized(new ArrayList());
            this.m_element             = (SecurityElement)null;
            this.m_parentLevel         = (PolicyLevel)null;
        }
Beispiel #22
0
        public CodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy)
#endif
        {
            if (null == membershipCondition)
            {
                throw new ArgumentNullException("membershipCondition");
            }

            if (policy != null)
            {
                m_policy = policy.Copy();
            }
            m_membershipCondition = membershipCondition.Copy();
        }
        protected CodeGroup( IMembershipCondition membershipCondition, PolicyStatement policy )
        {
            if (membershipCondition == null)
                throw new ArgumentNullException( "membershipCondition" );

            if (policy == null)
                m_policy = null;
            else
                m_policy = policy.Copy();
        
            m_membershipCondition = membershipCondition.Copy();
            m_children = ArrayList.Synchronized( new ArrayList() );
            m_element = null;
            m_parentLevel = null;
        }
Beispiel #24
0
        public static void GacMembershipConditionCallMethods()
        {
            GacMembershipCondition gmc = new GacMembershipCondition();
            bool check = gmc.Check(new Evidence());
            IMembershipCondition obj = gmc.Copy();

            check = gmc.Equals(new object());
            int             hash = gmc.GetHashCode();
            string          str  = gmc.ToString();
            SecurityElement se   = new SecurityElement("");
            PolicyLevel     pl   = (PolicyLevel)Activator.CreateInstance(typeof(PolicyLevel), true);

            gmc.FromXml(se);
            gmc.FromXml(se, pl);
            se = gmc.ToXml();
            se = gmc.ToXml(pl);
        }
        public static void StrongNameMembershipConditionCallMethods()
        {
            StrongNameMembershipCondition snmc = new StrongNameMembershipCondition(new StrongNamePublicKeyBlob(new byte[1]), "test", new Version(0, 1));
            bool check = snmc.Check(new Evidence());
            IMembershipCondition obj = snmc.Copy();

            check = snmc.Equals(new object());
            int             hash = snmc.GetHashCode();
            string          str  = snmc.ToString();
            SecurityElement se   = new SecurityElement("");
            PolicyLevel     pl   = (PolicyLevel)FormatterServices.GetUninitializedObject(typeof(PolicyLevel));

            snmc.FromXml(se);
            snmc.FromXml(se, pl);
            se = snmc.ToXml();
            se = snmc.ToXml(pl);
        }
        public static void PublisherMembershipConditionCallMethods()
        {
            PublisherMembershipCondition pmc = new PublisherMembershipCondition(new System.Security.Cryptography.X509Certificates.X509Certificate());
            bool check = pmc.Check(new Evidence());
            IMembershipCondition obj = pmc.Copy();

            check = pmc.Equals(new object());
            int             hash = pmc.GetHashCode();
            string          str  = pmc.ToString();
            SecurityElement se   = new SecurityElement("");
            PolicyLevel     pl   = (PolicyLevel)FormatterServices.GetUninitializedObject(typeof(PolicyLevel));

            pmc.FromXml(se);
            pmc.FromXml(se, pl);
            se = pmc.ToXml();
            se = pmc.ToXml(pl);
        }
        public static void HashMembershipConditionCallMethods()
        {
            HashMembershipCondition hmc = new HashMembershipCondition(Cryptography.SHA1.Create(), new byte[1]);
            bool check = hmc.Check(new Evidence());
            IMembershipCondition obj = hmc.Copy();

            check = hmc.Equals(new object());
            int             hash = hmc.GetHashCode();
            string          str  = hmc.ToString();
            SecurityElement se   = new SecurityElement("");
            PolicyLevel     pl   = (PolicyLevel)FormatterServices.GetUninitializedObject(typeof(PolicyLevel));

            hmc.FromXml(se);
            hmc.FromXml(se, pl);
            se = hmc.ToXml();
            se = hmc.ToXml(pl);
        }
        public static void GacMembershipConditionCallMethods()
        {
            GacMembershipCondition gmc = new GacMembershipCondition();
            bool check = gmc.Check(new Evidence());
            IMembershipCondition obj = gmc.Copy();

            check = gmc.Equals(new object());
            int             hash = gmc.GetHashCode();
            string          str  = gmc.ToString();
            SecurityElement se   = new SecurityElement("");
            PolicyLevel     pl   = (PolicyLevel)FormatterServices.GetUninitializedObject(typeof(PolicyLevel));

            gmc.FromXml(se);
            gmc.FromXml(se, pl);
            se = gmc.ToXml();
            se = gmc.ToXml(pl);
        }
Beispiel #29
0
        // Here is the managed portion of the QuickCache code.  It
        // is mainly concerned with detecting whether it is valid
        // for us to use the quick cache, and then calculating the
        // proper mapping of partial evidence to partial mapping.
        //
        // The choice of the partial evidence sets is fairly arbitrary
        // and in this case is tailored to give us meaningful
        // results from default policy.
        //
        // The choice of whether or not we can use the quick cache
        // is far from arbitrary.  There are a number of conditions that must
        // be true for the QuickCache to produce valid result.  These
        // are:
        //
        // * equivalent evidence objects must produce the same
        //   grant set (i.e. it must be independent of time of day,
        //   space on the harddisk, other "external" factors, and
        //   cannot be random).
        //
        // * evidence must be used positively (i.e. if evidence A grants
        //   permission X, then evidence A+B must grant at least permission
        //   X).
        //
        // In particular for our implementation, this means that we
        // limit the classes that can be used by policy to just
        // the ones defined within mscorlib and that there are
        // no Exclusive bits set on any code groups.

        internal static bool CanUseQuickCache(CodeGroup group)
        {
            ArrayList list = new ArrayList();

            list.Add(group);

            for (int i = 0; i < list.Count; ++i)
            {
                group = (CodeGroup)list[i];

                IUnionSemanticCodeGroup unionGroup = group as IUnionSemanticCodeGroup;

                if (unionGroup != null)
                {
                    if (!TestPolicyStatement(group.PolicyStatement))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                IMembershipCondition cond = group.MembershipCondition;
                if (cond != null && !(cond is IConstantMembershipCondition))
                {
                    return(false);
                }

                IList children = group.Children;

                if (children != null && children.Count > 0)
                {
                    IEnumerator enumerator = children.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        list.Add(enumerator.Current);
                    }
                }
            }

            return(true);
        }
Beispiel #30
0
 public void FromXml(SecurityElement e, PolicyLevel level)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     lock (this)
     {
         this.m_element             = e;
         this.m_parentLevel         = level;
         this.m_children            = null;
         this.m_membershipCondition = null;
         this.m_policy      = null;
         this.m_name        = e.Attribute("Name");
         this.m_description = e.Attribute("Description");
         this.ParseXml(e, level);
     }
 }
Beispiel #31
0
 protected CodeGroup(IMembershipCondition membershipCondition, System.Security.Policy.PolicyStatement policy)
 {
     if (membershipCondition == null)
     {
         throw new ArgumentNullException("membershipCondition");
     }
     if (policy == null)
     {
         this.m_policy = null;
     }
     else
     {
         this.m_policy = policy.Copy();
     }
     this.m_membershipCondition = membershipCondition.Copy();
     this.m_children            = ArrayList.Synchronized(new ArrayList());
     this.m_element             = null;
     this.m_parentLevel         = null;
 }
 protected CodeGroup(IMembershipCondition membershipCondition, System.Security.Policy.PolicyStatement policy)
 {
     if (membershipCondition == null)
     {
         throw new ArgumentNullException("membershipCondition");
     }
     if (policy == null)
     {
         this.m_policy = null;
     }
     else
     {
         this.m_policy = policy.Copy();
     }
     this.m_membershipCondition = membershipCondition.Copy();
     this.m_children = ArrayList.Synchronized(new ArrayList());
     this.m_element = null;
     this.m_parentLevel = null;
 }
Beispiel #33
0
        }// CreateCodegroup

        private CSingleCodeGroup FindExistingCodegroup(PolicyLevel pl, IMembershipCondition mc)
        {
            // If we have an existing one, it should be right under the root node
            CSingleCodeGroup scgParent = Security.GetRootCodeGroupNode(pl);

            for (int i = 0; i < scgParent.NumChildren; i++)
            {
                CSingleCodeGroup scg = (CSingleCodeGroup)CNodeManager.GetNode(scgParent.Child[i]);

                // See if we have a matching membership condition and the description
                // says it's one the wizard created
                if (scg.MyCodeGroup.MembershipCondition.ToString().Equals(mc.ToString()) && scg.MyCodeGroup.Description.Equals(CResourceStore.GetString("GeneratedCodegroup")))
                {
                    return(scg);
                }
            }

            // We weren't able to find one
            return(null);
        }// FindExistingCodegroup
Beispiel #34
0
#pragma warning restore 618

        /// <summary>
        ///     Check the membership condition to see if it matches the given evidence, and if the
        ///     membership condition supports it also return the evidence which was used to match the
        ///     membership condition.
        /// </summary>
        internal static bool CheckMembershipCondition(IMembershipCondition membershipCondition,
                                                      Evidence evidence,
                                                      out object usedEvidence) {
            BCLDebug.Assert(membershipCondition != null, "membershipCondition != null");
            BCLDebug.Assert(evidence != null, "evidence != null");

            IReportMatchMembershipCondition reportMatchMembershipCondition = membershipCondition as IReportMatchMembershipCondition;

            // If the membership condition supports telling us which evidence was used to match, then use
            // that capability.  Otherwise, we cannot report this information - which means we need to be
            // conservative and assume that all of the evidence was used and mark it as such.
            if (reportMatchMembershipCondition != null) {
                return reportMatchMembershipCondition.Check(evidence, out usedEvidence);
            }
            else {
                usedEvidence = null;
                evidence.MarkAllEvidenceAsUsed();

                return membershipCondition.Check(evidence);
            }
        }
	public FirstMatchCodeGroup(IMembershipCondition membershipCondition,
					     	   PolicyStatement policy)
			: base(membershipCondition, policy)
			{
				// Nothing to do here.
			}
Beispiel #36
0
		public FirstMatchCodeGroup (IMembershipCondition membershipCondition, PolicyStatement policy)
			: base (membershipCondition, policy)
		{
		}
 public NetCodeGroup( IMembershipCondition membershipCondition )
     : base( membershipCondition, (PolicyStatement)null )
 {
     SetDefaults();
 }
 public FileCodeGroup(IMembershipCondition membershipCondition, FileIOPermissionAccess access)
     : base(membershipCondition, (PolicyStatement)null) {
     m_access = access;
 }
Beispiel #39
0
 public FirstMatchCodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy)
     : base(default(IMembershipCondition), default(PolicyStatement))
 {
 }
Beispiel #40
0
 public FileCodeGroup(IMembershipCondition membershipCondition, FileIOPermissionAccess access)
     : base(membershipCondition, (PolicyStatement)null)
 {
     m_access = access;
 }
Beispiel #41
0
 protected CodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy) { }
 public UnionCodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy)
 {
 }
 internal UnionCodeGroup( IMembershipCondition membershipCondition, PermissionSet permSet )
     : base( membershipCondition, permSet )
 {
 }
        private bool ParseMembershipCondition( bool safeLoad )
        {
            lock (this)
            {
                IMembershipCondition membershipCondition = null;
                SecurityElement elMembershipCondition = m_element.SearchForChildByTag( "IMembershipCondition" );
                if (elMembershipCondition != null)
                {
                    try
                    {
                        membershipCondition = System.Security.Util.XMLUtil.CreateMembershipCondition( elMembershipCondition );

                        if (membershipCondition == null)
                            return false;
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ), ex );
                    }
//                    catch
//                    {
//                        throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ) );
//                    }
                    membershipCondition.FromXml( elMembershipCondition, m_parentLevel );
                }
                else
                {
                    throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ),  "IMembershipCondition", this.GetType().FullName ) );
                }
                
                m_membershipCondition = membershipCondition;
                return true;
            }
        }
	public NetCodeGroup(IMembershipCondition membershipCondition)
			: base(membershipCondition, null)
			{
				// Nothing to do here.
			}
Beispiel #46
0
		public FileCodeGroup (IMembershipCondition membershipCondition, FileIOPermissionAccess access) 
			: base (membershipCondition, null)
		{
			// note: FileIOPermissionAccess is a [Flag]
			m_access = access;
		}
 public FileCodeGroup (IMembershipCondition membershipCondition, System.Security.Permissions.FileIOPermissionAccess access) {
   return default(FileCodeGroup);
 }
	public void FromXml(SecurityElement et, PolicyLevel level)
			{
				SecurityElement child;
				String className;
				Type type;
				ArrayList list;
				CodeGroup group;

				if(et == null)
				{
					throw new ArgumentNullException("et");
				}
				if(et.Tag != "CodeGroup")
				{
					throw new ArgumentException
						(_("Security_CodeGroupName"));
				}
				if(et.Attribute("version") != "1")
				{
					throw new ArgumentException
						(_("Security_PolicyVersion"));
				}
				name = et.Attribute("Name");
				description = et.Attribute("Description");

				// Load the membership condition information for the group.
				child = et.SearchForChildByTag("IMembershipCondition");
				if(child != null)
				{
					className = child.Attribute("class");
					if(className == null)
					{
						throw new ArgumentException
							(_("Invalid_PermissionXml"));
					}
					type = Type.GetType(className);
					if(type == null && className.IndexOf('.') == -1)
					{
						// May not have been fully-qualified.
						type = Type.GetType
							("System.Security.Policy." + className);
					}
					if(!typeof(IMembershipCondition).IsAssignableFrom(type))
					{
						throw new ArgumentException
							(_("Invalid_PermissionXml"));
					}
					membershipCondition =
						(Activator.CreateInstance(type)
								as IMembershipCondition);
					if(membershipCondition != null)
					{
						membershipCondition.FromXml(child, level);
					}
				}
				else
				{
					throw new ArgumentException
						(_("Arg_InvalidMembershipCondition"));
				}

				// Load the children within this code group.
				list = new ArrayList();
				foreach(SecurityElement elem in et.Children)
				{
					if(elem.Tag != "CodeGroup")
					{
						continue;
					}
					className = child.Attribute("class");
					if(className == null)
					{
						throw new ArgumentException
							(_("Invalid_PermissionXml"));
					}
					type = Type.GetType(className);
					if(type == null && className.IndexOf('.') == -1)
					{
						// May not have been fully-qualified.
						type = Type.GetType
							("System.Security.Policy." + className);
					}
					if(!typeof(CodeGroup).IsAssignableFrom(type))
					{
						throw new ArgumentException
							(_("Invalid_PermissionXml"));
					}
					group = (Activator.CreateInstance(type) as CodeGroup);
					if(group != null)
					{
						group.FromXml(elem, level);
						list.Add(group);
					}
				}
				children = list;

				// Parse subclass-specific data from the element.
				ParseXml(et, level);
			}
#pragma warning restore 618

        /// <summary>
        ///     Check the membership condition to see if it matches the given evidence, and if the
        ///     membership condition supports it also return the evidence which was used to match the
        ///     membership condition.
        /// </summary>
        internal static bool CheckMembershipCondition(IMembershipCondition membershipCondition,
                                                      Evidence evidence,
                                                      out object usedEvidence) {
            BCLDebug.Assert(membershipCondition != null, "membershipCondition != null");
            BCLDebug.Assert(evidence != null, "evidence != null");

            IReportMatchMembershipCondition reportMatchMembershipCondition = membershipCondition as IReportMatchMembershipCondition;

            // If the membership condition supports telling us which evidence was used to match, then use
            // that capability.  Otherwise, we cannot report this information - which means we need to be
            // conservative and assume that all of the evidence was used and mark it as such.
            if (reportMatchMembershipCondition != null) {
                return reportMatchMembershipCondition.Check(evidence, out usedEvidence);
            }
            else {
                usedEvidence = null;
                evidence.MarkAllEvidenceAsUsed();

                return membershipCondition.Check(evidence);
            }
        }
Beispiel #50
0
		public MySecondCodeGroup (IMembershipCondition membershipCondition, PolicyStatement policy) 
			: base (membershipCondition, policy) {}
 public void FromXml(SecurityElement e, PolicyLevel level)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     lock (this)
     {
         this.m_element = e;
         this.m_parentLevel = level;
         this.m_children = null;
         this.m_membershipCondition = null;
         this.m_policy = null;
         this.m_name = e.Attribute("Name");
         this.m_description = e.Attribute("Description");
         this.ParseXml(e, level);
     }
 }
Beispiel #52
0
		public void FromXml (SecurityElement e, PolicyLevel level)
		{
			if (null == e)
				throw new ArgumentNullException("e");

			PermissionSet ps = null;
			string psetname = e.Attribute ("PermissionSetName");
			if ((psetname != null) && (level != null)) {
				ps = level.GetNamedPermissionSet (psetname);
			}
			else {
				SecurityElement pset = e.SearchForChildByTag ("PermissionSet");
				if (pset != null) {
					Type classType = Type.GetType (pset.Attribute ("class"));
					ps = (PermissionSet) Activator.CreateInstance (classType, true);
					ps.FromXml (pset);
				}
				else {
					ps = new PermissionSet (new PermissionSet (PermissionState.None));
				}
			}
			m_policy = new PolicyStatement (ps);

			m_children.Clear ();
			if ((e.Children != null) && (e.Children.Count > 0)) {
				foreach (SecurityElement se in e.Children) {
					if (se.Tag == "CodeGroup") {
						this.AddChild (CodeGroup.CreateFromXml (se, level));
					}
				}
			}
			
			m_membershipCondition = null;
			SecurityElement mc = e.SearchForChildByTag ("IMembershipCondition");
			if (mc != null) {
				string className = mc.Attribute ("class");
				Type classType = Type.GetType (className);
				if (classType == null)
					classType = Type.GetType ("System.Security.Policy." + className);
				m_membershipCondition = (IMembershipCondition) Activator.CreateInstance (classType, true);
				m_membershipCondition.FromXml (mc, level);
			}

			m_name = e.Attribute("Name");
			m_description = e.Attribute("Description");

			// seems like we might need this to Resolve() in subclasses
			//m_level = level;

			ParseXml (e, level);
		}
 public NetCodeGroup (IMembershipCondition membershipCondition) {
   return default(NetCodeGroup);
 }
 public FirstMatchCodeGroup (IMembershipCondition membershipCondition, PolicyStatement policy) {
   return default(FirstMatchCodeGroup);
 }
 private bool ParseMembershipCondition(bool safeLoad)
 {
     lock (this)
     {
         IMembershipCondition condition = null;
         SecurityElement el = this.m_element.SearchForChildByTag("IMembershipCondition");
         if (el == null)
         {
             throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "IMembershipCondition", base.GetType().FullName }));
         }
         try
         {
             condition = XMLUtil.CreateMembershipCondition(el);
             if (condition == null)
             {
                 return false;
             }
         }
         catch (Exception exception)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement"), exception);
         }
         condition.FromXml(el, this.m_parentLevel);
         this.m_membershipCondition = condition;
         return true;
     }
 }
Beispiel #56
0
 public FileCodeGroup(IMembershipCondition membershipCondition, Permissions.FileIOPermissionAccess access) : base(default(IMembershipCondition), default(PolicyStatement))
 {
 }
Beispiel #57
0
 public FileCodeGroup(IMembershipCondition membershipCondition, Permissions.FileIOPermissionAccess access) : base(default(IMembershipCondition), default(PolicyStatement)) { }
 /// <include file='doc\FirstMatchCodeGroup.uex' path='docs/doc[@for="FirstMatchCodeGroup.FirstMatchCodeGroup"]/*' />
 public FirstMatchCodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy)
     : base(membershipCondition, policy)
 {
 }
		public ApplicationSecurityManagerCodeGroup (IMembershipCondition membershipCondition)
			: base (membershipCondition, null)
		{
		}