public void OpenSave () { FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.OpenSave); Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted"); }
/// <include file='doc\FileDialogPermission.uex' path='docs/doc[@for="FileDialogPermission.IsSubsetOf"]/*' /> public override bool IsSubsetOf(IPermission target) { if (target == null) { // Only safe subset if this is empty return(access == FileDialogPermissionAccess.None); } try { FileDialogPermission operand = (FileDialogPermission)target; if (operand.IsUnrestricted()) { return(true); } else if (this.IsUnrestricted()) { return(false); } else { int open = (int)(access & FileDialogPermissionAccess.Open); int save = (int)(access & FileDialogPermissionAccess.Save); int openTarget = (int)(operand.Access & FileDialogPermissionAccess.Open); int saveTarget = (int)(operand.Access & FileDialogPermissionAccess.Save); return(open <= openTarget && save <= saveTarget); } } 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.access == FileDialogPermissionAccess.None); } try { FileDialogPermission dialogPermission = (FileDialogPermission)target; if (dialogPermission.IsUnrestricted()) { return(true); } if (this.IsUnrestricted()) { return(false); } int num1 = (int)(this.access & FileDialogPermissionAccess.Open); int num2 = (int)(this.access & FileDialogPermissionAccess.Save); int num3 = (int)(dialogPermission.Access & FileDialogPermissionAccess.Open); int num4 = (int)(dialogPermission.Access & FileDialogPermissionAccess.Save); int num5 = num3; return(num1 <= num5 && num2 <= num4); } catch (InvalidCastException ex) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } }
public void None () { FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.None); Assert ("IsUnrestricted", !p.IsUnrestricted ()); SecurityElement se = p.ToXml (); AssertNull ("ToXml-Access=None", (se.Attributes ["Access"] as string)); }
public void Derestricted () { FileDialogPermission p = new FileDialogPermission (PermissionState.Unrestricted); Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted"); p.Access = FileDialogPermissionAccess.None; Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); }
public void OpenSave () { FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.OpenSave); Assert ("IsUnrestricted", p.IsUnrestricted ()); SecurityElement se = p.ToXml (); AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string)); }
public void Save () { FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.Save); Assert ("IsUnrestricted", !p.IsUnrestricted ()); SecurityElement se = p.ToXml (); AssertEquals ("ToXml-Access=Save", "Save", (se.Attributes ["Access"] as string)); }
public void Derestricted () { FileDialogPermission p = new FileDialogPermission (PermissionState.Unrestricted); Assert ("IsUnrestricted", p.IsUnrestricted ()); p.Access = FileDialogPermissionAccess.None; Assert ("IsUnrestricted", !p.IsUnrestricted ()); }
public void None () { FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.None); Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.IsNull ((se.Attributes ["Access"] as string), "ToXml-Access=None"); }
public void Save () { FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.Save); Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.AreEqual ("Save", (se.Attributes ["Access"] as string), "ToXml-Access=Save"); }
public override bool IsSubsetOf(IPermission target) { bool flag; if (target == null) { return(this.access == FileDialogPermissionAccess.None); } try { FileDialogPermission permission = (FileDialogPermission)target; if (permission.IsUnrestricted()) { return(true); } if (this.IsUnrestricted()) { return(false); } int num = ((int)this.access) & 1; int num2 = ((int)this.access) & 2; int num3 = ((int)permission.Access) & 1; int num4 = ((int)permission.Access) & 2; flag = (num <= num3) && (num2 <= num4); } catch (InvalidCastException) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } return(flag); }
public void PermissionStateUnrestricted () { FileDialogPermission p = new FileDialogPermission (PermissionState.Unrestricted); Assert.IsNotNull (p, "FileDialogPermission(PermissionState.Unrestricted)"); Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted"); FileDialogPermission copy = (FileDialogPermission) p.Copy (); Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted"); }
public void PermissionStateUnrestricted () { FileDialogPermission p = new FileDialogPermission (PermissionState.Unrestricted); AssertNotNull ("FileDialogPermission(PermissionState.Unrestricted)", p); Assert ("IsUnrestricted", p.IsUnrestricted ()); FileDialogPermission copy = (FileDialogPermission) p.Copy (); AssertEquals ("Copy.IsUnrestricted", p.IsUnrestricted (), copy.IsUnrestricted ()); SecurityElement se = p.ToXml (); AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string)); }
public override bool IsSubsetOf(IPermission target) { FileDialogPermission fdp = Cast(target); if (fdp == null) { return(false); } return((_access & fdp._access) == _access); }
public void PermissionStateNone () { FileDialogPermission p = new FileDialogPermission (PermissionState.None); Assert.IsNotNull (p, "FileDialogPermission(PermissionState.None)"); Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); FileDialogPermission copy = (FileDialogPermission) p.Copy (); Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class"); Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version"); }
public void PermissionStateNone () { FileDialogPermission p = new FileDialogPermission (PermissionState.None); AssertNotNull ("FileDialogPermission(PermissionState.None)", p); Assert ("IsUnrestricted", !p.IsUnrestricted ()); FileDialogPermission copy = (FileDialogPermission) p.Copy (); AssertEquals ("Copy.IsUnrestricted", p.IsUnrestricted (), copy.IsUnrestricted ()); SecurityElement se = p.ToXml (); Assert ("ToXml-class", (se.Attributes ["class"] as string).StartsWith (className)); AssertEquals ("ToXml-version", "1", (se.Attributes ["version"] as string)); }
/// <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) { FileDialogPermission fileDialogPermission = this.Cast(target); if (fileDialogPermission == null) { return(null); } FileDialogPermissionAccess fileDialogPermissionAccess = this._access & fileDialogPermission._access; return((fileDialogPermissionAccess != FileDialogPermissionAccess.None) ? new FileDialogPermission(fileDialogPermissionAccess) : null); }
public override IPermission Intersect(IPermission target) { FileDialogPermission fdp = Cast(target); if (fdp == null) { return(null); } FileDialogPermissionAccess a = (_access & fdp._access); return((a == FileDialogPermissionAccess.None) ? null : new FileDialogPermission(a)); }
public void PermissionSetPermissionSet () { FileDialogPermission fdp = new FileDialogPermission (FileDialogPermissionAccess.Open); PermissionSet ps1 = new PermissionSet (PermissionState.None); ps1.AddPermission (fdp); Assert ("ps1.IsEmpty", !ps1.IsEmpty ()); PermissionSet ps = new PermissionSet (ps1); Assert ("PermissionSetPermissionSet.IsUnrestricted", !ps.IsUnrestricted ()); Assert ("PermissionSetPermissionSet.IsEmpty", !ps.IsEmpty ()); Assert ("PermissionSetPermissionSet.IsReadOnly", !ps.IsReadOnly); AssertEquals ("PermissionSetPermissionSet.ToXml().ToString()==ToString()", ps.ToXml ().ToString (), ps.ToString ()); }
public void PermissionSetPermissionSet () { FileDialogPermission fdp = new FileDialogPermission (FileDialogPermissionAccess.Open); PermissionSet ps1 = new PermissionSet (PermissionState.None); ps1.AddPermission (fdp); Assert.IsTrue (!ps1.IsEmpty (), "ps1.IsEmpty"); PermissionSet ps = new PermissionSet (ps1); Assert.IsTrue (!ps.IsUnrestricted (), "PermissionSetPermissionSet.IsUnrestricted"); Assert.IsTrue (!ps.IsEmpty (), "PermissionSetPermissionSet.IsEmpty"); Assert.IsTrue (!ps.IsReadOnly, "PermissionSetPermissionSet.IsReadOnly"); Assert.AreEqual (ps.ToXml ().ToString (), ps.ToString (), "PermissionSetPermissionSet.ToXml().ToString()==ToString()"); Assert.IsTrue (!ps.ContainsNonCodeAccessPermissions (), "ContainsNonCodeAccessPermissions"); }
public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } if (!base.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } FileDialogPermission permission = (FileDialogPermission)target; return(new FileDialogPermission(this.access | permission.Access)); }
/// <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. </exception> public override IPermission Union(IPermission target) { FileDialogPermission fileDialogPermission = this.Cast(target); if (fileDialogPermission == null) { return(this.Copy()); } if (this.IsUnrestricted() || fileDialogPermission.IsUnrestricted()) { return(new FileDialogPermission(PermissionState.Unrestricted)); } return(new FileDialogPermission(this._access | fileDialogPermission._access)); }
private FileDialogPermission Cast(IPermission target) { if (target == null) { return(null); } FileDialogPermission fileDialogPermission = target as FileDialogPermission; if (fileDialogPermission == null) { CodeAccessPermission.ThrowInvalidPermission(target, typeof(FileDialogPermission)); } return(fileDialogPermission); }
// Methods public override IPermission CreatePermission () { FileDialogPermission perm = null; if (this.Unrestricted) perm = new FileDialogPermission (PermissionState.Unrestricted); else { FileDialogPermissionAccess access = FileDialogPermissionAccess.None; if (canOpen) access |= FileDialogPermissionAccess.Open; if (canSave) access |= FileDialogPermissionAccess.Save; perm = new FileDialogPermission (access); } return perm; }
/// <include file='doc\FileDialogPermission.uex' path='docs/doc[@for="FileDialogPermission.Union"]/*' /> public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } else if (!VerifyType(target)) { throw new ArgumentException(String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)); } FileDialogPermission operand = (FileDialogPermission)target; return(new FileDialogPermission(access | operand.Access)); }
// helpers private FileDialogPermission Cast(IPermission target) { if (target == null) { return(null); } FileDialogPermission fdp = (target as FileDialogPermission); if (fdp == null) { ThrowInvalidPermission(target, typeof(FileDialogPermission)); } return(fdp); }
public override IPermission Union(IPermission target) { FileDialogPermission fdp = Cast(target); if (fdp == null) { return(Copy()); } if (IsUnrestricted() || fdp.IsUnrestricted()) { return(new FileDialogPermission(PermissionState.Unrestricted)); } return(new FileDialogPermission(_access | fdp._access)); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } if (!base.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } FileDialogPermission permission = (FileDialogPermission)target; FileDialogPermissionAccess access = this.access & permission.Access; if (access == FileDialogPermissionAccess.None) { return(null); } return(new FileDialogPermission(access)); }
public static bool RunSecurityDemands() { FileIOPermission fPer = new FileIOPermission(PermissionState.None); fPer.AllLocalFiles = FileIOPermissionAccess.AllAccess; fPer.AllFiles = FileIOPermissionAccess.AllAccess; try { fPer.Demand(); } catch (SecurityException s) { Common.DebugHelper.WriteLine("File IO Permission Error: {0}", s.Message); return false; } System.Security.Permissions.FileDialogPermission fdPer = new FileDialogPermission(FileDialogPermissionAccess.None); fdPer.Access = FileDialogPermissionAccess.OpenSave; try { fdPer.Demand(); } catch (System.Security.SecurityException s) { Common.DebugHelper.WriteLine("File Dialog Persmission Error: {0}", s.Message); return false; } System.Security.Permissions.RegistryPermission rPer = new RegistryPermission(PermissionState.None); rPer.SetPathList(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE"); try { fPer.Demand(); } catch (System.Security.SecurityException s) { Common.DebugHelper.WriteLine("Registry Access Permission Error: {0}", s.Message); return false; } return true; }
/// <summary>Creates and returns a new <see cref="T:System.Security.Permissions.FileDialogPermission" />.</summary> /// <returns>A <see cref="T:System.Security.Permissions.FileDialogPermission" /> that corresponds to this attribute.</returns> public override IPermission CreatePermission() { FileDialogPermission result; if (base.Unrestricted) { result = new FileDialogPermission(PermissionState.Unrestricted); } else { FileDialogPermissionAccess fileDialogPermissionAccess = FileDialogPermissionAccess.None; if (this.canOpen) { fileDialogPermissionAccess |= FileDialogPermissionAccess.Open; } if (this.canSave) { fileDialogPermissionAccess |= FileDialogPermissionAccess.Save; } result = new FileDialogPermission(fileDialogPermissionAccess); } return(result); }
// Methods public override IPermission CreatePermission() { FileDialogPermission perm = null; if (this.Unrestricted) { perm = new FileDialogPermission(PermissionState.Unrestricted); } else { FileDialogPermissionAccess access = FileDialogPermissionAccess.None; if (canOpen) { access |= FileDialogPermissionAccess.Open; } if (canSave) { access |= FileDialogPermissionAccess.Save; } perm = new FileDialogPermission(access); } return(perm); }
/// <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 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: 0x060024B0 RID: 9392 RVA: 0x000852D4 File Offset: 0x000834D4 public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.access == FileDialogPermissionAccess.None); } bool result; try { FileDialogPermission fileDialogPermission = (FileDialogPermission)target; if (fileDialogPermission.IsUnrestricted()) { result = true; } else if (this.IsUnrestricted()) { result = false; } else { int num = (int)(this.access & FileDialogPermissionAccess.Open); int num2 = (int)(this.access & FileDialogPermissionAccess.Save); int num3 = (int)(fileDialogPermission.Access & FileDialogPermissionAccess.Open); int num4 = (int)(fileDialogPermission.Access & FileDialogPermissionAccess.Save); result = (num <= num3 && num2 <= num4); } } catch (InvalidCastException) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } return(result); }
/// <include file='doc\FileDialogPermission.uex' path='docs/doc[@for="FileDialogPermission.Intersect"]/*' /> public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } else if (!VerifyType(target)) { throw new ArgumentException(String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)); } FileDialogPermission operand = (FileDialogPermission)target; FileDialogPermissionAccess intersectAccess = access & operand.Access; if (intersectAccess == FileDialogPermissionAccess.None) { return(null); } else { return(new FileDialogPermission(intersectAccess)); } }
public void IsSubsetOf () { FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open); FileDialogPermission p2 = new FileDialogPermission (FileDialogPermissionAccess.Save); Assert.IsTrue (!p1.IsSubsetOf (p2), "IsSubsetOf(nosubset1)"); Assert.IsTrue (!p2.IsSubsetOf (p1), "IsSubsetOf(nosubset2)"); FileDialogPermission p3 = new FileDialogPermission (FileDialogPermissionAccess.OpenSave); Assert.IsTrue (p1.IsSubsetOf (p3), "IsSubsetOf(OpenSave)"); Assert.IsTrue (!p3.IsSubsetOf (p1), "OpenSave.IsSubsetOf()"); }
public void IsSubsetOfUnrestricted () { FileDialogPermission p1 = new FileDialogPermission (PermissionState.Unrestricted); FileDialogPermission p2 = new FileDialogPermission (FileDialogPermissionAccess.Open); FileDialogPermission p3 = new FileDialogPermission (PermissionState.Unrestricted); Assert.IsTrue (!p1.IsSubsetOf (p2), "Unrestricted.IsSubsetOf()"); Assert.IsTrue (p2.IsSubsetOf (p1), "IsSubsetOf(Unrestricted)"); Assert.IsTrue (p1.IsSubsetOf (p3), "Unrestricted.IsSubsetOf(Unrestricted)"); }
public void IsSubsetOfNull () { FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open); Assert.IsTrue (!p1.IsSubsetOf (null), "IsSubsetOf(null)"); }
protected override IStackWalk CreateStackWalk() { FileDialogPermission permission = new FileDialogPermission(attribute.Access); return permission; }
public void IsSubsetOfBadPermission () { RegistryPermission ep1 = new RegistryPermission (RegistryPermissionAccess.Read, keyLocalMachine); FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted); Assert.IsTrue (ep1.IsSubsetOf (fdp2), "IsSubsetOf(FileDialogPermission)"); }
public void IntersectWithBadPermission () { PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509); FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted); PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Intersect (fdp2); }
public void IntersectWithBadPermission () { RegistryPermission ep1 = new RegistryPermission (RegistryPermissionAccess.Read, keyLocalMachine); FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted); RegistryPermission ep3 = (RegistryPermission)ep1.Intersect (fdp2); }
public void IsSubsetOfBadPermission () { EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables); FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted); Assert ("IsSubsetOf(FileDialogPermission)", ep1.IsSubsetOf (fdp2)); }
public void IsSubsetOfBadPermission () { FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open); EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted); Assert.IsTrue (p1.IsSubsetOf (ep2), "IsSubsetOf(EnvironmentPermission)"); }
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.FileDialogPermission" /> class with the specified access.</summary> /// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileDialogPermissionAccess" /> values. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid combination of the <see cref="T:System.Security.Permissions.FileDialogPermissionAccess" /> values. </exception> // Token: 0x060024A8 RID: 9384 RVA: 0x000851D9 File Offset: 0x000833D9 public FileDialogPermission(FileDialogPermissionAccess access) { FileDialogPermission.VerifyAccess(access); this.access = access; }
public void IsSubsetOfBadPermission () { PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509); FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted); Assert.IsTrue (p1.IsSubsetOf (fdp2), "IsSubsetOf(PublisherIdentityPermission)"); }
/// <include file='doc\FileDialogPermission.uex' path='docs/doc[@for="FileDialogPermission.IBuiltInPermission.GetTokenIndex"]/*' /> /// <internalonly/> int IBuiltInPermission.GetTokenIndex() { return(FileDialogPermission.GetTokenIndex()); }
public void IntersectWithBadPermission () { EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables); FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted); EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Intersect (fdp2); }
public void Access () { FileDialogPermission p = new FileDialogPermission (PermissionState.None); Assert.IsTrue (!p.IsUnrestricted (), "Access(default).IsUnrestricted"); p.Access = FileDialogPermissionAccess.None; Assert.IsTrue (!p.IsUnrestricted (), "Access(None).IsUnrestricted"); p.Access = FileDialogPermissionAccess.Open; Assert.IsTrue (!p.IsUnrestricted (), "Access(Open).IsUnrestricted"); p.Access = FileDialogPermissionAccess.Save; Assert.IsTrue (!p.IsUnrestricted (), "Access(Save).IsUnrestricted"); p.Access = FileDialogPermissionAccess.OpenSave; Assert.IsTrue (p.IsUnrestricted (), "Access(OpenSave).IsUnrestricted"); }
public void ResolveWithChildren () { PermissionSet pset1 = new PermissionSet (PermissionState.None); PermissionSet pset2 = new PermissionSet (PermissionState.None); PermissionSet pset3 = new PermissionSet (PermissionState.None); PermissionSet pset4 = new PermissionSet (PermissionState.None); PermissionSet pset5 = new PermissionSet (PermissionState.None); PermissionSet pset6 = new PermissionSet (PermissionState.None); IPermission perm1 = new UIPermission (PermissionState.Unrestricted); IPermission perm2 = new EnvironmentPermission (PermissionState.Unrestricted); IPermission perm3 = new FileDialogPermission (PermissionState.Unrestricted); IPermission perm4 = new ReflectionPermission (PermissionState.Unrestricted); IPermission perm5 = new RegistryPermission (PermissionState.Unrestricted); IPermission perm6 = new FileIOPermission (PermissionState.Unrestricted); pset1.AddPermission (perm1); PolicyStatement policy1 = new PolicyStatement (pset1); pset2.AddPermission(perm2); PolicyStatement policy2 = new PolicyStatement (pset2); pset3.AddPermission (perm3); PolicyStatement policy3 = new PolicyStatement (pset3); pset4.AddPermission (perm4); PolicyStatement policy4 = new PolicyStatement (pset4); pset5.AddPermission (perm5); PolicyStatement policy5 = new PolicyStatement (pset5); pset6.AddPermission (perm6); PolicyStatement policy6 = new PolicyStatement (pset6); UnionCodeGroup root = new UnionCodeGroup (new AllMembershipCondition (), policy1); UnionCodeGroup child1 = new UnionCodeGroup (new ZoneMembershipCondition (SecurityZone.Internet), policy2); UnionCodeGroup child2 = new UnionCodeGroup (new AllMembershipCondition (), policy3); UnionCodeGroup child3 = new UnionCodeGroup (new AllMembershipCondition (), policy4); UnionCodeGroup childofchild1 = new UnionCodeGroup (new AllMembershipCondition (), policy5); UnionCodeGroup childofchild3 = new UnionCodeGroup (new AllMembershipCondition (), policy6); child1.AddChild (childofchild1); child3.AddChild (childofchild3); root.AddChild (child1); root.AddChild (child2); root.AddChild (child3); PolicyStatement result = root.Resolve (new Evidence ()); PermissionSet correctset = new PermissionSet (PermissionState.None); correctset.AddPermission (perm1); correctset.AddPermission (perm3); correctset.AddPermission (perm4); correctset.AddPermission (perm6); Assert.AreEqual (correctset.Count, result.PermissionSet.Count, "PermissionSet.Count"); foreach (IPermission p in correctset) { IPermission r = result.PermissionSet.GetPermission (p.GetType ()); Assert.IsNotNull (r, "PermissionSet.GetPermission"); } }
public void FromXmlOne () { FileDialogPermission fdp = new FileDialogPermission (FileDialogPermissionAccess.Open); PermissionSet ps1 = new PermissionSet (PermissionState.None); ps1.AddPermission (fdp); Assert.IsTrue (!ps1.IsEmpty (), "ps1.IsEmpty"); PermissionSet ps = new PermissionSet (ps1); SecurityElement se = ps.ToXml (); Assert.IsNotNull (se, "One.ToXml()"); Assert.AreEqual (1, ps.Count, "One.Count"); PermissionSet ps2 = (PermissionSet) ps.Copy (); ps2.FromXml (se); Assert.IsTrue (!ps2.IsUnrestricted () , "FromXml-Copy.IsUnrestricted"); Assert.AreEqual (1, ps2.Count, "Copy.Count"); se.AddAttribute ("Unrestricted", "true"); ps2.FromXml (se); Assert.IsTrue (ps2.IsUnrestricted (), "FromXml-Unrestricted.IsUnrestricted"); #if NET_2_0 Assert.AreEqual (0, ps2.Count, "Unrestricted.Count"); #else // IPermission not shown in XML but still present in Count Assert.AreEqual (1, ps2.Count, "Unrestricted.Count"); #endif }
/// <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) { FileDialogPermission fileDialogPermission = this.Cast(target); return(fileDialogPermission != null && (this._access & fileDialogPermission._access) == this._access); }