コード例 #1
0
        internal void FromXml(SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly)
        {
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }
            if (!doc.GetTagForElement(position).Equals("PolicyStatement"))
            {
                throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), (object)"PolicyStatement", (object)this.GetType().FullName));
            }
            this.m_attributes = PolicyStatementAttribute.Nothing;
            string attributeForElement = doc.GetAttributeForElement(position, "Attributes");

            if (attributeForElement != null)
            {
                this.m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), attributeForElement);
            }
            lock (this)
            {
                this.m_permSet = (PermissionSet)null;
                if (level != null)
                {
                    string local_3 = doc.GetAttributeForElement(position, "PermissionSetName");
                    if (local_3 != null)
                    {
                        this.m_permSet = (PermissionSet)level.GetNamedPermissionSetInternal(local_3);
                        if (this.m_permSet == null)
                        {
                            this.m_permSet = new PermissionSet(PermissionState.None);
                        }
                    }
                }
                if (this.m_permSet == null)
                {
                    ArrayList local_4 = doc.GetChildrenPositionForElement(position);
                    int       local_5 = -1;
                    for (int local_6 = 0; local_6 < local_4.Count; ++local_6)
                    {
                        if (doc.GetTagForElement((int)local_4[local_6]).Equals("PermissionSet"))
                        {
                            local_5 = (int)local_4[local_6];
                        }
                    }
                    if (local_5 == -1)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                    }
                    string local_7 = doc.GetAttributeForElement(local_5, "class");
                    this.m_permSet = local_7 == null || !local_7.Equals("NamedPermissionSet") && !local_7.Equals("System.Security.NamedPermissionSet") ? new PermissionSet(PermissionState.None) : (PermissionSet) new NamedPermissionSet("DefaultName", PermissionState.None);
                    this.m_permSet.FromXml(doc, local_5, allowInternalOnly);
                }
                if (this.m_permSet != null)
                {
                    return;
                }
                this.m_permSet = new PermissionSet(PermissionState.None);
            }
        }
コード例 #2
0
        internal SecurityElement ToXml(PolicyLevel level, string policyClassName)
        {
            if ((this.m_membershipCondition == null) && (this.m_element != null))
            {
                this.ParseMembershipCondition();
            }
            if (this.m_children == null)
            {
                this.ParseChildren();
            }
            if ((this.m_policy == null) && (this.m_element != null))
            {
                this.ParsePolicy();
            }
            SecurityElement element = new SecurityElement("CodeGroup");

            XMLUtil.AddClassAttribute(element, base.GetType(), policyClassName);
            element.AddAttribute("version", "1");
            element.AddChild(this.m_membershipCondition.ToXml(level));
            if (this.m_policy != null)
            {
                PermissionSet      permissionSetNoCopy = this.m_policy.GetPermissionSetNoCopy();
                NamedPermissionSet set2 = permissionSetNoCopy as NamedPermissionSet;
                if (((set2 != null) && (level != null)) && (level.GetNamedPermissionSetInternal(set2.Name) != null))
                {
                    element.AddAttribute("PermissionSetName", set2.Name);
                }
                else if (!permissionSetNoCopy.IsEmpty())
                {
                    element.AddChild(permissionSetNoCopy.ToXml());
                }
                if (this.m_policy.Attributes != PolicyStatementAttribute.Nothing)
                {
                    element.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), this.m_policy.Attributes));
                }
            }
            if (this.m_children.Count > 0)
            {
                lock (this)
                {
                    IEnumerator enumerator = this.m_children.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        element.AddChild(((CodeGroup)enumerator.Current).ToXml(level));
                    }
                }
            }
            if (this.m_name != null)
            {
                element.AddAttribute("Name", SecurityElement.Escape(this.m_name));
            }
            if (this.m_description != null)
            {
                element.AddAttribute("Description", SecurityElement.Escape(this.m_description));
            }
            this.CreateXml(element, level);
            return(element);
        }
