// Methods public override IPermission CreatePermission () { SiteIdentityPermission perm = null; if (this.Unrestricted) perm = new SiteIdentityPermission (PermissionState.Unrestricted); else if (site == null) perm = new SiteIdentityPermission (PermissionState.None); else perm = new SiteIdentityPermission (site); return perm; }
public void PermissionState_None () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); Assert.AreEqual (String.Empty, sip.Site, "Site"); SecurityElement se = sip.ToXml (); // only class and version are present Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes"); Assert.IsNull (se.Children, "Xml-Children"); SiteIdentityPermission copy = (SiteIdentityPermission)sip.Copy (); Assert.IsFalse (Object.ReferenceEquals (sip, copy), "ReferenceEquals"); }
public void PermissionStateUnrestricted () { // In 2.0 Unrestricted are permitted for identity permissions SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.Unrestricted); Assert.AreEqual (String.Empty, sip.Site, "Site"); SecurityElement se = sip.ToXml (); Assert.AreEqual (3, se.Attributes.Count, "Xml-Attributes"); Assert.IsNull (se.Children, "Xml-Children"); SiteIdentityPermission copy = (SiteIdentityPermission)sip.Copy (); Assert.IsFalse (Object.ReferenceEquals (sip, copy), "ReferenceEquals"); // and they aren't equals to None Assert.IsFalse (sip.Equals (new SiteIdentityPermission (PermissionState.None))); }
public override IPermission Copy() { SiteIdentityPermission permission = new SiteIdentityPermission(PermissionState.None) { m_unrestricted = this.m_unrestricted }; if (this.m_sites != null) { permission.m_sites = new SiteString[this.m_sites.Length]; for (int i = 0; i < this.m_sites.Length; i++) { permission.m_sites[i] = this.m_sites[i].Copy(); } } return permission; }
//------------------------------------------------------ // // PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS // //------------------------------------------------------ //------------------------------------------------------ // // CODEACCESSPERMISSION IMPLEMENTATION // //------------------------------------------------------ //------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ public override IPermission Copy() { SiteIdentityPermission perm = new SiteIdentityPermission(PermissionState.None); perm.m_unrestricted = this.m_unrestricted; if (this.m_sites != null) { perm.m_sites = new SiteString[this.m_sites.Length]; int n; for (n = 0; n < this.m_sites.Length; n++) { perm.m_sites[n] = (SiteString)this.m_sites[n].Copy(); } } return(perm); }
public override IPermission Intersect(IPermission target) { SiteIdentityPermission sip = Cast(target); if ((sip == null) || (IsEmpty())) { return(null); } if (Match(sip._site)) { string s = ((_site.Length > sip._site.Length) ? _site : sip._site); return(new SiteIdentityPermission(s)); } return(null); }
private SiteIdentityPermission Cast(IPermission target) { if (target == null) { return(null); } SiteIdentityPermission sip = (target as SiteIdentityPermission); if (sip == null) { ThrowInvalidPermission(target, typeof(SiteIdentityPermission)); } return(sip); }
/// <summary>Determines whether the current permission is a subset of the specified permission.</summary> /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param> /// <returns> /// <see langword="true" /> if the current permission is a subset of the specified permission; otherwise, <see langword="false" />.</returns> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception> // Token: 0x0600262C RID: 9772 RVA: 0x00089B24 File Offset: 0x00087D24 public override bool IsSubsetOf(IPermission target) { if (target == null) { return(!this.m_unrestricted && (this.m_sites == null || this.m_sites.Length == 0)); } SiteIdentityPermission siteIdentityPermission = target as SiteIdentityPermission; if (siteIdentityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (siteIdentityPermission.m_unrestricted) { return(true); } if (this.m_unrestricted) { return(false); } if (this.m_sites != null) { foreach (SiteString siteString in this.m_sites) { bool flag = false; if (siteIdentityPermission.m_sites != null) { foreach (SiteString operand in siteIdentityPermission.m_sites) { if (siteString.IsSubsetOf(operand)) { flag = true; break; } } } if (!flag) { return(false); } } } return(true); }
public override IPermission Copy() { SiteIdentityPermission permission = new SiteIdentityPermission(PermissionState.None) { m_unrestricted = this.m_unrestricted }; if (this.m_sites != null) { permission.m_sites = new SiteString[this.m_sites.Length]; for (int i = 0; i < this.m_sites.Length; i++) { permission.m_sites[i] = this.m_sites[i].Copy(); } } return(permission); }
/// <summary>Creates and returns a new instance of <see cref="T:System.Security.Permissions.SiteIdentityPermission" />.</summary> /// <returns>A <see cref="T:System.Security.Permissions.SiteIdentityPermission" /> that corresponds to this attribute.</returns> public override IPermission CreatePermission() { SiteIdentityPermission result; if (base.Unrestricted) { result = new SiteIdentityPermission(PermissionState.Unrestricted); } else if (this.site == null) { result = new SiteIdentityPermission(PermissionState.None); } else { result = new SiteIdentityPermission(this.site); } return(result); }
// Methods public override IPermission CreatePermission() { SiteIdentityPermission perm = null; if (this.Unrestricted) { perm = new SiteIdentityPermission(PermissionState.Unrestricted); } else if (site == null) { perm = new SiteIdentityPermission(PermissionState.None); } else { perm = new SiteIdentityPermission(site); } return(perm); }
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary> /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns> /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. -or-The permissions are not equal and one is not a subset of the other.</exception> public override IPermission Union(IPermission target) { SiteIdentityPermission siteIdentityPermission = this.Cast(target); if (siteIdentityPermission == null || siteIdentityPermission.IsEmpty()) { return(this.Copy()); } if (this.IsEmpty()) { return(siteIdentityPermission.Copy()); } if (this.Match(siteIdentityPermission._site)) { string site = (this._site.Length >= siteIdentityPermission._site.Length) ? siteIdentityPermission._site : this._site; return(new SiteIdentityPermission(site)); } throw new ArgumentException(Locale.GetText("Cannot union two different sites."), "target"); }
public override IPermission Union(IPermission target) { SiteIdentityPermission sip = Cast(target); if ((sip == null) || sip.IsEmpty()) { return(Copy()); } if (IsEmpty()) { return(sip.Copy()); } if (Match(sip._site)) { string s = ((_site.Length < sip._site.Length) ? _site : sip._site); return(new SiteIdentityPermission(s)); } throw new ArgumentException(Locale.GetText( "Cannot union two different sites."), "target"); }
/// <summary>Determines whether the current permission is a subset of the specified permission.</summary> /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns> /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception> public override bool IsSubsetOf(IPermission target) { SiteIdentityPermission siteIdentityPermission = this.Cast(target); if (siteIdentityPermission == null) { return(this.IsEmpty()); } if (this._site == null && siteIdentityPermission._site == null) { return(true); } if (this._site == null || siteIdentityPermission._site == null) { return(false); } int num = siteIdentityPermission._site.IndexOf('*'); if (num == -1) { return(this._site == siteIdentityPermission._site); } return(this._site.EndsWith(siteIdentityPermission._site.Substring(num + 1))); }
public void FromXml_WrongTagCase () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); SecurityElement se = sip.ToXml (); se.Tag = "IPERMISSION"; // instead of IPermission sip.FromXml (se); }
public void FromXml_WrongTag () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); SecurityElement se = sip.ToXml (); se.Tag = "IMono"; sip.FromXml (se); }
public void FromXml_Null () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); sip.FromXml (null); }
public void Union_Different_Site () { SiteIdentityPermission sip1 = new SiteIdentityPermission (GoodSites [0]); SiteIdentityPermission sip2 = new SiteIdentityPermission (GoodSites [1]); SiteIdentityPermission result = (SiteIdentityPermission)sip1.Union (sip2); // it's not possible to return many sites using the Site property so it throws Assert.IsNull (result.Site); }
public void Union_Different () { SiteIdentityPermission sip1 = new SiteIdentityPermission (GoodSites [0]); SiteIdentityPermission sip2 = new SiteIdentityPermission (GoodSites [1]); SiteIdentityPermission result = (SiteIdentityPermission)sip1.Union (sip2); Assert.IsNotNull (result, "Mono U Novell"); // new XML format is used to contain more than one site SecurityElement se = result.ToXml (); Assert.AreEqual (2, se.Children.Count, "Childs"); Assert.AreEqual ((se.Children [0] as SecurityElement).Attribute ("Site"), sip1.Site, "Site#1"); Assert.AreEqual ((se.Children [1] as SecurityElement).Attribute ("Site"), sip2.Site, "Site#2"); // strangely it is still versioned as 'version="1"'. Assert.AreEqual ("1", se.Attribute ("version"), "Version"); }
public void Intersect_Different () { SiteIdentityPermission sip1 = new SiteIdentityPermission (GoodSites [0]); SiteIdentityPermission sip2 = new SiteIdentityPermission (GoodSites [1]); SiteIdentityPermission result = (SiteIdentityPermission)sip1.Intersect (sip2); Assert.IsNull (result, "Mono N Novell"); }
public void FromXml_WrongVersion () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); SecurityElement se = sip.ToXml (); se.Attributes.Remove ("version"); se.Attributes.Add ("version", "2"); sip.FromXml (se); }
public override IPermission Union(IPermission target) { if (target == null) { if (((this.m_sites == null) || (this.m_sites.Length == 0)) && !this.m_unrestricted) { return(null); } return(this.Copy()); } SiteIdentityPermission permission = target as SiteIdentityPermission; if (permission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.m_unrestricted || permission.m_unrestricted) { return(new SiteIdentityPermission(PermissionState.None) { m_unrestricted = true }); } if ((this.m_sites == null) || (this.m_sites.Length == 0)) { if ((permission.m_sites != null) && (permission.m_sites.Length != 0)) { return(permission.Copy()); } return(null); } if ((permission.m_sites == null) || (permission.m_sites.Length == 0)) { return(this.Copy()); } List <SiteString> list = new List <SiteString>(); foreach (SiteString str in this.m_sites) { list.Add(str); } foreach (SiteString str2 in permission.m_sites) { bool flag = false; foreach (SiteString str3 in list) { if (str2.Equals(str3)) { flag = true; break; } } if (!flag) { list.Add(str2); } } return(new SiteIdentityPermission(PermissionState.None) { m_sites = list.ToArray() }); }
public void Intersect_Null () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); // No intersection with null foreach (string s in GoodSites) { sip.Site = s; Assert.IsNull (sip.Intersect (null), s); } }
public void Intersect_None () { SiteIdentityPermission sip1 = new SiteIdentityPermission (PermissionState.None); SiteIdentityPermission sip2 = new SiteIdentityPermission (PermissionState.None); SiteIdentityPermission result = (SiteIdentityPermission)sip1.Intersect (sip2); Assert.IsNull (result, "None N None"); foreach (string s in GoodSites) { sip1.Site = s; // 1. Intersect None with site result = (SiteIdentityPermission)sip1.Intersect (sip2); Assert.IsNull (result, "None N " + s); // 2. Intersect site with None result = (SiteIdentityPermission)sip2.Intersect (sip1); Assert.IsNull (result, s + "N None"); } }
public void PermissionState_Bad () { SiteIdentityPermission sip = new SiteIdentityPermission ((PermissionState)Int32.MinValue); }
public void IsSubset_None () { // IsSubset with none // a. source (this) is none -> target is never a subset SiteIdentityPermission sip1 = new SiteIdentityPermission (PermissionState.None); SiteIdentityPermission sip2 = new SiteIdentityPermission (PermissionState.None); foreach (string s in GoodSites) { sip1.Site = s; Assert.IsFalse (sip1.IsSubsetOf (sip2), "target " + s); } sip1 = new SiteIdentityPermission (PermissionState.None); // b. destination (target) is none -> target is always a subset foreach (string s in GoodSites) { sip2.Site = s; Assert.IsFalse (sip2.IsSubsetOf (sip1), "source " + s); } }
public void IsSubset_Null () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); Assert.IsTrue (sip.IsSubsetOf (null), "Empty"); foreach (string s in GoodSites) { sip.Site = s; Assert.IsFalse (sip.IsSubsetOf (null), s); } }
public void FromXml_WrongClass () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); SecurityElement se = sip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", "Wrong" + se.Attribute ("class")); w.AddAttribute ("version", se.Attribute ("version")); sip.FromXml (w); // doesn't care of the class name at that stage // anyway the class has already be created so... }
public void FromXml_NoClass () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); SecurityElement se = sip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("version", se.Attribute ("version")); sip.FromXml (w); // doesn't even care of the class attribute presence }
public override IPermission Intersect(IPermission target) { if (target == null) return null; SiteIdentityPermission that = target as SiteIdentityPermission; if(that == null) throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); if(this.m_unrestricted && that.m_unrestricted) { SiteIdentityPermission res = new SiteIdentityPermission(PermissionState.None); res.m_unrestricted = true; return res; } if(this.m_unrestricted) return that.Copy(); if(that.m_unrestricted) return this.Copy(); if(this.m_sites == null || that.m_sites == null || this.m_sites.Length == 0 || that.m_sites.Length == 0) return null; List<SiteString> alSites = new List<SiteString>(); foreach(SiteString ssThis in this.m_sites) { foreach(SiteString ssThat in that.m_sites) { SiteString ssInt = (SiteString)ssThis.Intersect(ssThat); if(ssInt != null) alSites.Add(ssInt); } } if(alSites.Count == 0) return null; SiteIdentityPermission result = new SiteIdentityPermission(PermissionState.None); result.m_sites = alSites.ToArray(); return result; }
public void FromXml_NoVersion () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); SecurityElement se = sip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", se.Attribute ("class")); sip.FromXml (w); }
public void Intersect_Self () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); foreach (string s in GoodSites) { sip.Site = s; SiteIdentityPermission result = (SiteIdentityPermission)sip.Intersect (sip); Assert.AreEqual (s, result.Site, s); } }
public void IsSubset_Self () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); Assert.IsTrue (sip.IsSubsetOf (sip), "None"); foreach (string s in GoodSites) { sip.Site = s; Assert.IsTrue (sip.IsSubsetOf (sip), s); } }
/// <internalonly/> int IBuiltInPermission.GetTokenIndex() { return(SiteIdentityPermission.GetTokenIndex()); }
public void SiteIdentityPermission_NullSite () { SiteIdentityPermission sip = new SiteIdentityPermission (null); }
public void IsSubset_Different () { SiteIdentityPermission sip1 = new SiteIdentityPermission (GoodSites [0]); SiteIdentityPermission sip2 = new SiteIdentityPermission (GoodSites [1]); Assert.IsFalse (sip1.IsSubsetOf (sip2), "Mono subset Novell"); Assert.IsFalse (sip2.IsSubsetOf (sip1), "Novell subset Mono"); }
/// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary> /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns> /// <param name="target">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -这两个权限不相等,而且其中一个不是另一个的子集。</exception> public override IPermission Union(IPermission target) { if (target == null) { if ((this.m_sites == null || this.m_sites.Length == 0) && !this.m_unrestricted) { return((IPermission)null); } return(this.Copy()); } SiteIdentityPermission identityPermission = target as SiteIdentityPermission; if (identityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (this.m_unrestricted || identityPermission.m_unrestricted) { return (IPermission) new SiteIdentityPermission(PermissionState.None) { m_unrestricted = true } } ; if (this.m_sites == null || this.m_sites.Length == 0) { if (identityPermission.m_sites == null || identityPermission.m_sites.Length == 0) { return((IPermission)null); } return(identityPermission.Copy()); } if (identityPermission.m_sites == null || identityPermission.m_sites.Length == 0) { return(this.Copy()); } List <SiteString> siteStringList = new List <SiteString>(); foreach (SiteString mSite in this.m_sites) { siteStringList.Add(mSite); } foreach (SiteString mSite in identityPermission.m_sites) { bool flag = false; foreach (SiteString siteString in siteStringList) { if (mSite.Equals((object)siteString)) { flag = true; break; } } if (!flag) { siteStringList.Add(mSite); } } return((IPermission) new SiteIdentityPermission(PermissionState.None) { m_sites = siteStringList.ToArray() }); }
public void IsSubset_Wildcard () { SiteIdentityPermission sip1 = new SiteIdentityPermission (GoodSites [0]); SiteIdentityPermission sip2 = new SiteIdentityPermission ("*.mono-project.com"); Assert.IsTrue (sip1.IsSubsetOf (sip2), "www.mono-project.com subset *.mono-project.com"); Assert.IsFalse (sip2.IsSubsetOf (sip1), "*.mono-project.com subset www.mono-project.com"); }
public override IPermission Union(IPermission target) { if (target == null) { if ((this.m_sites == null || this.m_sites.Length == 0) && !this.m_unrestricted) { return(null); } return(this.Copy()); } SiteIdentityPermission that = target as SiteIdentityPermission; if (that == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (this.m_unrestricted || that.m_unrestricted) { SiteIdentityPermission res = new SiteIdentityPermission(PermissionState.None); res.m_unrestricted = true; return(res); } if (this.m_sites == null || this.m_sites.Length == 0) { if (that.m_sites == null || that.m_sites.Length == 0) { return(null); } return(that.Copy()); } if (that.m_sites == null || that.m_sites.Length == 0) { return(this.Copy()); } List <SiteString> alSites = new List <SiteString>(); foreach (SiteString ssThis in this.m_sites) { alSites.Add(ssThis); } foreach (SiteString ssThat in that.m_sites) { bool bDupe = false; foreach (SiteString ss in alSites) { if (ssThat.Equals(ss)) { bDupe = true; break; } } if (!bDupe) { alSites.Add(ssThat); } } SiteIdentityPermission result = new SiteIdentityPermission(PermissionState.None); result.m_sites = alSites.ToArray(); return(result); }
public void Union_Null () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); // Union with null is a simple copy foreach (string s in GoodSites) { sip.Site = s; SiteIdentityPermission union = (SiteIdentityPermission)sip.Union (null); Assert.AreEqual (s, union.Site, s); } }
//------------------------------------------------------ // // PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS // //------------------------------------------------------ //----------------------------------------------------- // // CODEACCESSPERMISSION IMPLEMENTATION // //------------------------------------------------------ //----------------------------------------------------- // // IPERMISSION IMPLEMENTATION // //----------------------------------------------------- public override IPermission Copy() { SiteIdentityPermission perm = new SiteIdentityPermission( PermissionState.None ); perm.m_unrestricted = this.m_unrestricted; if (this.m_sites != null) { perm.m_sites = new SiteString[this.m_sites.Length]; int n; for(n = 0; n < this.m_sites.Length; n++) perm.m_sites[n] = (SiteString)this.m_sites[n].Copy(); } return perm; }
public void Union_None () { // Union with none is same SiteIdentityPermission sip1 = new SiteIdentityPermission (PermissionState.None); SiteIdentityPermission sip2 = new SiteIdentityPermission (PermissionState.None); // a. source (this) is none foreach (string s in GoodSites) { sip1.Site = s; SiteIdentityPermission union = (SiteIdentityPermission)sip1.Union (sip2); Assert.AreEqual (s, union.Site, s); } sip1 = new SiteIdentityPermission (PermissionState.None); // b. destination (target) is none foreach (string s in GoodSites) { sip2.Site = s; SiteIdentityPermission union = (SiteIdentityPermission)sip2.Union (sip1); Assert.AreEqual (s, union.Site, s); } }
public override IPermission Union(IPermission target) { if (target == null) { if((this.m_sites == null || this.m_sites.Length == 0) && !this.m_unrestricted) return null; return this.Copy(); } SiteIdentityPermission that = target as SiteIdentityPermission; if(that == null) throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); if(this.m_unrestricted || that.m_unrestricted) { SiteIdentityPermission res = new SiteIdentityPermission(PermissionState.None); res.m_unrestricted = true; return res; } if (this.m_sites == null || this.m_sites.Length == 0) { if(that.m_sites == null || that.m_sites.Length == 0) return null; return that.Copy(); } if(that.m_sites == null || that.m_sites.Length == 0) return this.Copy(); List<SiteString> alSites = new List<SiteString>(); foreach(SiteString ssThis in this.m_sites) alSites.Add(ssThis); foreach(SiteString ssThat in that.m_sites) { bool bDupe = false; foreach(SiteString ss in alSites) { if(ssThat.Equals(ss)) { bDupe = true; break; } } if(!bDupe) alSites.Add(ssThat); } SiteIdentityPermission result = new SiteIdentityPermission(PermissionState.None); result.m_sites = alSites.ToArray(); return result; }
public void Union_Self () { SiteIdentityPermission sip = new SiteIdentityPermission (PermissionState.None); SiteIdentityPermission union = (SiteIdentityPermission)sip.Union (sip); Assert.IsNull (union, "None U None"); }