public virtual IPermission SetPermission(IPermission perm) #endif { if ((perm == null) || _readOnly) { return(perm); } #if NET_2_0 IUnrestrictedPermission u = (perm as IUnrestrictedPermission); if (u == null) { state = PermissionState.None; } else { state = u.IsUnrestricted() ? state : PermissionState.None; } #else if (perm is IUnrestrictedPermission) { state = PermissionState.None; } #endif RemovePermission(perm.GetType()); list.Add(perm); return(perm); }
}// AddImages public override int GetImageIndex(int i) { // Figure out if we have settings for this specific permission // A permission needs to implement the IUnrestrictedPermission interface if // we want to be able to assign it a meaningful icon... if (m_psetWrapper.PSet.GetPermission(m_alPermissions[i].GetType()) is IUnrestrictedPermission) { IUnrestrictedPermission permission = (IUnrestrictedPermission)m_psetWrapper.PSet.GetPermission(m_alPermissions[i].GetType()); // If we don't have this permission if (permission == null) { return(m_iRestrictedIndex); } // If this is unrestricted.... if (permission.IsUnrestricted()) { return(m_iUnRestrictedIndex); } // else, this has partial permissions.... return(m_iRestrictedIndex); } // Otherwise... we don't know. We'll just display the restricted permission icon return(m_iRestrictedIndex); }// GetImageIndex
}// GetCurrentPermission protected void CheckUnrestricted(IUnrestrictedPermission perm) { if (perm.IsUnrestricted()) { m_radUnrestricted.Checked = true; m_ucOptions.Enabled = false; } else { m_radGrantFollowingPermission.Checked = true; } }// CheckUnrestricted
// Returns true if OK to return from check, or false if // permission-specific information must be checked. internal static bool CheckUnrestricted(IUnrestrictedPermission grant, CodeAccessPermission demand) { // We return true here because we're defining a demand of null to // automatically pass. if (demand == null) return true; if (demand.GetType() != grant.GetType()) return false; if (grant.IsUnrestricted()) return true; if (((IUnrestrictedPermission)demand).IsUnrestricted()) throw new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().FullName), demand.GetType(), demand.ToXml().ToString()); return false; }
public void GetStandardPermissionSetEverythingPermissionSetTest() { PermissionSet everything = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.Everything); // Everything should neither be empty nor full trust Assert.IsFalse(everything.IsUnrestricted()); Assert.IsFalse(everything.IsEmpty()); // Each permission in Everything should be unrestricted, except for SecurityPermission foreach (IPermission permission in everything) { IUnrestrictedPermission unrestricted = permission as IUnrestrictedPermission; SecurityPermission securityPermission = permission as SecurityPermission; if (securityPermission != null) { SecurityPermissionFlag everythingFlags = SecurityPermissionFlag.Assertion | SecurityPermissionFlag.BindingRedirects | SecurityPermissionFlag.ControlAppDomain | SecurityPermissionFlag.ControlDomainPolicy | SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy | SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.ControlThread | SecurityPermissionFlag.Execution | SecurityPermissionFlag.Infrastructure | SecurityPermissionFlag.RemotingConfiguration | SecurityPermissionFlag.SerializationFormatter | SecurityPermissionFlag.UnmanagedCode; Assert.AreEqual(everythingFlags, securityPermission.Flags); } else if (unrestricted != null) { Assert.IsTrue(unrestricted.IsUnrestricted()); } } // Everything should be a superset of Internet and LocalIntranet PermissionSet internet = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.Internet); Assert.IsTrue(internet.IsSubsetOf(everything)); Assert.IsFalse(everything.IsSubsetOf(internet)); PermissionSet localIntranet = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet); Assert.IsTrue(localIntranet.IsSubsetOf(everything)); Assert.IsFalse(everything.IsSubsetOf(localIntranet)); }
}// PutValuesinPage private int DeterminePermissionIcon(IPermission perm) { if (perm is IUnrestrictedPermission) { IUnrestrictedPermission permission = (IUnrestrictedPermission)perm; // If this is unrestricted.... if (permission.IsUnrestricted()) { return(UNRESTRICTEDIMAGEINDEX); } // else, this has partial permissions.... return(PARTIALIMAGEINDEX); } // Otherwise... we don't know... return(PARTIALIMAGEINDEX); }// DeterminePermissionIcon
public IPermission SetPermission(IPermission perm) { if ((perm == null) || _readOnly) { return(perm); } IUnrestrictedPermission u = (perm as IUnrestrictedPermission); if (u == null) { state = PermissionState.None; } else { state = u.IsUnrestricted() ? state : PermissionState.None; } RemovePermission(perm.GetType()); list.Add(perm); return(perm); }
// Returns true if OK to return from check, or false if // permission-specific information must be checked. internal static bool CheckUnrestricted(IUnrestrictedPermission grant, CodeAccessPermission demand) { // We return true here because we're defining a demand of null to // automatically pass. if (demand == null) { return(true); } if (demand.GetType() != grant.GetType()) { return(false); } if (grant.IsUnrestricted()) { return(true); } if (((IUnrestrictedPermission)demand).IsUnrestricted()) { throw new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().FullName), demand.GetType(), demand.ToXml().ToString()); } return(false); }