コード例 #3
0
        internal SecurityElement ToXml(PolicyLevel level, string policyClassName)
        {
            if (this.m_membershipCondition == null && this.m_element != null)
            {
                this.ParseMembershipCondition();
            }
            if (this.m_children == null)
            {
                this.ParseChildren();
            }
            if (this.m_policy == null && this.m_element != null)
            {
                this.ParsePolicy();
            }
            SecurityElement element = new SecurityElement("CodeGroup");

            XMLUtil.AddClassAttribute(element, this.GetType(), policyClassName);
            element.AddAttribute("version", "1");
            element.AddChild(this.m_membershipCondition.ToXml(level));
            if (this.m_policy != null)
            {
                PermissionSet      permissionSetNoCopy = this.m_policy.GetPermissionSetNoCopy();
                NamedPermissionSet namedPermissionSet  = permissionSetNoCopy as NamedPermissionSet;
                if (namedPermissionSet != null && level != null && level.GetNamedPermissionSetInternal(namedPermissionSet.Name) != null)
                {
                    element.AddAttribute("PermissionSetName", namedPermissionSet.Name);
                }
                else if (!permissionSetNoCopy.IsEmpty())
                {
                    element.AddChild(permissionSetNoCopy.ToXml());
                }
                if (this.m_policy.Attributes != PolicyStatementAttribute.Nothing)
                {
                    element.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), (object)this.m_policy.Attributes));
                }
            }
            if (this.m_children.Count > 0)
            {
                lock (this)
                {
                    foreach (CodeGroup item_0 in (IEnumerable)this.m_children)
                    {
                        element.AddChild(item_0.ToXml(level));
                    }
                }
            }
            if (this.m_name != null)
            {
                element.AddAttribute("Name", SecurityElement.Escape(this.m_name));
            }
            if (this.m_description != null)
            {
                element.AddAttribute("Description", SecurityElement.Escape(this.m_description));
            }
            this.CreateXml(element, level);
            return(element);
        }
コード例 #4
0
        internal void FromXml(SecurityElement et, PolicyLevel level, bool allowInternalOnly)
        {
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (!et.Tag.Equals("PolicyStatement"))
            {
                throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), (object)"PolicyStatement", (object)this.GetType().FullName));
            }
            this.m_attributes = PolicyStatementAttribute.Nothing;
            string str = et.Attribute("Attributes");

            if (str != null)
            {
                this.m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), str);
            }
            lock (this)
            {
                this.m_permSet = (PermissionSet)null;
                if (level != null)
                {
                    string local_3 = et.Attribute("PermissionSetName");
                    if (local_3 != null)
                    {
                        this.m_permSet = (PermissionSet)level.GetNamedPermissionSetInternal(local_3);
                        if (this.m_permSet == null)
                        {
                            this.m_permSet = new PermissionSet(PermissionState.None);
                        }
                    }
                }
                if (this.m_permSet == null)
                {
                    SecurityElement local_4 = et.SearchForChildByTag("PermissionSet");
                    if (local_4 == null)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                    }
                    string local_5 = local_4.Attribute("class");
                    this.m_permSet = local_5 == null || !local_5.Equals("NamedPermissionSet") && !local_5.Equals("System.Security.NamedPermissionSet") ? new PermissionSet(PermissionState.None) : (PermissionSet) new NamedPermissionSet("DefaultName", PermissionState.None);
                    try
                    {
                        this.m_permSet.FromXml(local_4, allowInternalOnly, true);
                    }
                    catch
                    {
                    }
                }
                if (this.m_permSet != null)
                {
                    return;
                }
                this.m_permSet = new PermissionSet(PermissionState.None);
            }
        }
コード例 #5
0
        /// <include file='doc\PolicyStatement.uex' path='docs/doc[@for="PolicyStatement.FromXml1"]/*' />
        public void FromXml(SecurityElement et, PolicyLevel level)
        {
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }

            if (!et.Tag.Equals("PolicyStatement"))
            {
                throw new ArgumentException(String.Format(Environment.GetResourceString("Argument_InvalidXMLElement"), "PolicyStatement", this.GetType().FullName));
            }

            m_attributes = (PolicyStatementAttribute)0;

            String strAttributes = et.Attribute("Attributes");

            if (strAttributes != null)
            {
                m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), strAttributes);
            }

            lock (this)
            {
                m_permSet = null;

                if (level != null)
                {
                    String permSetName = et.Attribute("PermissionSetName");

                    if (permSetName != null)
                    {
                        m_permSet = level.GetNamedPermissionSetInternal(permSetName);

                        if (m_permSet == null)
                        {
                            m_permSet = new PermissionSet(PermissionState.None);
                        }
                    }
                }


                if (m_permSet == null)
                {
                    // There is no provided level, it is not a named permission set, or
                    // the named permission set doesn't exist in the provided level,
                    // so just create the class through reflection and decode normally.

                    SecurityElement e = et.SearchForChildByTag("PermissionSet");

                    if (e != null)
                    {
                        String className = e.Attribute("class");

                        if (className != null && (className.Equals("NamedPermissionSet") ||
                                                  className.Equals("System.Security.NamedPermissionSet")))
                        {
                            m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
                        }
                        else
                        {
                            m_permSet = new PermissionSet(PermissionState.None);
                        }

                        try
                        {
                            // We play it conservative here and just say that we are loading policy
                            // anytime we have to decode a permission set.
                            bool fullyLoaded;
                            m_permSet.FromXml(e, true, out fullyLoaded);
                        }
                        catch (Exception)
                        {
                            // ignore any exceptions from the decode process.
                            // Note: we go ahead and use the permission set anyway.  This should be safe since
                            // the decode process should never give permission beyond what a proper decode would have
                            // given.
                        }
                    }
                    else
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                    }
                }

                if (m_permSet == null)
                {
                    m_permSet = new PermissionSet(PermissionState.None);
                }
            }
        }
