Beispiel #1
0
        public void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (string.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }
            this.m_appTrustedToRun = false;
            string strA = element.Attribute("TrustedToRun");

            if ((strA != null) && (string.Compare(strA, "true", StringComparison.Ordinal) == 0))
            {
                this.m_appTrustedToRun = true;
            }
            this.m_persist = false;
            string str2 = element.Attribute("Persist");

            if ((str2 != null) && (string.Compare(str2, "true", StringComparison.Ordinal) == 0))
            {
                this.m_persist = true;
            }
            this.m_appId = null;
            string applicationIdentityFullName = element.Attribute("FullName");

            if ((applicationIdentityFullName != null) && (applicationIdentityFullName.Length > 0))
            {
                this.m_appId = new System.ApplicationIdentity(applicationIdentityFullName);
            }
            this.m_psDefaultGrant       = null;
            this.m_grantSetSpecialFlags = 0;
            SecurityElement element2 = element.SearchForChildByTag("DefaultGrant");

            if (element2 != null)
            {
                SecurityElement et = element2.SearchForChildByTag("PolicyStatement");
                if (et != null)
                {
                    PolicyStatement statement = new PolicyStatement(null);
                    statement.FromXml(et);
                    this.m_psDefaultGrant       = statement;
                    this.m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(statement.PermissionSet, null);
                }
            }
            List <StrongName> list     = new List <StrongName>();
            SecurityElement   element4 = element.SearchForChildByTag("FullTrustAssemblies");

            if ((element4 != null) && (element4.InternalChildren != null))
            {
                IEnumerator enumerator = element4.Children.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StrongName item = new StrongName();
                    item.FromXml(enumerator.Current as SecurityElement);
                    list.Add(item);
                }
            }
            this.m_fullTrustAssemblies = list.AsReadOnly();
            this.m_elExtraInfo         = element.SearchForChildByTag("ExtraInfo");
        }
Beispiel #2
0
        public void FromXml (SecurityElement element) {
            if (element == null)
                throw new ArgumentNullException("element"); 
            if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML")); 
 
#if FEATURE_CLICKONCE
            m_appTrustedToRun = false; 
            string isAppTrustedToRun = element.Attribute("TrustedToRun");
            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0) {
                m_appTrustedToRun = true;
            } 

            m_persist = false; 
            string persist = element.Attribute("Persist"); 
            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0) {
                m_persist = true; 
            }

            m_appId = null;
            string fullName = element.Attribute("FullName"); 
            if (fullName != null && fullName.Length > 0) {
                m_appId = new ApplicationIdentity(fullName); 
            } 
#endif // FEATURE_CLICKONCE
 
            m_psDefaultGrant = null;
            m_grantSetSpecialFlags = 0;
            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
            if (elDefaultGrant != null) { 
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null) { 
                    PolicyStatement ps = new PolicyStatement(null); 
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant = ps; 
                    m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(ps.PermissionSet, null);
                }
            }
 
            List<StrongName> fullTrustAssemblies = new List<StrongName>();
            SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies"); 
            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) { 
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                while (enumerator.MoveNext()) { 
                    StrongName fullTrustAssembly = new StrongName();
                    fullTrustAssembly.FromXml(enumerator.Current as SecurityElement);
                    fullTrustAssemblies.Add(fullTrustAssembly);
                } 
            }
 
            m_fullTrustAssemblies = fullTrustAssemblies.AsReadOnly(); 

#if FEATURE_CLICKONCE 
            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
#endif // FEATURE_CLICKONCE
        }
