public override bool IsSubsetOf(IPermission target) { FileIOPermission fiop = Cast(target); if (fiop == null) { return(false); } if (fiop.IsEmpty()) { return(IsEmpty()); } if (IsUnrestricted()) { return(fiop.IsUnrestricted()); } else if (fiop.IsUnrestricted()) { return(true); } if ((m_AllFilesAccess & fiop.AllFiles) != m_AllFilesAccess) { return(false); } if ((m_AllLocalFilesAccess & fiop.AllLocalFiles) != m_AllLocalFilesAccess) { return(false); } if (!KeyIsSubsetOf(appendList, fiop.appendList)) { return(false); } if (!KeyIsSubsetOf(readList, fiop.readList)) { return(false); } if (!KeyIsSubsetOf(writeList, fiop.writeList)) { return(false); } if (!KeyIsSubsetOf(pathList, fiop.pathList)) { return(false); } return(true); }
//------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.IsEmpty()); } FileIOPermission operand = target as FileIOPermission; if (operand == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (operand.IsUnrestricted()) { return(true); } else if (this.IsUnrestricted()) { return(false); } else { return((this.m_read == null || this.m_read.IsSubsetOf(operand.m_read)) && (this.m_write == null || this.m_write.IsSubsetOf(operand.m_write)) && (this.m_append == null || this.m_append.IsSubsetOf(operand.m_append)) && (this.m_pathDiscovery == null || this.m_pathDiscovery.IsSubsetOf(operand.m_pathDiscovery)) && (this.m_viewAcl == null || this.m_viewAcl.IsSubsetOf(operand.m_viewAcl)) && (this.m_changeAcl == null || this.m_changeAcl.IsSubsetOf(operand.m_changeAcl))); } }
/// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary> /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns> /// <param name="other">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="other" /> 参数不是 null,而且与当前权限不是同一类型。</exception> public override IPermission Union(IPermission other) { if (other == null) { return(this.Copy()); } FileIOPermission fileIoPermission = other as FileIOPermission; if (fileIoPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (this.IsUnrestricted() || fileIoPermission.IsUnrestricted()) { return((IPermission) new FileIOPermission(PermissionState.Unrestricted)); } FileIOAccess fileIoAccess1 = this.m_read == null ? fileIoPermission.m_read : this.m_read.Union(fileIoPermission.m_read); FileIOAccess fileIoAccess2 = this.m_write == null ? fileIoPermission.m_write : this.m_write.Union(fileIoPermission.m_write); FileIOAccess fileIoAccess3 = this.m_append == null ? fileIoPermission.m_append : this.m_append.Union(fileIoPermission.m_append); FileIOAccess fileIoAccess4 = this.m_pathDiscovery == null ? fileIoPermission.m_pathDiscovery : this.m_pathDiscovery.Union(fileIoPermission.m_pathDiscovery); FileIOAccess fileIoAccess5 = this.m_viewAcl == null ? fileIoPermission.m_viewAcl : this.m_viewAcl.Union(fileIoPermission.m_viewAcl); FileIOAccess fileIoAccess6 = this.m_changeAcl == null ? fileIoPermission.m_changeAcl : this.m_changeAcl.Union(fileIoPermission.m_changeAcl); if ((fileIoAccess1 == null || fileIoAccess1.IsEmpty()) && (fileIoAccess2 == null || fileIoAccess2.IsEmpty()) && ((fileIoAccess3 == null || fileIoAccess3.IsEmpty()) && (fileIoAccess4 == null || fileIoAccess4.IsEmpty())) && ((fileIoAccess5 == null || fileIoAccess5.IsEmpty()) && (fileIoAccess6 == null || fileIoAccess6.IsEmpty()))) { return((IPermission)null); } return((IPermission) new FileIOPermission(PermissionState.None) { m_unrestricted = false, m_read = fileIoAccess1, m_write = fileIoAccess2, m_append = fileIoAccess3, m_pathDiscovery = fileIoAccess4, m_viewAcl = fileIoAccess5, m_changeAcl = fileIoAccess6 }); }
public override IPermission Intersect(IPermission target) { FileIOPermission fiop = Cast(target); if (fiop == null) { return(null); } if (IsUnrestricted()) { return(fiop.Copy()); } if (fiop.IsUnrestricted()) { return(Copy()); } FileIOPermission result = new FileIOPermission(PermissionState.None); result.AllFiles = m_AllFilesAccess & fiop.AllFiles; result.AllLocalFiles = m_AllLocalFilesAccess & fiop.AllLocalFiles; IntersectKeys(readList, fiop.readList, result.readList); IntersectKeys(writeList, fiop.writeList, result.writeList); IntersectKeys(appendList, fiop.appendList, result.appendList); IntersectKeys(pathList, fiop.pathList, result.pathList); return(result.IsEmpty() ? null : result); }
//------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ /// <include file='doc\FileIOPermission.uex' path='docs/doc[@for="FileIOPermission.IsSubsetOf"]/*' /> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.IsEmpty()); } try { FileIOPermission operand = (FileIOPermission)target; if (operand.IsUnrestricted()) { return(true); } else if (this.IsUnrestricted()) { return(false); } else { return((this.m_read == null || this.m_read.IsSubsetOf(operand.m_read)) && (this.m_write == null || this.m_write.IsSubsetOf(operand.m_write)) && (this.m_append == null || this.m_append.IsSubsetOf(operand.m_append)) && (this.m_pathDiscovery == null || this.m_pathDiscovery.IsSubsetOf(operand.m_pathDiscovery))); } } catch (InvalidCastException) { throw new ArgumentException( String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName) ); } }
/// <summary>确定当前权限是否为指定权限的子集。</summary> /// <returns>如果当前权限是指定权限的子集,则为 true;否则为 false。</returns> /// <param name="target">将要测试子集关系的权限。此权限必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.IsEmpty()); } FileIOPermission fileIoPermission = target as FileIOPermission; if (fileIoPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (fileIoPermission.IsUnrestricted()) { return(true); } if (this.IsUnrestricted() || this.m_read != null && !this.m_read.IsSubsetOf(fileIoPermission.m_read) || (this.m_write != null && !this.m_write.IsSubsetOf(fileIoPermission.m_write) || this.m_append != null && !this.m_append.IsSubsetOf(fileIoPermission.m_append)) || (this.m_pathDiscovery != null && !this.m_pathDiscovery.IsSubsetOf(fileIoPermission.m_pathDiscovery) || this.m_viewAcl != null && !this.m_viewAcl.IsSubsetOf(fileIoPermission.m_viewAcl))) { return(false); } if (this.m_changeAcl != null) { return(this.m_changeAcl.IsSubsetOf(fileIoPermission.m_changeAcl)); } return(true); }
public override IPermission Union(IPermission other) { if (other == null) { return(this.Copy()); } FileIOPermission permission = other as FileIOPermission; if (permission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.IsUnrestricted() || permission.IsUnrestricted()) { return(new FileIOPermission(PermissionState.Unrestricted)); } FileIOAccess access = (this.m_read == null) ? permission.m_read : this.m_read.Union(permission.m_read); FileIOAccess access2 = (this.m_write == null) ? permission.m_write : this.m_write.Union(permission.m_write); FileIOAccess access3 = (this.m_append == null) ? permission.m_append : this.m_append.Union(permission.m_append); FileIOAccess access4 = (this.m_pathDiscovery == null) ? permission.m_pathDiscovery : this.m_pathDiscovery.Union(permission.m_pathDiscovery); FileIOAccess access5 = (this.m_viewAcl == null) ? permission.m_viewAcl : this.m_viewAcl.Union(permission.m_viewAcl); FileIOAccess access6 = (this.m_changeAcl == null) ? permission.m_changeAcl : this.m_changeAcl.Union(permission.m_changeAcl); if (((((access == null) || access.IsEmpty()) && ((access2 == null) || access2.IsEmpty())) && (((access3 == null) || access3.IsEmpty()) && ((access4 == null) || access4.IsEmpty()))) && (((access5 == null) || access5.IsEmpty()) && ((access6 == null) || access6.IsEmpty()))) { return(null); } return(new FileIOPermission(PermissionState.None) { m_unrestricted = false, m_read = access, m_write = access2, m_append = access3, m_pathDiscovery = access4, m_viewAcl = access5, m_changeAcl = access6 }); }
/// <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 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 IPermission Intersect(IPermission target) { FileIOPermission fileIOPermission = FileIOPermission.Cast(target); if (fileIOPermission == null) { return(null); } if (this.IsUnrestricted()) { return(fileIOPermission.Copy()); } if (fileIOPermission.IsUnrestricted()) { return(this.Copy()); } FileIOPermission fileIOPermission2 = new FileIOPermission(PermissionState.None); fileIOPermission2.AllFiles = (this.m_AllFilesAccess & fileIOPermission.AllFiles); fileIOPermission2.AllLocalFiles = (this.m_AllLocalFilesAccess & fileIOPermission.AllLocalFiles); FileIOPermission.IntersectKeys(this.readList, fileIOPermission.readList, fileIOPermission2.readList); FileIOPermission.IntersectKeys(this.writeList, fileIOPermission.writeList, fileIOPermission2.writeList); FileIOPermission.IntersectKeys(this.appendList, fileIOPermission.appendList, fileIOPermission2.appendList); FileIOPermission.IntersectKeys(this.pathList, fileIOPermission.pathList, fileIOPermission2.pathList); return((!fileIOPermission2.IsEmpty()) ? fileIOPermission2 : null); }
/// <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 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) { FileIOPermission fileIOPermission = FileIOPermission.Cast(target); if (fileIOPermission == null) { return(false); } if (fileIOPermission.IsEmpty()) { return(this.IsEmpty()); } if (this.IsUnrestricted()) { return(fileIOPermission.IsUnrestricted()); } return(fileIOPermission.IsUnrestricted() || ((this.m_AllFilesAccess & fileIOPermission.AllFiles) == this.m_AllFilesAccess && (this.m_AllLocalFilesAccess & fileIOPermission.AllLocalFiles) == this.m_AllLocalFilesAccess && FileIOPermission.KeyIsSubsetOf(this.appendList, fileIOPermission.appendList) && FileIOPermission.KeyIsSubsetOf(this.readList, fileIOPermission.readList) && FileIOPermission.KeyIsSubsetOf(this.writeList, fileIOPermission.writeList) && FileIOPermission.KeyIsSubsetOf(this.pathList, fileIOPermission.pathList))); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } FileIOPermission operand = target as FileIOPermission; if (operand == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } else if (this.IsUnrestricted()) { return(target.Copy()); } if (operand.IsUnrestricted()) { return(this.Copy()); } FileIOAccess intersectRead = this.m_read == null ? null : this.m_read.Intersect(operand.m_read); FileIOAccess intersectWrite = this.m_write == null ? null : this.m_write.Intersect(operand.m_write); FileIOAccess intersectAppend = this.m_append == null ? null : this.m_append.Intersect(operand.m_append); FileIOAccess intersectPathDiscovery = this.m_pathDiscovery == null ? null : this.m_pathDiscovery.Intersect(operand.m_pathDiscovery); FileIOAccess intersectViewAcl = this.m_viewAcl == null ? null : this.m_viewAcl.Intersect(operand.m_viewAcl); FileIOAccess intersectChangeAcl = this.m_changeAcl == null ? null : this.m_changeAcl.Intersect(operand.m_changeAcl); if ((intersectRead == null || intersectRead.IsEmpty()) && (intersectWrite == null || intersectWrite.IsEmpty()) && (intersectAppend == null || intersectAppend.IsEmpty()) && (intersectPathDiscovery == null || intersectPathDiscovery.IsEmpty()) && (intersectViewAcl == null || intersectViewAcl.IsEmpty()) && (intersectChangeAcl == null || intersectChangeAcl.IsEmpty())) { return(null); } FileIOPermission intersectPermission = new FileIOPermission(PermissionState.None); intersectPermission.m_unrestricted = false; intersectPermission.m_read = intersectRead; intersectPermission.m_write = intersectWrite; intersectPermission.m_append = intersectAppend; intersectPermission.m_pathDiscovery = intersectPathDiscovery; intersectPermission.m_viewAcl = intersectViewAcl; intersectPermission.m_changeAcl = intersectChangeAcl; return(intersectPermission); }
public override IPermission Union(IPermission other) { FileIOPermission fiop = Cast(other); if (fiop == null) { return(Copy()); } if (IsUnrestricted() || fiop.IsUnrestricted()) { return(new FileIOPermission(PermissionState.Unrestricted)); } if (IsEmpty() && fiop.IsEmpty()) { return(null); } FileIOPermission result = (FileIOPermission)Copy(); result.AllFiles |= fiop.AllFiles; result.AllLocalFiles |= fiop.AllLocalFiles; string[] paths = fiop.GetPathList(FileIOPermissionAccess.Read); if (paths != null) { UnionKeys(result.readList, paths); } paths = fiop.GetPathList(FileIOPermissionAccess.Write); if (paths != null) { UnionKeys(result.writeList, paths); } paths = fiop.GetPathList(FileIOPermissionAccess.Append); if (paths != null) { UnionKeys(result.appendList, paths); } paths = fiop.GetPathList(FileIOPermissionAccess.PathDiscovery); if (paths != null) { UnionKeys(result.pathList, paths); } return(result); }
public override IPermission Union(IPermission other) { if (other == null) { return(this.Copy()); } FileIOPermission operand = other as FileIOPermission; if (operand == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)); } if (this.IsUnrestricted() || operand.IsUnrestricted()) { return(new FileIOPermission(PermissionState.Unrestricted)); } FileIOAccess unionRead = this.m_read == null ? operand.m_read : this.m_read.Union(operand.m_read); FileIOAccess unionWrite = this.m_write == null ? operand.m_write : this.m_write.Union(operand.m_write); FileIOAccess unionAppend = this.m_append == null ? operand.m_append : this.m_append.Union(operand.m_append); FileIOAccess unionPathDiscovery = this.m_pathDiscovery == null ? operand.m_pathDiscovery : this.m_pathDiscovery.Union(operand.m_pathDiscovery); FileIOAccess unionViewAcl = this.m_viewAcl == null ? operand.m_viewAcl : this.m_viewAcl.Union(operand.m_viewAcl); FileIOAccess unionChangeAcl = this.m_changeAcl == null ? operand.m_changeAcl : this.m_changeAcl.Union(operand.m_changeAcl); if ((unionRead == null || unionRead.IsEmpty()) && (unionWrite == null || unionWrite.IsEmpty()) && (unionAppend == null || unionAppend.IsEmpty()) && (unionPathDiscovery == null || unionPathDiscovery.IsEmpty()) && (unionViewAcl == null || unionViewAcl.IsEmpty()) && (unionChangeAcl == null || unionChangeAcl.IsEmpty())) { return(null); } FileIOPermission unionPermission = new FileIOPermission(PermissionState.None); unionPermission.m_unrestricted = false; unionPermission.m_read = unionRead; unionPermission.m_write = unionWrite; unionPermission.m_append = unionAppend; unionPermission.m_pathDiscovery = unionPathDiscovery; unionPermission.m_viewAcl = unionViewAcl; unionPermission.m_changeAcl = unionChangeAcl; return(unionPermission); }
/// <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="other">A permission to combine with the current permission. It must be the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception> public override IPermission Union(IPermission other) { FileIOPermission fileIOPermission = FileIOPermission.Cast(other); if (fileIOPermission == null) { return(this.Copy()); } if (this.IsUnrestricted() || fileIOPermission.IsUnrestricted()) { return(new FileIOPermission(PermissionState.Unrestricted)); } if (this.IsEmpty() && fileIOPermission.IsEmpty()) { return(null); } FileIOPermission fileIOPermission2 = (FileIOPermission)this.Copy(); fileIOPermission2.AllFiles |= fileIOPermission.AllFiles; fileIOPermission2.AllLocalFiles |= fileIOPermission.AllLocalFiles; string[] array = fileIOPermission.GetPathList(FileIOPermissionAccess.Read); if (array != null) { FileIOPermission.UnionKeys(fileIOPermission2.readList, array); } array = fileIOPermission.GetPathList(FileIOPermissionAccess.Write); if (array != null) { FileIOPermission.UnionKeys(fileIOPermission2.writeList, array); } array = fileIOPermission.GetPathList(FileIOPermissionAccess.Append); if (array != null) { FileIOPermission.UnionKeys(fileIOPermission2.appendList, array); } array = fileIOPermission.GetPathList(FileIOPermissionAccess.PathDiscovery); if (array != null) { FileIOPermission.UnionKeys(fileIOPermission2.pathList, array); } return(fileIOPermission2); }
public void FromXML () { p = new FileIOPermission(PermissionState.None); SecurityElement esd = new SecurityElement("IPermission"); esd.AddAttribute("class", "FileIOPermission"); esd.AddAttribute("version", "1"); esd.AddAttribute("Unrestricted", "true"); p.FromXml(esd); Assert.IsTrue(p.IsUnrestricted(), "Should get an unrestricted permission"); esd = new SecurityElement("IPermission"); esd.AddAttribute("class", "FileIOPermission"); esd.AddAttribute("version", "1"); // FIXME: Adjust to run on Mac OS's if (Path.VolumeSeparatorChar == ':') { esd.AddAttribute("Read", "c:\\temp;d:\\temp2"); esd.AddAttribute("Write", "c:\\temp;d:\\temp2;z:\\temp3"); } else { esd.AddAttribute("Read", "/temp;/usr/temp2"); esd.AddAttribute("Write", "/temp;/usr/temp2;/usr/bin/temp3"); } p = new FileIOPermission(PermissionState.None); p.FromXml(esd); pathsInPermission = p.GetPathList(FileIOPermissionAccess.Read); Assert.IsTrue(pathsInPermission.Length == 2, "Path list should have 2 for Read"); pathsInPermission = p.GetPathList(FileIOPermissionAccess.Write); Assert.IsTrue(pathsInPermission.Length == 3, "Path list should have 2 for Write"); }
public void ConstructorPermissionState () { p = new FileIOPermission(PermissionState.None); Assert.AreEqual(false, p.IsUnrestricted(), "Should be Restricted"); p = new FileIOPermission(PermissionState.Unrestricted); Assert.AreEqual(true, p.IsUnrestricted(), "Should be Unrestricted"); try{ p = new FileIOPermission((PermissionState)77); Assert.Fail("Should have thrown an exception on invalid PermissionState"); } catch{ // we should be here if things are working. nothing to do } }
private static string GetFileIOPermission (FileIOPermission ep) { if (ep.IsUnrestricted ()) return " FileIOPermission - Unrestricted\\l"; StringBuilder sb = new StringBuilder (" FileIOPermission\\l"); /* string[] list = ep.GetPathList (FileIOPermissionAccess.PathDiscovery); if ((list != null) && (list.Length > 0)) { sb.AppendFormat (" PathDiscovery: {0}\\l", s); } s = ep.GetPathList (FileIOPermissionAccess.Read); if ((s != null) && (s.Length > 0)) sb.AppendFormat (" Read: {0}\\l", s); s = ep.GetPathList (FileIOPermissionAccess.Write); if ((s != null) && (s.Length > 0)) sb.AppendFormat (" Write: {0}\\l", s); s = ep.GetPathList (FileIOPermissionAccess.Append); if ((s != null) && (s.Length > 0)) sb.AppendFormat (" Append: {0}\\l", s);*/ return sb.ToString (); }