コード例 #6
0
        [System.Security.SecurityCritical]  // auto-generated
        internal SecurityElement ToXml(PolicyLevel level, String policyClassName)
        {
            if (m_membershipCondition == null && m_element != null)
            {
                ParseMembershipCondition();
            }

            if (m_children == null)
            {
                ParseChildren();
            }

            if (m_policy == null && m_element != null)
            {
                ParsePolicy();
            }

            SecurityElement e = new SecurityElement("CodeGroup");

            System.Security.Util.XMLUtil.AddClassAttribute(e, this.GetType(), policyClassName);
            // If you hit this assert then most likely you are trying to change the name of this class.
            // This is ok as long as you change the hard coded string above and change the assert below.
            Contract.Assert(this.GetType().FullName.Equals(policyClassName), "Incorrect class name passed in! Was: " + policyClassName + " Should be " + this.GetType().FullName);

            e.AddAttribute("version", "1");

            e.AddChild(m_membershipCondition.ToXml(level));

            // Grab the inerts of the policy statement's xml and just stick it
            // into the code group xml directly. We do this to hide the policy statement from
            // users in the config file.

            if (m_policy != null)
            {
                PermissionSet      permSet      = m_policy.GetPermissionSetNoCopy();
                NamedPermissionSet namedPermSet = permSet as NamedPermissionSet;

                if (namedPermSet != null && level != null && level.GetNamedPermissionSetInternal(namedPermSet.Name) != null)
                {
                    e.AddAttribute("PermissionSetName", namedPermSet.Name);
                }
                else
                {
                    if (!permSet.IsEmpty())
                    {
                        e.AddChild(permSet.ToXml());
                    }
                }

                if (m_policy.Attributes != PolicyStatementAttribute.Nothing)
                {
                    e.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), m_policy.Attributes));
                }
            }

            if (m_children.Count > 0)
            {
                lock (this)
                {
                    IEnumerator enumerator = m_children.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        e.AddChild(((CodeGroup)enumerator.Current).ToXml(level));
                    }
                }
            }

            if (m_name != null)
            {
                e.AddAttribute("Name", SecurityElement.Escape(m_name));
            }

            if (m_description != null)
            {
                e.AddAttribute("Description", SecurityElement.Escape(m_description));
            }

            CreateXml(e, level);

            return(e);
        }
 internal void FromXml(SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly)
 {
     if (doc == null)
     {
         throw new ArgumentNullException("doc");
     }
     if (!doc.GetTagForElement(position).Equals("PolicyStatement"))
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PolicyStatement", base.GetType().FullName }));
     }
     this.m_attributes = PolicyStatementAttribute.Nothing;
     string attributeForElement = doc.GetAttributeForElement(position, "Attributes");
     if (attributeForElement != null)
     {
         this.m_attributes = (PolicyStatementAttribute) Enum.Parse(typeof(PolicyStatementAttribute), attributeForElement);
     }
     lock (this)
     {
         this.m_permSet = null;
         if (level != null)
         {
             string name = doc.GetAttributeForElement(position, "PermissionSetName");
             if (name != null)
             {
                 this.m_permSet = level.GetNamedPermissionSetInternal(name);
                 if (this.m_permSet == null)
                 {
                     this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                 }
             }
         }
         if (this.m_permSet == null)
         {
             ArrayList childrenPositionForElement = doc.GetChildrenPositionForElement(position);
             int num = -1;
             for (int i = 0; i < childrenPositionForElement.Count; i++)
             {
                 if (doc.GetTagForElement((int) childrenPositionForElement[i]).Equals("PermissionSet"))
                 {
                     num = (int) childrenPositionForElement[i];
                 }
             }
             if (num == -1)
             {
                 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
             }
             string str3 = doc.GetAttributeForElement(num, "class");
             if ((str3 != null) && (str3.Equals("NamedPermissionSet") || str3.Equals("System.Security.NamedPermissionSet")))
             {
                 this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
             }
             else
             {
                 this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
             }
             this.m_permSet.FromXml(doc, num, allowInternalOnly);
         }
         if (this.m_permSet == null)
         {
             this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
         }
     }
 }