Beispiel #3
0
        /// <summary>从 XML 编码重新构造具有给定状态的 <see cref="T:System.Security.Policy.ApplicationTrust" /> 对象。</summary>
        /// <param name="element">用于重新构造 <see cref="T:System.Security.Policy.ApplicationTrust" /> 对象的 XML 编码。</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="element" /> 为 null。</exception>
        /// <exception cref="T:System.ArgumentException">用于 <paramref name="element" /> 的 XML 编码无效。</exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
        /// </PermissionSet>
        public void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (string.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }
            this.m_appTrustedToRun = false;
            string strA1 = element.Attribute("TrustedToRun");

            if (strA1 != null && string.Compare(strA1, "true", StringComparison.Ordinal) == 0)
            {
                this.m_appTrustedToRun = true;
            }
            this.m_persist = false;
            string strA2 = element.Attribute("Persist");

            if (strA2 != null && string.Compare(strA2, "true", StringComparison.Ordinal) == 0)
            {
                this.m_persist = true;
            }
            this.m_appId = (ApplicationIdentity)null;
            string applicationIdentityFullName = element.Attribute("FullName");

            if (applicationIdentityFullName != null && applicationIdentityFullName.Length > 0)
            {
                this.m_appId = new ApplicationIdentity(applicationIdentityFullName);
            }
            this.m_psDefaultGrant       = (PolicyStatement)null;
            this.m_grantSetSpecialFlags = 0;
            SecurityElement securityElement1 = element.SearchForChildByTag("DefaultGrant");

            if (securityElement1 != null)
            {
                SecurityElement et = securityElement1.SearchForChildByTag("PolicyStatement");
                if (et != null)
                {
                    PolicyStatement policyStatement = new PolicyStatement((PermissionSet)null);
                    policyStatement.FromXml(et);
                    this.m_psDefaultGrant       = policyStatement;
                    this.m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(policyStatement.PermissionSet, (PermissionSet)null);
                }
            }
            List <StrongName> strongNameList   = new List <StrongName>();
            SecurityElement   securityElement2 = element.SearchForChildByTag("FullTrustAssemblies");

            if (securityElement2 != null && securityElement2.InternalChildren != null)
            {
                foreach (object child in securityElement2.Children)
                {
                    StrongName strongName = new StrongName();
                    strongName.FromXml(child as SecurityElement);
                    strongNameList.Add(strongName);
                }
            }
            this.m_fullTrustAssemblies = (IList <StrongName>)strongNameList.AsReadOnly();
            this.m_elExtraInfo         = element.SearchForChildByTag("ExtraInfo");
        }
Beispiel #4
0
        public void FromXml(SecurityElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }

#if FEATURE_CLICKONCE
            m_appTrustedToRun = false;
            string isAppTrustedToRun = element.Attribute("TrustedToRun");
            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0)
            {
                m_appTrustedToRun = true;
            }

            m_persist = false;
            string persist = element.Attribute("Persist");
            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0)
            {
                m_persist = true;
            }

            m_appId = null;
            string fullName = element.Attribute("FullName");
            if (fullName != null && fullName.Length > 0)
            {
                m_appId = new ApplicationIdentity(fullName);
            }
#endif // FEATURE_CLICKONCE

            m_psDefaultGrant       = null;
            m_grantSetSpecialFlags = 0;
            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
            if (elDefaultGrant != null)
            {
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null)
                {
                    PolicyStatement ps = new PolicyStatement(null);
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant       = ps;
                    m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(ps.PermissionSet, null);
                }
            }

            List <StrongName> fullTrustAssemblies   = new List <StrongName>();
            SecurityElement   elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");
            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null)
            {
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StrongName fullTrustAssembly = new StrongName();
                    fullTrustAssembly.FromXml(enumerator.Current as SecurityElement);
                    fullTrustAssemblies.Add(fullTrustAssembly);
                }
            }

            m_fullTrustAssemblies = fullTrustAssemblies.AsReadOnly();

#if FEATURE_CLICKONCE
            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
#endif // FEATURE_CLICKONCE
        }
 public void FromXml(SecurityElement element)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (string.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
     }
     this.m_appTrustedToRun = false;
     string strA = element.Attribute("TrustedToRun");
     if ((strA != null) && (string.Compare(strA, "true", StringComparison.Ordinal) == 0))
     {
         this.m_appTrustedToRun = true;
     }
     this.m_persist = false;
     string str2 = element.Attribute("Persist");
     if ((str2 != null) && (string.Compare(str2, "true", StringComparison.Ordinal) == 0))
     {
         this.m_persist = true;
     }
     this.m_appId = null;
     string applicationIdentityFullName = element.Attribute("FullName");
     if ((applicationIdentityFullName != null) && (applicationIdentityFullName.Length > 0))
     {
         this.m_appId = new System.ApplicationIdentity(applicationIdentityFullName);
     }
     this.m_psDefaultGrant = null;
     this.m_grantSetSpecialFlags = 0;
     SecurityElement element2 = element.SearchForChildByTag("DefaultGrant");
     if (element2 != null)
     {
         SecurityElement et = element2.SearchForChildByTag("PolicyStatement");
         if (et != null)
         {
             PolicyStatement statement = new PolicyStatement(null);
             statement.FromXml(et);
             this.m_psDefaultGrant = statement;
             this.m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(statement.PermissionSet, null);
         }
     }
     List<StrongName> list = new List<StrongName>();
     SecurityElement element4 = element.SearchForChildByTag("FullTrustAssemblies");
     if ((element4 != null) && (element4.InternalChildren != null))
     {
         IEnumerator enumerator = element4.Children.GetEnumerator();
         while (enumerator.MoveNext())
         {
             StrongName item = new StrongName();
             item.FromXml(enumerator.Current as SecurityElement);
             list.Add(item);
         }
     }
     this.m_fullTrustAssemblies = list.AsReadOnly();
     this.m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
 }