public override bool IsSubsetOf(IPermission target) { UrlIdentityPermission uip = Cast(target); if (uip == null) { return(IsEmpty()); } if (IsEmpty()) { return(true); } if (uip.url == null) { return(false); } // here Match wouldn't work as it is bidirectional int wildcard = uip.url.LastIndexOf('*'); if (wildcard == -1) { wildcard = uip.url.Length; // exact match } return(String.Compare(url, 0, uip.url, 0, wildcard, true, CultureInfo.InvariantCulture) == 0); }
/// <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 <see cref="P:System.Security.Permissions.UrlIdentityPermission.Url" /> property is not a valid URL.-or-The two permissions are not equal and one is not a subset of the other.</exception> public override IPermission Union(IPermission target) { UrlIdentityPermission urlIdentityPermission = this.Cast(target); if (urlIdentityPermission == null) { return(this.Copy()); } if (this.IsEmpty() && urlIdentityPermission.IsEmpty()) { return(null); } if (urlIdentityPermission.IsEmpty()) { return(this.Copy()); } if (this.IsEmpty()) { return(urlIdentityPermission.Copy()); } if (!this.Match(urlIdentityPermission.url)) { throw new ArgumentException(Locale.GetText("Cannot union two different urls."), "target"); } if (this.url.Length < urlIdentityPermission.url.Length) { return(this.Copy()); } return(urlIdentityPermission.Copy()); }
/// <include file='doc\URLIdentityPermission.uex' path='docs/doc[@for="UrlIdentityPermission.IsSubsetOf"]/*' /> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.m_url == null); } try { UrlIdentityPermission operand = (UrlIdentityPermission)target; if (this.m_url == null) { return(true); } return(this.m_url.IsSubsetOf(operand.m_url)); } catch (InvalidCastException) { throw new ArgumentException( String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName) ); } }
public override IPermission Union(IPermission target) { UrlIdentityPermission uip = Cast(target); if (uip == null) { return(Copy()); } if (IsEmpty() && uip.IsEmpty()) { return(null); } if (uip.IsEmpty()) { return(Copy()); } if (IsEmpty()) { return(uip.Copy()); } if (Match(uip.url)) { // shortest form is the union if (url.Length < uip.url.Length) { return(Copy()); } else { return(uip.Copy()); } } throw new ArgumentException(Locale.GetText( "Cannot union two different urls."), "target"); }
/// <include file='doc\URLIdentityPermission.uex' path='docs/doc[@for="UrlIdentityPermission.Intersect"]/*' /> public override IPermission Intersect(IPermission target) { if (target == null || this.m_url == null) { return(null); } else if (!VerifyType(target)) { throw new ArgumentException( String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName) ); } UrlIdentityPermission operand = (UrlIdentityPermission)target; if (operand.m_url == null || this.m_url == null) { return(null); } URLString url = (URLString)this.m_url.Intersect(operand.m_url); if (url == null) { return(null); } else { return(new UrlIdentityPermission(url)); } }
/// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary> /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param> /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is <see langword="null" /> if the intersection is empty.</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. -or-The Url property is not a valid URL.</exception> // Token: 0x06002671 RID: 9841 RVA: 0x0008B318 File Offset: 0x00089518 public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } UrlIdentityPermission urlIdentityPermission = target as UrlIdentityPermission; if (urlIdentityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.m_unrestricted && urlIdentityPermission.m_unrestricted) { return(new UrlIdentityPermission(PermissionState.None) { m_unrestricted = true }); } if (this.m_unrestricted) { return(urlIdentityPermission.Copy()); } if (urlIdentityPermission.m_unrestricted) { return(this.Copy()); } if (this.m_urls == null || urlIdentityPermission.m_urls == null || this.m_urls.Length == 0 || urlIdentityPermission.m_urls.Length == 0) { return(null); } List <URLString> list = new List <URLString>(); foreach (URLString urlstring in this.m_urls) { foreach (URLString operand in urlIdentityPermission.m_urls) { URLString urlstring2 = (URLString)urlstring.Intersect(operand); if (urlstring2 != null) { list.Add(urlstring2); } } } if (list.Count == 0) { return(null); } return(new UrlIdentityPermission(PermissionState.None) { m_urls = list.ToArray() }); }
public override bool IsSubsetOf(IPermission target) { if (target == null) { if (m_unrestricted) { return(false); } if (m_urls == null) { return(true); } if (m_urls.Length == 0) { return(true); } return(false); } UrlIdentityPermission that = target as UrlIdentityPermission; if (that == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (that.m_unrestricted) { return(true); } if (m_unrestricted) { return(false); } if (this.m_urls != null) { foreach (URLString usThis in this.m_urls) { bool bOK = false; if (that.m_urls != null) { foreach (URLString usThat in that.m_urls) { if (usThis.IsSubsetOf(usThat)) { bOK = true; break; } } } if (!bOK) { return(false); } } } return(true); }
public override bool IsSubsetOf(IPermission target) { if (target == null) { if (!this.m_unrestricted) { if (this.m_urls == null) { return(true); } if (this.m_urls.Length == 0) { return(true); } } return(false); } UrlIdentityPermission permission = target as UrlIdentityPermission; if (permission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (!permission.m_unrestricted) { if (this.m_unrestricted) { return(false); } if (this.m_urls != null) { foreach (URLString str in this.m_urls) { bool flag = false; if (permission.m_urls != null) { foreach (URLString str2 in permission.m_urls) { if (str.IsSubsetOf(str2)) { flag = true; break; } } } if (!flag) { return(false); } } } } return(true); }
/// <summary>创建并返回一个权限,该权限是当前权限和指定权限的交集。</summary> /// <returns>一个新权限,它表示当前权限与指定权限的交集。如果交集为空,则此新权限为 null。</returns> /// <param name="target">要与当前权限相交的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -Url 属性不是有效的 URL。</exception> public override IPermission Intersect(IPermission target) { if (target == null) { return((IPermission)null); } UrlIdentityPermission identityPermission = target as UrlIdentityPermission; if (identityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (this.m_unrestricted && identityPermission.m_unrestricted) { return (IPermission) new UrlIdentityPermission(PermissionState.None) { m_unrestricted = true } } ; if (this.m_unrestricted) { return(identityPermission.Copy()); } if (identityPermission.m_unrestricted) { return(this.Copy()); } if (this.m_urls == null || identityPermission.m_urls == null || (this.m_urls.Length == 0 || identityPermission.m_urls.Length == 0)) { return((IPermission)null); } List <URLString> urlStringList = new List <URLString>(); foreach (URLString mUrl1 in this.m_urls) { foreach (URLString mUrl2 in identityPermission.m_urls) { URLString urlString = (URLString)mUrl1.Intersect((SiteString)mUrl2); if (urlString != null) { urlStringList.Add(urlString); } } } if (urlStringList.Count == 0) { return((IPermission)null); } return((IPermission) new UrlIdentityPermission(PermissionState.None) { m_urls = urlStringList.ToArray() }); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } UrlIdentityPermission permission = target as UrlIdentityPermission; if (permission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.m_unrestricted && permission.m_unrestricted) { return(new UrlIdentityPermission(PermissionState.None) { m_unrestricted = true }); } if (this.m_unrestricted) { return(permission.Copy()); } if (permission.m_unrestricted) { return(this.Copy()); } if (((this.m_urls == null) || (permission.m_urls == null)) || ((this.m_urls.Length == 0) || (permission.m_urls.Length == 0))) { return(null); } List <URLString> list = new List <URLString>(); foreach (URLString str in this.m_urls) { foreach (URLString str2 in permission.m_urls) { URLString item = (URLString)str.Intersect(str2); if (item != null) { list.Add(item); } } } if (list.Count == 0) { return(null); } return(new UrlIdentityPermission(PermissionState.None) { m_urls = list.ToArray() }); }
public void PermissionState_None () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); // that cause a NullReferenceException before 2.0 Assert.AreEqual (String.Empty, uip.Url, "Url"); SecurityElement se = uip.ToXml (); // only class and version are present Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes"); Assert.IsNull (se.Children, "Xml-Children"); UrlIdentityPermission copy = (UrlIdentityPermission)uip.Copy (); Assert.IsFalse (Object.ReferenceEquals (uip, copy), "ReferenceEquals"); }
public void PermissionStateUnrestricted () { // In 2.0 Unrestricted are permitted for identity permissions UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.Unrestricted); Assert.AreEqual (String.Empty, uip.Url, "Url"); SecurityElement se = uip.ToXml (); // only class and version are present Assert.AreEqual (3, se.Attributes.Count, "Xml-Attributes"); Assert.IsNull (se.Children, "Xml-Children"); // and they aren't equals to None Assert.IsFalse (uip.Equals (new UrlIdentityPermission (PermissionState.None))); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } UrlIdentityPermission that = target as UrlIdentityPermission; if (that == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (this.m_unrestricted && that.m_unrestricted) { UrlIdentityPermission res = new UrlIdentityPermission(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_urls == null || that.m_urls == null || this.m_urls.Length == 0 || that.m_urls.Length == 0) { return(null); } List <URLString> alUrls = new List <URLString>(); foreach (URLString usThis in this.m_urls) { foreach (URLString usThat in that.m_urls) { URLString usInt = (URLString)usThis.Intersect(usThat); if (usInt != null) { alUrls.Add(usInt); } } } if (alUrls.Count == 0) { return(null); } UrlIdentityPermission result = new UrlIdentityPermission(PermissionState.None); result.m_urls = alUrls.ToArray(); return(result); }
private UrlIdentityPermission Cast(IPermission target) { if (target == null) { return(null); } UrlIdentityPermission urlIdentityPermission = target as UrlIdentityPermission; if (urlIdentityPermission == null) { CodeAccessPermission.ThrowInvalidPermission(target, typeof(UrlIdentityPermission)); } return(urlIdentityPermission); }
/// <summary>创建并返回当前权限的相同副本。</summary> /// <returns>当前权限的副本。</returns> public override IPermission Copy() { UrlIdentityPermission identityPermission = new UrlIdentityPermission(PermissionState.None); identityPermission.m_unrestricted = this.m_unrestricted; if (this.m_urls != null) { identityPermission.m_urls = new URLString[this.m_urls.Length]; for (int index = 0; index < this.m_urls.Length; ++index) { identityPermission.m_urls[index] = (URLString)this.m_urls[index].Copy(); } } return((IPermission)identityPermission); }
/// <summary>Creates and returns an identical copy of the current permission.</summary> /// <returns>A copy of the current permission.</returns> // Token: 0x0600266F RID: 9839 RVA: 0x0008B1D4 File Offset: 0x000893D4 public override IPermission Copy() { UrlIdentityPermission urlIdentityPermission = new UrlIdentityPermission(PermissionState.None); urlIdentityPermission.m_unrestricted = this.m_unrestricted; if (this.m_urls != null) { urlIdentityPermission.m_urls = new URLString[this.m_urls.Length]; for (int i = 0; i < this.m_urls.Length; i++) { urlIdentityPermission.m_urls[i] = (URLString)this.m_urls[i].Copy(); } } return(urlIdentityPermission); }
public override IPermission Copy() { UrlIdentityPermission permission = new UrlIdentityPermission(PermissionState.None) { m_unrestricted = this.m_unrestricted }; if (this.m_urls != null) { permission.m_urls = new URLString[this.m_urls.Length]; for (int i = 0; i < this.m_urls.Length; i++) { permission.m_urls[i] = (URLString) this.m_urls[i].Copy(); } } return permission; }
//------------------------------------------------------ // // PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS // //------------------------------------------------------ //------------------------------------------------------ // // CODEACCESSPERMISSION IMPLEMENTATION // //------------------------------------------------------ //------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ public override IPermission Copy() { UrlIdentityPermission perm = new UrlIdentityPermission(PermissionState.None); perm.m_unrestricted = this.m_unrestricted; if (this.m_urls != null) { perm.m_urls = new URLString[this.m_urls.Length]; int n; for (n = 0; n < this.m_urls.Length; n++) { perm.m_urls[n] = (URLString)this.m_urls[n].Copy(); } } return(perm); }
private UrlIdentityPermission Cast(IPermission target) { if (target == null) { return(null); } UrlIdentityPermission uip = (target as UrlIdentityPermission); if (uip == null) { ThrowInvalidPermission(target, typeof(UrlIdentityPermission)); } return(uip); }
/// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary> /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns> /// <param name="target">A permission to intersect 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 Url property is not a valid URL.</exception> public override IPermission Intersect(IPermission target) { UrlIdentityPermission urlIdentityPermission = this.Cast(target); if (urlIdentityPermission == null || this.IsEmpty()) { return(null); } if (!this.Match(urlIdentityPermission.url)) { return(null); } if (this.url.Length > urlIdentityPermission.url.Length) { return(this.Copy()); } return(urlIdentityPermission.Copy()); }
/// <summary>确定当前权限是否为指定权限的子集。</summary> /// <returns>如果当前权限是指定权限的子集,则为 true;否则为 false。</returns> /// <param name="target">将要测试子集关系的权限。此权限必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -Url 属性不是有效的 URL。</exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /> /// </PermissionSet> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(!this.m_unrestricted && (this.m_urls == null || this.m_urls.Length == 0)); } UrlIdentityPermission identityPermission = target as UrlIdentityPermission; if (identityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (identityPermission.m_unrestricted) { return(true); } if (this.m_unrestricted) { return(false); } if (this.m_urls != null) { foreach (URLString mUrl1 in this.m_urls) { bool flag = false; if (identityPermission.m_urls != null) { foreach (URLString mUrl2 in identityPermission.m_urls) { if (mUrl1.IsSubsetOf((SiteString)mUrl2)) { flag = true; break; } } } if (!flag) { return(false); } } } return(true); }
private void AppendZoneOrigin(ZoneIdentityPermission z, UrlIdentityPermission u) { if (z != null) { if (this.m_zoneList == null) { this.m_zoneList = new ArrayList(); } z.AppendZones(this.m_zoneList); } if (u != null) { if (this.m_originList == null) { this.m_originList = new ArrayList(); } u.AppendOrigin(this.m_originList); } }
/// <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. -or-The Url property is not a valid URL.</exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /> /// </PermissionSet> public override bool IsSubsetOf(IPermission target) { UrlIdentityPermission urlIdentityPermission = this.Cast(target); if (urlIdentityPermission == null) { return(this.IsEmpty()); } if (this.IsEmpty()) { return(true); } if (urlIdentityPermission.url == null) { return(false); } int num = urlIdentityPermission.url.LastIndexOf('*'); if (num == -1) { num = urlIdentityPermission.url.Length; } return(string.Compare(this.url, 0, urlIdentityPermission.url, 0, num, true, CultureInfo.InvariantCulture) == 0); }
public override IPermission Intersect(IPermission target) { // if one permission is null (object or url) then there's no intersection // if both are null then intersection is null UrlIdentityPermission uip = Cast(target); if ((uip == null) || (IsEmpty())) { return(null); } if (Match(uip.url)) { // longest form is the intersection if (url.Length > uip.url.Length) { return(Copy()); } else { return(uip.Copy()); } } return(null); }
public void Union_None () { // Union with none is same UrlIdentityPermission uip1 = new UrlIdentityPermission (PermissionState.None); UrlIdentityPermission uip2 = new UrlIdentityPermission (PermissionState.None); // a. source (this) is none foreach (string s in GoodUrls) { uip1.Url = s; UrlIdentityPermission union = (UrlIdentityPermission)uip1.Union (uip2); // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format // so we only compare the start of the url Assert.IsTrue (union.Url.StartsWith (uip1.Url), s); } uip1 = new UrlIdentityPermission (PermissionState.None); // b. destination (target) is none foreach (string s in GoodUrls) { uip2.Url = s; UrlIdentityPermission union = (UrlIdentityPermission)uip2.Union (uip1); // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format // so we only compare the start of the url Assert.IsTrue (union.Url.StartsWith (uip2.Url), s); } }
public void Union_Self () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); UrlIdentityPermission union = (UrlIdentityPermission)uip.Union (uip); Assert.IsNull (union, "None U None"); foreach (string s in GoodUrls) { uip.Url = s; union = (UrlIdentityPermission)uip.Union (uip); // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format // so we only compare the start of the url Assert.IsTrue (union.Url.StartsWith (uip.Url), s); } }
public void Url () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); foreach (string s in GoodUrls) { uip.Url = s; Assert.AreEqual (s, uip.Url, s); } }
public void Union_Null () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); // Union with null is a simple copy foreach (string s in GoodUrls) { uip.Url = s; UrlIdentityPermission union = (UrlIdentityPermission)uip.Union (null); // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format // so we only compare the start of the url Assert.IsTrue (union.Url.StartsWith (uip.Url), s); } }
public void FromXml_WrongClass () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", "Wrong" + se.Attribute ("class")); w.AddAttribute ("version", se.Attribute ("version")); uip.FromXml (w); // doesn't care of the class name at that stage // anyway the class has already be created so... }
public void FromXml_WrongVersion () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); se.Attributes.Remove ("version"); se.Attributes.Add ("version", "2"); uip.FromXml (se); }
/// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary> /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns> /// <param name="target">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -<see cref="P:System.Security.Permissions.UrlIdentityPermission.Url" /> 属性不是有效的 URL。- 或 -两个权限不相等,而且其中一个不是另一个的子集。</exception> public override IPermission Union(IPermission target) { if (target == null) { if ((this.m_urls == null || this.m_urls.Length == 0) && !this.m_unrestricted) { return((IPermission)null); } return(this.Copy()); } UrlIdentityPermission identityPermission = target as UrlIdentityPermission; if (identityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (this.m_unrestricted || identityPermission.m_unrestricted) { return (IPermission) new UrlIdentityPermission(PermissionState.None) { m_unrestricted = true } } ; if (this.m_urls == null || this.m_urls.Length == 0) { if (identityPermission.m_urls == null || identityPermission.m_urls.Length == 0) { return((IPermission)null); } return(identityPermission.Copy()); } if (identityPermission.m_urls == null || identityPermission.m_urls.Length == 0) { return(this.Copy()); } List <URLString> urlStringList = new List <URLString>(); foreach (URLString mUrl in this.m_urls) { urlStringList.Add(mUrl); } foreach (URLString mUrl in identityPermission.m_urls) { bool flag = false; foreach (URLString url in urlStringList) { if (mUrl.Equals(url)) { flag = true; break; } } if (!flag) { urlStringList.Add(mUrl); } } return((IPermission) new UrlIdentityPermission(PermissionState.None) { m_urls = urlStringList.ToArray() }); }
public void FromXml_WrongTag () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); se.Tag = "IMono"; uip.FromXml (se); }
public void Intersect_None () { UrlIdentityPermission uip1 = new UrlIdentityPermission (PermissionState.None); UrlIdentityPermission uip2 = new UrlIdentityPermission (PermissionState.None); UrlIdentityPermission result = (UrlIdentityPermission)uip1.Intersect (uip2); Assert.IsNull (result, "None N None"); foreach (string s in GoodUrls) { uip1.Url = s; // 1. Intersect None with Url result = (UrlIdentityPermission)uip1.Intersect (uip2); Assert.IsNull (result, "None N " + s); // 2. Intersect Url with None result = (UrlIdentityPermission)uip2.Intersect (uip1); Assert.IsNull (result, s + "N None"); } }
public void Intersect_Self () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); foreach (string s in GoodUrls) { uip.Url = s; UrlIdentityPermission result = (UrlIdentityPermission)uip.Intersect (uip); // Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format // so we only compare the start of the url Assert.IsTrue (result.Url.StartsWith (uip.Url), s); } }
public void Intersect_Null () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); // No intersection with null foreach (string s in GoodUrls) { uip.Url = s; Assert.IsNull (uip.Intersect (null), s); } }
public override IPermission Union(IPermission target) { if (target == null) { if (((this.m_urls == null) || (this.m_urls.Length == 0)) && !this.m_unrestricted) { return(null); } return(this.Copy()); } UrlIdentityPermission permission = target as UrlIdentityPermission; if (permission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.m_unrestricted || permission.m_unrestricted) { return(new UrlIdentityPermission(PermissionState.None) { m_unrestricted = true }); } if ((this.m_urls == null) || (this.m_urls.Length == 0)) { if ((permission.m_urls != null) && (permission.m_urls.Length != 0)) { return(permission.Copy()); } return(null); } if ((permission.m_urls == null) || (permission.m_urls.Length == 0)) { return(this.Copy()); } List <URLString> list = new List <URLString>(); foreach (URLString str in this.m_urls) { list.Add(str); } foreach (URLString str2 in permission.m_urls) { bool flag = false; foreach (URLString str3 in list) { if (str2.Equals(str3)) { flag = true; break; } } if (!flag) { list.Add(str2); } } return(new UrlIdentityPermission(PermissionState.None) { m_urls = list.ToArray() }); }
public override IPermission Intersect(IPermission target) { if (target == null) return null; UrlIdentityPermission that = target as UrlIdentityPermission; if(that == null) throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); if(this.m_unrestricted && that.m_unrestricted) { UrlIdentityPermission res = new UrlIdentityPermission(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_urls == null || that.m_urls == null || this.m_urls.Length == 0 || that.m_urls.Length == 0) return null; List<URLString> alUrls = new List<URLString>(); foreach(URLString usThis in this.m_urls) { foreach(URLString usThat in that.m_urls) { URLString usInt = (URLString)usThis.Intersect(usThat); if(usInt != null) alUrls.Add(usInt); } } if(alUrls.Count == 0) return null; UrlIdentityPermission result = new UrlIdentityPermission(PermissionState.None); result.m_urls = alUrls.ToArray(); return result; }
public void Union_Different () { UrlIdentityPermission uip1 = new UrlIdentityPermission (GoodUrls [0]); UrlIdentityPermission uip2 = new UrlIdentityPermission (GoodUrls [1]); UrlIdentityPermission result = (UrlIdentityPermission)uip1.Union (uip2); 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 (GoodUrls [0], (se.Children [0] as SecurityElement).Attribute ("Url"), "Url#1"); Assert.AreEqual (GoodUrls [1], (se.Children [1] as SecurityElement).Attribute ("Url"), "Url#2"); // strangely it is still versioned as 'version="1"'. Assert.AreEqual ("1", se.Attribute ("version"), "Version"); }
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary> /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param> /// <returns>A new permission that represents the union of the current permission and the specified permission.</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. -or-The <see cref="P:System.Security.Permissions.UrlIdentityPermission.Url" /> property is not a valid URL.-or-The two permissions are not equal and one is not a subset of the other.</exception> // Token: 0x06002672 RID: 9842 RVA: 0x0008B440 File Offset: 0x00089640 public override IPermission Union(IPermission target) { if (target == null) { if ((this.m_urls == null || this.m_urls.Length == 0) && !this.m_unrestricted) { return(null); } return(this.Copy()); } else { UrlIdentityPermission urlIdentityPermission = target as UrlIdentityPermission; if (urlIdentityPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.m_unrestricted || urlIdentityPermission.m_unrestricted) { return(new UrlIdentityPermission(PermissionState.None) { m_unrestricted = true }); } if (this.m_urls == null || this.m_urls.Length == 0) { if (urlIdentityPermission.m_urls == null || urlIdentityPermission.m_urls.Length == 0) { return(null); } return(urlIdentityPermission.Copy()); } else { if (urlIdentityPermission.m_urls == null || urlIdentityPermission.m_urls.Length == 0) { return(this.Copy()); } List <URLString> list = new List <URLString>(); foreach (URLString item in this.m_urls) { list.Add(item); } foreach (URLString urlstring in urlIdentityPermission.m_urls) { bool flag = false; foreach (URLString url in list) { if (urlstring.Equals(url)) { flag = true; break; } } if (!flag) { list.Add(urlstring); } } return(new UrlIdentityPermission(PermissionState.None) { m_urls = list.ToArray() }); } } }
public void FromXml_Null () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); uip.FromXml (null); }
public void IsSubset_None () { // IsSubset with none // a. source (this) is none -> target is never a subset UrlIdentityPermission uip1 = new UrlIdentityPermission (PermissionState.None); UrlIdentityPermission uip2 = new UrlIdentityPermission (PermissionState.None); foreach (string s in GoodUrls) { uip1.Url = s; Assert.IsFalse (uip1.IsSubsetOf (uip2), "target " + s); } uip1 = new UrlIdentityPermission (PermissionState.None); // b. destination (target) is none -> target is always a subset foreach (string s in GoodUrls) { uip2.Url = s; Assert.IsFalse (uip2.IsSubsetOf (uip1), "source " + s); } }
public void FromXml_WrongTagCase () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); se.Tag = "IPERMISSION"; // instead of IPermission uip.FromXml (se); }
public void IsSubset_Self () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); Assert.IsTrue (uip.IsSubsetOf (uip), "None"); foreach (string s in GoodUrls) { uip.Url = s; Assert.IsTrue (uip.IsSubsetOf (uip), s); } }
public void FromXml_NoClass () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("version", se.Attribute ("version")); uip.FromXml (w); // doesn't even care of the class attribute presence }
public void IsSubset_Different () { UrlIdentityPermission uip1 = new UrlIdentityPermission (GoodUrls [0]); UrlIdentityPermission uip2 = new UrlIdentityPermission (GoodUrls [1]); Assert.IsFalse (uip1.IsSubsetOf (uip2), "Mono subset Novell"); Assert.IsFalse (uip2.IsSubsetOf (uip1), "Novell subset Mono"); }
public void FromXml_NoVersion () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); SecurityElement se = uip.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", se.Attribute ("class")); uip.FromXml (w); }
public void PermissionState_Bad () { UrlIdentityPermission uip = new UrlIdentityPermission ((PermissionState)Int32.MinValue); }
public void Intersect_Different () { UrlIdentityPermission uip1 = new UrlIdentityPermission (GoodUrls [0]); UrlIdentityPermission uip2 = new UrlIdentityPermission (GoodUrls [1]); UrlIdentityPermission result = (UrlIdentityPermission)uip1.Intersect (uip2); Assert.IsNull (result, "Mono N Novell"); }
public void IsSubset_Null () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); Assert.IsTrue (uip.IsSubsetOf (null), "Empty"); foreach (string s in GoodUrls) { uip.Url = s; Assert.IsFalse (uip.IsSubsetOf (null), s); } }
public void UrlIdentityPermission_NullUrl () { UrlIdentityPermission uip = new UrlIdentityPermission (null); }
public override IPermission Union(IPermission target) { if (target == null) { if ((this.m_urls == null || this.m_urls.Length == 0) && !this.m_unrestricted) { return(null); } return(this.Copy()); } UrlIdentityPermission that = target as UrlIdentityPermission; if (that == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (this.m_unrestricted || that.m_unrestricted) { UrlIdentityPermission res = new UrlIdentityPermission(PermissionState.None); res.m_unrestricted = true; return(res); } if (this.m_urls == null || this.m_urls.Length == 0) { if (that.m_urls == null || that.m_urls.Length == 0) { return(null); } return(that.Copy()); } if (that.m_urls == null || that.m_urls.Length == 0) { return(this.Copy()); } List <URLString> alUrls = new List <URLString>(); foreach (URLString usThis in this.m_urls) { alUrls.Add(usThis); } foreach (URLString usThat in that.m_urls) { bool bDupe = false; foreach (URLString us in alUrls) { if (usThat.Equals(us)) { bDupe = true; break; } } if (!bDupe) { alUrls.Add(usThat); } } UrlIdentityPermission result = new UrlIdentityPermission(PermissionState.None); result.m_urls = alUrls.ToArray(); return(result); }
//------------------------------------------------------ // // PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS // //------------------------------------------------------ //------------------------------------------------------ // // CODEACCESSPERMISSION IMPLEMENTATION // //------------------------------------------------------ //------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ public override IPermission Copy() { UrlIdentityPermission perm = new UrlIdentityPermission( PermissionState.None ); perm.m_unrestricted = this.m_unrestricted; if (this.m_urls != null) { perm.m_urls = new URLString[this.m_urls.Length]; int n; for(n = 0; n < this.m_urls.Length; n++) perm.m_urls[n] = (URLString)this.m_urls[n].Copy(); } return perm; }
/// <internalonly/> int IBuiltInPermission.GetTokenIndex() { return(UrlIdentityPermission.GetTokenIndex()); }
public override IPermission Union(IPermission target) { if (target == null) { if((this.m_urls == null || this.m_urls.Length == 0) && !this.m_unrestricted) return null; return this.Copy(); } UrlIdentityPermission that = target as UrlIdentityPermission; if(that == null) throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); if(this.m_unrestricted || that.m_unrestricted) { UrlIdentityPermission res = new UrlIdentityPermission(PermissionState.None); res.m_unrestricted = true; return res; } if (this.m_urls == null || this.m_urls.Length == 0) { if(that.m_urls == null || that.m_urls.Length == 0) return null; return that.Copy(); } if(that.m_urls == null || that.m_urls.Length == 0) return this.Copy(); List<URLString> alUrls = new List<URLString>(); foreach(URLString usThis in this.m_urls) alUrls.Add(usThis); foreach(URLString usThat in that.m_urls) { bool bDupe = false; foreach(URLString us in alUrls) { if(usThat.Equals(us)) { bDupe = true; break; } } if(!bDupe) alUrls.Add(usThat); } UrlIdentityPermission result = new UrlIdentityPermission(PermissionState.None); result.m_urls = alUrls.ToArray(); return result; }
public void Copy_None () { UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None); UrlIdentityPermission copy = (UrlIdentityPermission)uip.Copy (); }