コード例 #8
0
 internal SecurityElement ToXml(PolicyLevel level, string policyClassName)
 {
     if ((this.m_membershipCondition == null) && (this.m_element != null))
     {
         this.ParseMembershipCondition();
     }
     if (this.m_children == null)
     {
         this.ParseChildren();
     }
     if ((this.m_policy == null) && (this.m_element != null))
     {
         this.ParsePolicy();
     }
     SecurityElement element = new SecurityElement("CodeGroup");
     XMLUtil.AddClassAttribute(element, base.GetType(), policyClassName);
     element.AddAttribute("version", "1");
     element.AddChild(this.m_membershipCondition.ToXml(level));
     if (this.m_policy != null)
     {
         PermissionSet permissionSetNoCopy = this.m_policy.GetPermissionSetNoCopy();
         NamedPermissionSet set2 = permissionSetNoCopy as NamedPermissionSet;
         if (((set2 != null) && (level != null)) && (level.GetNamedPermissionSetInternal(set2.Name) != null))
         {
             element.AddAttribute("PermissionSetName", set2.Name);
         }
         else if (!permissionSetNoCopy.IsEmpty())
         {
             element.AddChild(permissionSetNoCopy.ToXml());
         }
         if (this.m_policy.Attributes != PolicyStatementAttribute.Nothing)
         {
             element.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), this.m_policy.Attributes));
         }
     }
     if (this.m_children.Count > 0)
     {
         lock (this)
         {
             IEnumerator enumerator = this.m_children.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 element.AddChild(((CodeGroup) enumerator.Current).ToXml(level));
             }
         }
     }
     if (this.m_name != null)
     {
         element.AddAttribute("Name", SecurityElement.Escape(this.m_name));
     }
     if (this.m_description != null)
     {
         element.AddAttribute("Description", SecurityElement.Escape(this.m_description));
     }
     this.CreateXml(element, level);
     return element;
 }
コード例 #9
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void FromXml( SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly )
        {
            if (doc == null)
                throw new ArgumentNullException( "doc" );
            Contract.EndContractBlock();

            if (!doc.GetTagForElement( position ).Equals( "PolicyStatement" ))
                throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ),  "PolicyStatement", this.GetType().FullName ) );
        
            m_attributes = (PolicyStatementAttribute) 0;

            String strAttributes = doc.GetAttributeForElement( position, "Attributes" );

            if (strAttributes != null)
                m_attributes = (PolicyStatementAttribute)Enum.Parse( typeof( PolicyStatementAttribute ), strAttributes );

            lock (this)
            {
                m_permSet = null;

                if (level != null)
                {
                    String permSetName = doc.GetAttributeForElement( position, "PermissionSetName" );
    
                    if (permSetName != null)
                    {
                        m_permSet = level.GetNamedPermissionSetInternal( permSetName );

                        if (m_permSet == null)
                            m_permSet = new PermissionSet( PermissionState.None );
                    }
                }


                if (m_permSet == null)
                {
                    // There is no provided level, it is not a named permission set, or
                    // the named permission set doesn't exist in the provided level,
                    // so just create the class through reflection and decode normally.
        
                    ArrayList childPositions = doc.GetChildrenPositionForElement( position );
                    int positionPermissionSet = -1;

                    for (int i = 0; i < childPositions.Count; ++i)
                    {
                        if (doc.GetTagForElement( (int)childPositions[i] ).Equals( "PermissionSet" ))
                        {
                            positionPermissionSet = (int)childPositions[i];
                        }
                    }

                    if (positionPermissionSet != -1)
                    {
                        String className = doc.GetAttributeForElement( positionPermissionSet, "class" );

                        if (className != null && (className.Equals( "NamedPermissionSet" ) ||
                                                  className.Equals( "System.Security.NamedPermissionSet" )))
                            m_permSet = new NamedPermissionSet( "DefaultName", PermissionState.None );
                        else
                            m_permSet = new PermissionSet( PermissionState.None );
                
                        m_permSet.FromXml( doc, positionPermissionSet, allowInternalOnly );
                    }
                    else
                    {
                        throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidXML" ) );
                    }
                }

                if (m_permSet == null) 
                    m_permSet = new PermissionSet( PermissionState.None );
            }    
        }
