public static void PolicyStatementCallMethods() { PolicyStatement ps = new PolicyStatement(new PermissionSet(new PermissionState())); PolicyStatement ps2 = ps.Copy(); bool equals = ps.Equals(ps2); int hash = ps.GetHashCode(); SecurityElement se = new SecurityElement(""); PolicyLevel pl = (PolicyLevel)Activator.CreateInstance(typeof(PolicyLevel), true); ps.FromXml(se); ps.FromXml(se, pl); se = ps.ToXml(); se = ps.ToXml(pl); }
private PolicyStatement CalculatePolicy(String host, String scheme) { // // SecurityElement socketPerm = null; SecurityElement webPerm = CreateWebPermission(host, scheme); // Now build the policy statement SecurityElement root = new SecurityElement("PolicyStatement"); SecurityElement permSet = new SecurityElement("PermissionSet"); permSet.AddAttribute("class", "System.Security.PermissionSet"); permSet.AddAttribute("version", "1"); if (webPerm != null) { permSet.AddChild(webPerm); } if (socketPerm != null) { permSet.AddChild(socketPerm); } root.AddChild(permSet); PolicyStatement policy = new PolicyStatement(); policy.FromXml(root); return(policy); }
internal PolicyStatement CalculatePolicy(string host, string scheme, string port) { SecurityElement child = this.CreateWebPermission(host, scheme, port, null); SecurityElement et = new SecurityElement("PolicyStatement"); SecurityElement element3 = new SecurityElement("PermissionSet"); element3.AddAttribute("class", "System.Security.PermissionSet"); element3.AddAttribute("version", "1"); if (child != null) { element3.AddChild(child); } et.AddChild(element3); PolicyStatement statement = new PolicyStatement(); statement.FromXml(et); return(statement); }
// Token: 0x0600298A RID: 10634 RVA: 0x000993A0 File Offset: 0x000975A0 internal PolicyStatement CalculatePolicy(string host, string scheme, string port) { SecurityElement securityElement = this.CreateWebPermission(host, scheme, port, null); SecurityElement securityElement2 = new SecurityElement("PolicyStatement"); SecurityElement securityElement3 = new SecurityElement("PermissionSet"); securityElement3.AddAttribute("class", "System.Security.PermissionSet"); securityElement3.AddAttribute("version", "1"); if (securityElement != null) { securityElement3.AddChild(securityElement); } securityElement2.AddChild(securityElement3); PolicyStatement policyStatement = new PolicyStatement(); policyStatement.FromXml(securityElement2); return(policyStatement); }
internal PolicyStatement CalculatePolicy(string host, string scheme, string port) { SecurityElement webPermission = this.CreateWebPermission(host, scheme, port, (string)null); SecurityElement securityElement = new SecurityElement("PolicyStatement"); SecurityElement child = new SecurityElement("PermissionSet"); child.AddAttribute("class", "System.Security.PermissionSet"); child.AddAttribute("version", "1"); if (webPermission != null) { child.AddChild(webPermission); } securityElement.AddChild(child); PolicyStatement policyStatement = new PolicyStatement(); SecurityElement et = securityElement; policyStatement.FromXml(et); return(policyStatement); }
private PolicyStatement CalculatePolicy(String host, String scheme, int port) { // Note: this gets a little stupid since the web and socket permissions are // outside of mscorlib we have to load them dynamically, so I do it in // separate functions. // For now we set it null while the Net dudes decide whether // they want socketPerm granted or not. The socket code // currently does nothing with the port. // SecurityElement socketPerm = CreateSocketPermission( host, scheme, port ); SecurityElement socketPerm = null; SecurityElement webPerm = CreateWebPermission(host, scheme, port); // Now build the policy statement SecurityElement root = new SecurityElement("PolicyStatement"); SecurityElement permSet = new SecurityElement("PermissionSet"); permSet.AddAttribute("class", "System.Security.PermissionSet"); permSet.AddAttribute("version", "1"); if (webPerm != null) { permSet.AddChild(webPerm); } if (socketPerm != null) { permSet.AddChild(socketPerm); } root.AddChild(permSet); PolicyStatement policy = new PolicyStatement(); policy.FromXml(root); return(policy); }
internal PolicyStatement CalculatePolicy(String host, String scheme, String port) { SecurityElement webPerm = CreateWebPermission(host, scheme, port); SecurityElement root = new SecurityElement("PolicyStatement"); SecurityElement permSet = new SecurityElement("PermissionSet"); permSet.AddAttribute("class", "System.Security.PermissionSet"); permSet.AddAttribute("version", "1"); if (webPerm != null) { permSet.AddChild(webPerm); } root.AddChild(permSet); PolicyStatement policy = new PolicyStatement(); policy.FromXml(root); return(policy); }
public void FromXml_BadSecurityElement () { PolicyStatement ps = new PolicyStatement (null); ps.FromXml (new SecurityElement ("Bad")); }
private PolicyStatement CalculatePolicy( String host, String scheme ) { // // SecurityElement socketPerm = null; SecurityElement webPerm = CreateWebPermission( host, scheme ); // Now build the policy statement SecurityElement root = new SecurityElement( "PolicyStatement" ); SecurityElement permSet = new SecurityElement( "PermissionSet" ); permSet.AddAttribute( "class", "System.Security.PermissionSet" ); permSet.AddAttribute( "version", "1" ); if (webPerm != null) permSet.AddChild( webPerm ); if (socketPerm != null) permSet.AddChild( socketPerm ); root.AddChild( permSet ); PolicyStatement policy = new PolicyStatement(); policy.FromXml( root ); return policy; }
private PolicyStatement CheckCache(int count, byte[] serializedEvidence) { byte[] buffer; if (this.m_configId == System.Security.Policy.ConfigId.None) { return null; } if (!Config.GetCacheEntry(this.m_configId, count, serializedEvidence, out buffer)) { return null; } PolicyStatement statement = new PolicyStatement(); SecurityDocument doc = new SecurityDocument(buffer); statement.FromXml(doc, 0, null, true); return statement; }
// Token: 0x060028D4 RID: 10452 RVA: 0x00096790 File Offset: 0x00094990 private void ParsePolicy() { for (;;) { PolicyStatement policyStatement = new PolicyStatement(); bool flag = false; SecurityElement securityElement = new SecurityElement("PolicyStatement"); securityElement.AddAttribute("version", "1"); SecurityElement element = this.m_element; lock (this) { if (this.m_element != null) { string text = this.m_element.Attribute("PermissionSetName"); if (text != null) { securityElement.AddAttribute("PermissionSetName", text); flag = true; } else { SecurityElement securityElement2 = this.m_element.SearchForChildByTag("PermissionSet"); if (securityElement2 != null) { securityElement.AddChild(securityElement2); flag = true; } else { securityElement.AddChild(new PermissionSet(false).ToXml()); flag = true; } } string text2 = this.m_element.Attribute("Attributes"); if (text2 != null) { securityElement.AddAttribute("Attributes", text2); flag = true; } } } if (flag) { policyStatement.FromXml(securityElement, this.m_parentLevel); } else { policyStatement.PermissionSet = null; } lock (this) { if (element == this.m_element && this.m_policy == null) { this.m_policy = policyStatement; } else if (this.m_policy == null) { continue; } } break; } if (this.m_policy != null && this.m_children != null) { IMembershipCondition membershipCondition = this.m_membershipCondition; } }
private void ParsePolicy() { // There is a potential deadlock situation here // since the PolicyStatement.FromXml method calls // into PolicyLevel and we are holding this CodeGroup's lock. // We solve this by releasing the lock for the duration of // the FromXml call, but this leads us into some race conditions // with other threads trying to alter the state of this object. // The trickiest of these is the case from FromXml gets called on // this object, in which case we will loop and try the decode again. while (true) { PolicyStatement policy = new PolicyStatement(); bool needToParse = false; SecurityElement elPolicy = new SecurityElement( "PolicyStatement" ); elPolicy.AddAttribute( "version", "1" ); SecurityElement localRef = m_element; lock (this) { // We create an xml representation of a policy statement from the // xml for a code group. We do this to hide the policy statement from // users in the config file. if (m_element != null) { String permSetName = m_element.Attribute( "PermissionSetName" ); if (permSetName != null) { elPolicy.AddAttribute( "PermissionSetName", permSetName ); needToParse = true; } else { SecurityElement elPermSet = m_element.SearchForChildByTag( "PermissionSet" ); if (elPermSet != null) { elPolicy.AddChild( elPermSet ); needToParse = true; } else { elPolicy.AddChild( new PermissionSet( false ).ToXml() ); needToParse = true; } } String attributes = m_element.Attribute( "Attributes" ); if (attributes != null) { elPolicy.AddAttribute( "Attributes", attributes ); needToParse = true; } } } if (needToParse) policy.FromXml( elPolicy, m_parentLevel ); else policy.PermissionSet = null; lock (this) { if (localRef == m_element && m_policy == null) { m_policy = policy; break; } else if (m_policy != null) { break; } } } if (m_policy != null && m_children != null && m_membershipCondition != null) { //m_element = null; //m_parentLevel = null; } }
private PolicyStatement CheckCache( int count, char[] serializedEvidence, out bool xmlError ) { BCLDebug.Assert( m_configId != ConfigId.None, "PolicyLevels must have a valid config id to check the cache" ); char[] cachedValue; PolicyStatement cachedSet = null; xmlError = false; if (!Config.GetCacheEntry( m_configId, count, serializedEvidence, out cachedValue )) { return null; } else { BCLDebug.Assert( cachedValue != null, "GetCacheData returned success but cached value is null" ); cachedSet = new PolicyStatement(); Parser parser = null; try { parser = new Parser( cachedValue ); cachedSet.FromXml( parser.GetTopElement() ); return cachedSet; } catch (XmlSyntaxException) { BCLDebug.Assert( false, "XmlSyntaxException in CheckCache" ); xmlError = true; return null; } } }
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")); } m_psDefaultGrant = null; m_fullTrustAssemblies = null; m_appTrustedToRun = false; string isAppTrustedToRun = element.Attribute("TrustedToRun"); if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0) { m_appTrustedToRun = true; } string persist = element.Attribute("Persist"); if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0) { m_persist = true; } string fullName = element.Attribute("FullName"); if (fullName != null && fullName.Length > 0) { m_appId = new ApplicationIdentity(fullName); } 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; } } SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies"); if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) { m_fullTrustAssemblies = new StrongName[elFullTrustAssemblies.Children.Count]; IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator(); int index = 0; while (enumerator.MoveNext()) { m_fullTrustAssemblies[index] = new StrongName(); m_fullTrustAssemblies[index].FromXml(enumerator.Current as SecurityElement); index++; } } m_elExtraInfo = element.SearchForChildByTag("ExtraInfo"); }
internal PolicyStatement CalculatePolicy(string host, string scheme, string port) { SecurityElement child = this.CreateWebPermission(host, scheme, port, null); SecurityElement et = new SecurityElement("PolicyStatement"); SecurityElement element3 = new SecurityElement("PermissionSet"); element3.AddAttribute("class", "System.Security.PermissionSet"); element3.AddAttribute("version", "1"); if (child != null) { element3.AddChild(child); } et.AddChild(element3); PolicyStatement statement = new PolicyStatement(); statement.FromXml(et); return statement; }
private void ParsePolicy() { label_0: PolicyStatement policyStatement = new PolicyStatement(); bool flag = false; SecurityElement et = new SecurityElement("PolicyStatement"); et.AddAttribute("version", "1"); SecurityElement securityElement = this.m_element; lock (this) { if (this.m_element != null) { string local_6 = this.m_element.Attribute("PermissionSetName"); if (local_6 != null) { et.AddAttribute("PermissionSetName", local_6); flag = true; } else { SecurityElement local_8 = this.m_element.SearchForChildByTag("PermissionSet"); if (local_8 != null) { et.AddChild(local_8); flag = true; } else { et.AddChild(new PermissionSet(false).ToXml()); flag = true; } } string local_7 = this.m_element.Attribute("Attributes"); if (local_7 != null) { et.AddAttribute("Attributes", local_7); flag = true; } } } if (flag) { policyStatement.FromXml(et, this.m_parentLevel); } else { policyStatement.PermissionSet = (PermissionSet)null; } lock (this) { if (securityElement == this.m_element && this.m_policy == null) { this.m_policy = policyStatement; } else if (this.m_policy == null) { goto label_0; } } if (this.m_policy == null || this.m_children == null) { return; } IMembershipCondition membershipCondition = this.m_membershipCondition; }
private void ParsePolicy() { // There is a potential deadlock situation here // since the PolicyStatement.FromXml method calls // into PolicyLevel and we are holding this CodeGroup's lock. // We solve this by releasing the lock for the duration of // the FromXml call, but this leads us into some race conditions // with other threads trying to alter the state of this object. // The trickiest of these is the case from FromXml gets called on // this object, in which case we will loop and try the decode again. while (true) { PolicyStatement policy = new PolicyStatement(); bool needToParse = false; SecurityElement elPolicy = new SecurityElement("PolicyStatement"); elPolicy.AddAttribute("version", "1"); SecurityElement localRef = m_element; lock (this) { // We create an xml representation of a policy statement from the // xml for a code group. We do this to hide the policy statement from // users in the config file. if (m_element != null) { String permSetName = m_element.Attribute("PermissionSetName"); if (permSetName != null) { elPolicy.AddAttribute("PermissionSetName", permSetName); needToParse = true; } else { SecurityElement elPermSet = m_element.SearchForChildByTag("PermissionSet"); if (elPermSet != null) { elPolicy.AddChild(elPermSet); needToParse = true; } else { elPolicy.AddChild(new PermissionSet(false).ToXml()); needToParse = true; } } String attributes = m_element.Attribute("Attributes"); if (attributes != null) { elPolicy.AddAttribute("Attributes", attributes); needToParse = true; } } } if (needToParse) { policy.FromXml(elPolicy, m_parentLevel); } else { policy.PermissionSet = null; } lock (this) { if (localRef == m_element && m_policy == null) { m_policy = policy; break; } else if (m_policy != null) { break; } } } if (m_policy != null && m_children != null && m_membershipCondition != null) { //m_element = null; //m_parentLevel = null; } }
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"); }
[System.Security.SecurityCritical] // auto-generated private PolicyStatement CheckCache (int count, byte[] serializedEvidence) { if (m_configId == ConfigId.None) return null; if (serializedEvidence == null) return null; byte[] cachedValue; if (!Config.GetCacheEntry(m_configId, count, serializedEvidence, out cachedValue)) return null; PolicyStatement cachedSet = new PolicyStatement(); SecurityDocument doc = new SecurityDocument(cachedValue); cachedSet.FromXml(doc, 0, null, true); return cachedSet; }
public void FromXml_SecurityElementNull () { PolicyStatement ps = new PolicyStatement (null); ps.FromXml (null, PolicyLevel.CreateAppDomainLevel ()); }
public void FromXml_Null () { PolicyStatement ps = new PolicyStatement (null); ps.FromXml (null); }
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")); m_psDefaultGrant = null; m_fullTrustAssemblies = null; m_appTrustedToRun = false; string isAppTrustedToRun = element.Attribute("TrustedToRun"); if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0) m_appTrustedToRun = true; string persist = element.Attribute("Persist"); if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0) m_persist = true; string fullName = element.Attribute("FullName"); if (fullName != null && fullName.Length > 0) m_appId = new ApplicationIdentity(fullName); 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; } } SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies"); if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) { m_fullTrustAssemblies = new StrongName[elFullTrustAssemblies.Children.Count]; IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator(); int index = 0; while (enumerator.MoveNext()) { m_fullTrustAssemblies[index] = new StrongName(); m_fullTrustAssemblies[index].FromXml(enumerator.Current as SecurityElement); index++; } } m_elExtraInfo = element.SearchForChildByTag("ExtraInfo"); }
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"); }
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 ToFromXml_PolicyLevelNull () { PolicyStatement ps = new PolicyStatement (null); SecurityElement se = ps.ToXml (null); ps.FromXml (se, null); }
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 ToFromXml_RoundTrip () { PolicyStatement ps1 = new PolicyStatement (Unrestricted, PolicyStatementAttribute.All); SecurityElement se = ps1.ToXml (); PolicyStatement ps2 = new PolicyStatement (null); ps2.FromXml (se, null); Assert.AreEqual (ps1.ToXml ().ToString (), ps2.ToXml ().ToString (), "Xml"); }
internal PolicyStatement CalculatePolicy( String host, String scheme, String port ) { SecurityElement webPerm = CreateWebPermission( host, scheme, port ); SecurityElement root = new SecurityElement( "PolicyStatement" ); SecurityElement permSet = new SecurityElement( "PermissionSet" ); permSet.AddAttribute( "class", "System.Security.PermissionSet" ); permSet.AddAttribute( "version", "1" ); if (webPerm != null) permSet.AddChild( webPerm ); root.AddChild( permSet ); PolicyStatement policy = new PolicyStatement(); policy.FromXml( root ); return policy; }
/// <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"); }