コード例 #10
0
 internal void FromXml(SecurityElement et, PolicyLevel level, bool allowInternalOnly)
 {
     if (et == null)
     {
         throw new ArgumentNullException("et");
     }
     if (!et.Tag.Equals("PolicyStatement"))
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PolicyStatement", base.GetType().FullName }));
     }
     this.m_attributes = PolicyStatementAttribute.Nothing;
     string str = et.Attribute("Attributes");
     if (str != null)
     {
         this.m_attributes = (PolicyStatementAttribute) Enum.Parse(typeof(PolicyStatementAttribute), str);
     }
     lock (this)
     {
         this.m_permSet = null;
         if (level != null)
         {
             string name = et.Attribute("PermissionSetName");
             if (name != null)
             {
                 this.m_permSet = level.GetNamedPermissionSetInternal(name);
                 if (this.m_permSet == null)
                 {
                     this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                 }
             }
         }
         if (this.m_permSet == null)
         {
             SecurityElement element = et.SearchForChildByTag("PermissionSet");
             if (element == null)
             {
                 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
             }
             string str3 = element.Attribute("class");
             if ((str3 != null) && (str3.Equals("NamedPermissionSet") || str3.Equals("System.Security.NamedPermissionSet")))
             {
                 this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
             }
             else
             {
                 this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
             }
             try
             {
                 this.m_permSet.FromXml(element, allowInternalOnly, true);
             }
             catch
             {
             }
         }
         if (this.m_permSet == null)
         {
             this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
         }
     }
 }
コード例 #11
0
        internal void FromXml(SecurityElement et, PolicyLevel level, bool allowInternalOnly)
        {
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (!et.Tag.Equals("PolicyStatement"))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), "PolicyStatement", base.GetType().FullName));
            }
            this.m_attributes = PolicyStatementAttribute.Nothing;
            string text = et.Attribute("Attributes");

            if (text != null)
            {
                this.m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), text);
            }
            lock (this)
            {
                this.m_permSet = null;
                if (level != null)
                {
                    string text2 = et.Attribute("PermissionSetName");
                    if (text2 != null)
                    {
                        this.m_permSet = level.GetNamedPermissionSetInternal(text2);
                        if (this.m_permSet == null)
                        {
                            this.m_permSet = new PermissionSet(PermissionState.None);
                        }
                    }
                }
                if (this.m_permSet == null)
                {
                    SecurityElement securityElement = et.SearchForChildByTag("PermissionSet");
                    if (securityElement != null)
                    {
                        string text3 = securityElement.Attribute("class");
                        if (text3 != null && (text3.Equals("NamedPermissionSet") || text3.Equals("System.Security.NamedPermissionSet")))
                        {
                            this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
                        }
                        else
                        {
                            this.m_permSet = new PermissionSet(PermissionState.None);
                        }
                        try
                        {
                            this.m_permSet.FromXml(securityElement, allowInternalOnly, true);
                            goto IL_14F;
                        }
                        catch
                        {
                            goto IL_14F;
                        }
                    }
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                }
IL_14F:
                if (this.m_permSet == null)
                {
                    this.m_permSet = new PermissionSet(PermissionState.None);
                }
            }
        }
コード例 #12
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void FromXml( SecurityElement et, PolicyLevel level, bool allowInternalOnly )
        {
            if (et == null)
                throw new ArgumentNullException( "et" );

            if (!et.Tag.Equals( "PolicyStatement" ))
                throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ),  "PolicyStatement", this.GetType().FullName ) );
            Contract.EndContractBlock();
        
            m_attributes = (PolicyStatementAttribute) 0;

            String strAttributes = et.Attribute( "Attributes" );

            if (strAttributes != null)
                m_attributes = (PolicyStatementAttribute)Enum.Parse( typeof( PolicyStatementAttribute ), strAttributes );

            lock (this)
            {
                m_permSet = null;

                if (level != null)
                {
                    String permSetName = et.Attribute( "PermissionSetName" );
    
                    if (permSetName != null)
                    {
                        m_permSet = level.GetNamedPermissionSetInternal( permSetName );

                        if (m_permSet == null)
                            m_permSet = new PermissionSet( PermissionState.None );
                    }
                }


                if (m_permSet == null)
                {
                    // There is no provided level, it is not a named permission set, or
                    // the named permission set doesn't exist in the provided level,
                    // so just create the class through reflection and decode normally.
        
                    SecurityElement e = et.SearchForChildByTag( "PermissionSet" );

                    if (e != null)
                    {
                        String className = e.Attribute( "class" );

                        if (className != null && (className.Equals( "NamedPermissionSet" ) ||
                                                  className.Equals( "System.Security.NamedPermissionSet" )))
                            m_permSet = new NamedPermissionSet( "DefaultName", PermissionState.None );
                        else
                            m_permSet = new PermissionSet( PermissionState.None );
                
                        try
                        {
                            m_permSet.FromXml( e, allowInternalOnly, true );
                        }
                        catch
                        {
                            // ignore any exceptions from the decode process.
                            // Note: we go ahead and use the permission set anyway.  This should be safe since
                            // the decode process should never give permission beyond what a proper decode would have
                            // given.
                        }
                    }
                    else
                    {
                        throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidXML" ) );
                    }
                }

                if (m_permSet == null) 
                    m_permSet = new PermissionSet( PermissionState.None );
            }    
        }
コード例 #13
0
        internal void FromXml(SecurityElement et, PolicyLevel level, bool allowInternalOnly)
        {
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (!et.Tag.Equals("PolicyStatement"))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PolicyStatement", base.GetType().FullName }));
            }
            this.m_attributes = PolicyStatementAttribute.Nothing;
            string str = et.Attribute("Attributes");

            if (str != null)
            {
                this.m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), str);
            }
            lock (this)
            {
                this.m_permSet = null;
                if (level != null)
                {
                    string name = et.Attribute("PermissionSetName");
                    if (name != null)
                    {
                        this.m_permSet = level.GetNamedPermissionSetInternal(name);
                        if (this.m_permSet == null)
                        {
                            this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                        }
                    }
                }
                if (this.m_permSet == null)
                {
                    SecurityElement element = et.SearchForChildByTag("PermissionSet");
                    if (element == null)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                    }
                    string str3 = element.Attribute("class");
                    if ((str3 != null) && (str3.Equals("NamedPermissionSet") || str3.Equals("System.Security.NamedPermissionSet")))
                    {
                        this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
                    }
                    else
                    {
                        this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                    }
                    try
                    {
                        this.m_permSet.FromXml(element, allowInternalOnly, true);
                    }
                    catch
                    {
                    }
                }
                if (this.m_permSet == null)
                {
                    this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                }
            }
        }
コード例 #14
0
        /// <include file='doc\CodeGroup.uex' path='docs/doc[@for="CodeGroup.ToXml1"]/*' />
        public SecurityElement ToXml(PolicyLevel level)
        {
            if (m_membershipCondition == null && m_element != null)
            {
                ParseMembershipCondition();
            }

            if (m_children == null)
            {
                ParseChildren();
            }

            if (m_policy == null && m_element != null)
            {
                ParsePolicy();
            }

            SecurityElement e = new SecurityElement("CodeGroup");

            System.Security.Util.XMLUtil.AddClassAttribute(e, this.GetType());
            e.AddAttribute("version", "1");

            e.AddChild(m_membershipCondition.ToXml(level));

            // Grab the inerts of the policy statement's xml and just stick it
            // into the code group xml directly. We do this to hide the policy statement from
            // users in the config file.

            if (m_policy != null)
            {
                PermissionSet      permSet      = m_policy.GetPermissionSetNoCopy();
                NamedPermissionSet namedPermSet = permSet as NamedPermissionSet;

                if (namedPermSet != null && level != null && level.GetNamedPermissionSetInternal(namedPermSet.Name) != null)
                {
                    e.AddAttribute("PermissionSetName", namedPermSet.Name);
                }
                else
                {
                    if (!permSet.IsEmpty())
                    {
                        e.AddChild(permSet.ToXml());
                    }
                }

                if (m_policy.Attributes != PolicyStatementAttribute.Nothing)
                {
                    e.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), m_policy.Attributes));
                }
            }

            if (m_children.Count > 0)
            {
                lock (this)
                {
                    IEnumerator enumerator = m_children.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        e.AddChild(((CodeGroup)enumerator.Current).ToXml(level));
                    }
                }
            }

            if (m_name != null)
            {
                e.AddAttribute("Name", SecurityElement.Escape(m_name));
            }

            if (m_description != null)
            {
                e.AddAttribute("Description", SecurityElement.Escape(m_description));
            }

            CreateXml(e, level);

            return(e);
        }
コード例 #15
0
        internal SecurityElement ToXml( PolicyLevel level, String policyClassName )
        {
            if (m_membershipCondition == null && m_element != null)
                ParseMembershipCondition();
                
            if (m_children == null)
                ParseChildren();
                
            if (m_policy == null && m_element != null)
                ParsePolicy();
        
            SecurityElement e = new SecurityElement( "CodeGroup" );
            System.Security.Util.XMLUtil.AddClassAttribute( e, this.GetType(), policyClassName );
            // If you hit this assert then most likely you are trying to change the name of this class. 
            // This is ok as long as you change the hard coded string above and change the assert below.
            BCLDebug.Assert( this.GetType().FullName.Equals( policyClassName ), "Incorrect class name passed in! Was: " + policyClassName + " Should be " + this.GetType().FullName);
	    
            e.AddAttribute( "version", "1" );

            e.AddChild( m_membershipCondition.ToXml( level ) );

            // Grab the inerts of the policy statement's xml and just stick it
            // into the code group xml directly. We do this to hide the policy statement from
            // users in the config file.
            
            if (m_policy != null)
            {
                PermissionSet permSet = m_policy.GetPermissionSetNoCopy();
                NamedPermissionSet namedPermSet = permSet as NamedPermissionSet;

                if (namedPermSet != null && level != null && level.GetNamedPermissionSetInternal( namedPermSet.Name ) != null)
                {
                    e.AddAttribute( "PermissionSetName", namedPermSet.Name );
                }
                else
                {
                    if (!permSet.IsEmpty())
                        e.AddChild( permSet.ToXml() );
                }

                if (m_policy.Attributes != PolicyStatementAttribute.Nothing)
                    e.AddAttribute( "Attributes", XMLUtil.BitFieldEnumToString( typeof( PolicyStatementAttribute ), m_policy.Attributes ) );
                }
            
                if (m_children.Count > 0)
                {
                    lock (this)
                    {
                        IEnumerator enumerator = m_children.GetEnumerator();
            
                        while (enumerator.MoveNext())
                        {
                            e.AddChild( ((CodeGroup)enumerator.Current).ToXml( level ) );
                        }
                    }
                }

            if (m_name != null)
            {
                e.AddAttribute( "Name", SecurityElement.Escape( m_name ) );
            }

            if (m_description != null)
            {
                e.AddAttribute( "Description", SecurityElement.Escape( m_description ) );
            }

			CreateXml( e, level );
            
            return e;
        }
コード例 #16
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void FromXml(SecurityElement et, PolicyLevel level, bool allowInternalOnly)
        {
            if (et == null)
            {
                throw new ArgumentNullException(nameof(et));
            }

            if (!et.Tag.Equals("PolicyStatement"))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), nameof(PolicyStatement), this.GetType().FullName));
            }
            Contract.EndContractBlock();

            m_attributes = (PolicyStatementAttribute)0;

            String strAttributes = et.Attribute("Attributes");

            if (strAttributes != null)
            {
                m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), strAttributes);
            }

            lock (this)
            {
                m_permSet = null;

                if (level != null)
                {
                    String permSetName = et.Attribute("PermissionSetName");

                    if (permSetName != null)
                    {
                        m_permSet = level.GetNamedPermissionSetInternal(permSetName);

                        if (m_permSet == null)
                        {
                            m_permSet = new PermissionSet(PermissionState.None);
                        }
                    }
                }


                if (m_permSet == null)
                {
                    // There is no provided level, it is not a named permission set, or
                    // the named permission set doesn't exist in the provided level,
                    // so just create the class through reflection and decode normally.

                    SecurityElement e = et.SearchForChildByTag("PermissionSet");

                    if (e != null)
                    {
                        String className = e.Attribute("class");

                        if (className != null && (className.Equals("NamedPermissionSet") ||
                                                  className.Equals("System.Security.NamedPermissionSet")))
                        {
                            m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
                        }
                        else
                        {
                            m_permSet = new PermissionSet(PermissionState.None);
                        }

                        try
                        {
                            m_permSet.FromXml(e, allowInternalOnly, true);
                        }
                        catch
                        {
                            // ignore any exceptions from the decode process.
                            // Note: we go ahead and use the permission set anyway.  This should be safe since
                            // the decode process should never give permission beyond what a proper decode would have
                            // given.
                        }
                    }
                    else
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                    }
                }

                if (m_permSet == null)
                {
                    m_permSet = new PermissionSet(PermissionState.None);
                }
            }
        }
コード例 #17
0
ファイル: codegroup.cs プロジェクト: ArildF/masters
        /// <include file='doc\CodeGroup.uex' path='docs/doc[@for="CodeGroup.ToXml1"]/*' />
        public SecurityElement ToXml( PolicyLevel level )
        {
            if (m_membershipCondition == null && m_element != null)
                ParseMembershipCondition();
                
            if (m_children == null)
                ParseChildren();
                
            if (m_policy == null && m_element != null)
                ParsePolicy();
        
            SecurityElement e = new SecurityElement( "CodeGroup" );
            System.Security.Util.XMLUtil.AddClassAttribute( e, this.GetType() );
            e.AddAttribute( "version", "1" );

            e.AddChild( m_membershipCondition.ToXml( level ) );

            // Grab the inerts of the policy statement's xml and just stick it
            // into the code group xml directly. We do this to hide the policy statement from
            // users in the config file.
            
            if (m_policy != null)
            {
                PermissionSet permSet = m_policy.GetPermissionSetNoCopy();
                NamedPermissionSet namedPermSet = permSet as NamedPermissionSet;

                if (namedPermSet != null && level != null && level.GetNamedPermissionSetInternal( namedPermSet.Name ) != null)
                {
                    e.AddAttribute( "PermissionSetName", namedPermSet.Name );
                }
                else
                {
                    if (!permSet.IsEmpty())
                        e.AddChild( permSet.ToXml() );
                }

                if (m_policy.Attributes != PolicyStatementAttribute.Nothing)
                    e.AddAttribute( "Attributes", XMLUtil.BitFieldEnumToString( typeof( PolicyStatementAttribute ), m_policy.Attributes ) );
                }
            
                if (m_children.Count > 0)
                {
                    lock (this)
                    {
                        IEnumerator enumerator = m_children.GetEnumerator();
            
                        while (enumerator.MoveNext())
                        {
                            e.AddChild( ((CodeGroup)enumerator.Current).ToXml( level ) );
                        }
                    }
                }

            if (m_name != null)
            {
                e.AddAttribute( "Name", SecurityElement.Escape( m_name ) );
            }

            if (m_description != null)
            {
                e.AddAttribute( "Description", SecurityElement.Escape( m_description ) );
            }

			CreateXml( e, level );
            
            return e;
        }
コード例 #18
0
        internal void FromXml(SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly)
        {
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }
            if (!doc.GetTagForElement(position).Equals("PolicyStatement"))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PolicyStatement", base.GetType().FullName }));
            }
            this.m_attributes = PolicyStatementAttribute.Nothing;
            string attributeForElement = doc.GetAttributeForElement(position, "Attributes");

            if (attributeForElement != null)
            {
                this.m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), attributeForElement);
            }
            lock (this)
            {
                this.m_permSet = null;
                if (level != null)
                {
                    string name = doc.GetAttributeForElement(position, "PermissionSetName");
                    if (name != null)
                    {
                        this.m_permSet = level.GetNamedPermissionSetInternal(name);
                        if (this.m_permSet == null)
                        {
                            this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                        }
                    }
                }
                if (this.m_permSet == null)
                {
                    ArrayList childrenPositionForElement = doc.GetChildrenPositionForElement(position);
                    int       num = -1;
                    for (int i = 0; i < childrenPositionForElement.Count; i++)
                    {
                        if (doc.GetTagForElement((int)childrenPositionForElement[i]).Equals("PermissionSet"))
                        {
                            num = (int)childrenPositionForElement[i];
                        }
                    }
                    if (num == -1)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                    }
                    string str3 = doc.GetAttributeForElement(num, "class");
                    if ((str3 != null) && (str3.Equals("NamedPermissionSet") || str3.Equals("System.Security.NamedPermissionSet")))
                    {
                        this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
                    }
                    else
                    {
                        this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                    }
                    this.m_permSet.FromXml(doc, num, allowInternalOnly);
                }
                if (this.m_permSet == null)
                {
                    this.m_permSet = new System.Security.PermissionSet(PermissionState.None);
                }
            }
        }
コード例 #19
0
        internal void FromXml(SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly)
        {
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }

            if (!doc.GetTagForElement(position).Equals("PolicyStatement"))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), "PolicyStatement", this.GetType().FullName));
            }

            m_attributes = (PolicyStatementAttribute)0;

            String strAttributes = doc.GetAttributeForElement(position, "Attributes");

            if (strAttributes != null)
            {
                m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), strAttributes);
            }

            lock (this)
            {
                m_permSet = null;

                if (level != null)
                {
                    String permSetName = doc.GetAttributeForElement(position, "PermissionSetName");

                    if (permSetName != null)
                    {
                        m_permSet = level.GetNamedPermissionSetInternal(permSetName);

                        if (m_permSet == null)
                        {
                            m_permSet = new PermissionSet(PermissionState.None);
                        }
                    }
                }


                if (m_permSet == null)
                {
                    // There is no provided level, it is not a named permission set, or
                    // the named permission set doesn't exist in the provided level,
                    // so just create the class through reflection and decode normally.

                    ArrayList childPositions        = doc.GetChildrenPositionForElement(position);
                    int       positionPermissionSet = -1;

                    for (int i = 0; i < childPositions.Count; ++i)
                    {
                        if (doc.GetTagForElement((int)childPositions[i]).Equals("PermissionSet"))
                        {
                            positionPermissionSet = (int)childPositions[i];
                        }
                    }

                    if (positionPermissionSet != -1)
                    {
                        String className = doc.GetAttributeForElement(positionPermissionSet, "class");

                        if (className != null && (className.Equals("NamedPermissionSet") ||
                                                  className.Equals("System.Security.NamedPermissionSet")))
                        {
                            m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None);
                        }
                        else
                        {
                            m_permSet = new PermissionSet(PermissionState.None);
                        }

                        m_permSet.FromXml(doc, positionPermissionSet, allowInternalOnly);
                    }
                    else
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
                    }
                }

                if (m_permSet == null)
                {
                    m_permSet = new PermissionSet(PermissionState.None);
                }
            }
        }