public static PermissionViewBase CreateControlBy(IPermission permission) { var type = GetViewTypeByPermissionType(permission.GetType()); var control = type.GetConstructor(new[] { permission.GetType() }).Invoke(new[] { permission }); return((PermissionViewBase)control); }
// methods public IPermission AddPermission(IPermission perm) { if ((perm == null) || _readOnly) { return(perm); } // we don't add to an unrestricted permission set unless... if (state == PermissionState.Unrestricted) { // identity permissions can be unrestricted under 2.x { // we return the union of the permission with unrestricted // which results in a permission of the same type initialized // with PermissionState.Unrestricted return((IPermission)Activator.CreateInstance(perm.GetType(), psUnrestricted)); } } // we can't add two permissions of the same type in a set // so we remove an existing one, union with it and add it back IPermission existing = RemovePermission(perm.GetType()); if (existing != null) { perm = perm.Union(existing); } // note: Add doesn't copy list.Add(perm); return(perm); }
static internal SecurityElement CreatePermissionElement(IPermission perm, String permname) { SecurityElement root = new SecurityElement("IPermission"); XMLUtil.AddClassAttribute(root, perm.GetType(), permname); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. BCLDebug.Assert(perm.GetType().FullName.Equals(permname), "Incorrect class name passed in! Was: " + permname + " Should be " + perm.GetType().FullName); root.AddAttribute("version", "1"); return(root); }
/// <include file='doc\ResourcePermissionBase.uex' path='docs/doc[@for="ResourcePermissionBase.Intersect"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } if (target.GetType() != this.GetType()) { throw new ArgumentException("target"); } ResourcePermissionBase targetPermission = (ResourcePermissionBase)target; if (this.IsUnrestricted()) { return(targetPermission.Copy()); } if (targetPermission.IsUnrestricted()) { return(this.Copy()); } ResourcePermissionBase newPermission = null; Hashtable newPermissionRootTable = (Hashtable)IntersectContents(this.rootTable, targetPermission.rootTable); if (newPermissionRootTable != null) { newPermission = CreateInstance(); newPermission.rootTable = newPermissionRootTable; } return(newPermission); }
// Form the intersection of two permission objects. public override IPermission Intersect(IPermission target) { if (target == null) { return(target); } else if (target.GetType() != GetType()) { throw new ArgumentException(S._("Arg_PermissionMismatch")); } else if (((ResourcePermissionBase)target).IsUnrestricted()) { return(Copy()); } else if (IsUnrestricted()) { return(target.Copy()); } ResourcePermissionBase perm; perm = (ResourcePermissionBase)(target.Copy()); perm.Clear(); foreach (ResourcePermissionBaseEntry entry in permissions) { if (((ResourcePermissionBase)target).Contains(entry)) { perm.AddPermissionAccess(entry); } } return(perm); }
// Form the union of two permission objects. public override IPermission Union(IPermission target) { if (target == null) { return(Copy()); } else if (target.GetType() != GetType()) { throw new ArgumentException(S._("Arg_PermissionMismatch")); } else if (IsUnrestricted() || ((ResourcePermissionBase)target).IsUnrestricted()) { return((ResourcePermissionBase)Activator.CreateInstance (GetType(), new Object [] { PermissionState.Unrestricted })); } else { ResourcePermissionBase perm; perm = (ResourcePermissionBase)(target.Copy()); foreach (ResourcePermissionBaseEntry entry in permissions) { if (!perm.Contains(entry)) { perm.AddPermissionAccess(entry); } } return(perm); } }
SecurityException(string message, AssemblyName assemblyName, #if NOT_PFX PermissionSet grant, PermissionSet refused, #endif MethodInfo method, SecurityAction action, object demanded #if NOT_PFX , IPermission permThatFailed, Evidence evidence #endif ) : base(message) { base.HResult = unchecked ((int)0x8013150A); _assembly = assemblyName; #if NOT_PFX _granted = (grant == null) ? String.Empty : grant.ToString(); _refused = (refused == null) ? String.Empty : refused.ToString(); #endif _method = method; _action = action; _demanded = demanded; #if NOT_PFX _firstperm = permThatFailed; if (_firstperm != null) { permissionType = _firstperm.GetType(); } _evidence = evidence; #endif }
public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.IsEmpty()); } if (target.GetType() != base.GetType()) { throw ADP.PermissionTypeMismatch(); } DBDataPermission permission = target as DBDataPermission; bool flag = permission.IsUnrestricted(); if ((!flag && !this.IsUnrestricted()) && (!this.AllowBlankPassword || permission.AllowBlankPassword)) { if ((this._keyvalues != null) && (permission._keyvaluetree == null)) { return(flag); } flag = true; if (this._keyvalues == null) { return(flag); } foreach (DBConnectionString str in this._keyvalues) { if (!permission._keyvaluetree.CheckValueForKeyPermit(str)) { return(false); } } } return(flag); }
override public IPermission Union(IPermission target) { if (null == target) { return(this.Copy()); } if (target.GetType() != this.GetType()) { throw ADP.PermissionTypeMismatch(); } if (IsUnrestricted()) { // MDAC 84803 return(this.Copy()); } SqlClientPermission newPermission = (SqlClientPermission)target.Copy(); if (!newPermission.IsUnrestricted()) { newPermission.AllowBlankPassword |= AllowBlankPassword; if (null != _keyvalues) { foreach (DBConnectionString entry in _keyvalues) { newPermission.AddPermissionEntry(entry); } } } return(newPermission.IsEmpty() ? null : newPermission); }
internal static void ThrowInvalidPermission(IPermission target, Type expected) { string msg = Locale.GetText("Invalid permission type '{0}', expected type '{1}'."); msg = String.Format(msg, target.GetType(), expected); throw new ArgumentException(msg, "target"); }
public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } if (target.GetType() != base.GetType()) { throw new ArgumentException(SR.GetString("PermissionTypeMismatch"), "target"); } ResourcePermissionBase base2 = (ResourcePermissionBase)target; ResourcePermissionBase base3 = null; if (this.IsUnrestricted() || base2.IsUnrestricted()) { base3 = this.CreateInstance(); base3.isUnrestricted = true; return(base3); } Hashtable hashtable = (Hashtable)this.UnionOfContents(this.rootTable, base2.rootTable); if (hashtable != null) { base3 = this.CreateInstance(); base3.rootTable = hashtable; } return(base3); }
public SecurityException(string message, AssemblyName assemblyName, PermissionSet grant, PermissionSet refused, MethodInfo method, SecurityAction action, object demanded, IPermission permThatFailed, Evidence evidence) : base(message) { PermissionSet.s_fullTrust.Assert(); this.SetErrorCode(-2146233078); this.Action = action; if (permThatFailed != null) { this.m_typeOfPermissionThatFailed = permThatFailed.GetType(); } this.FirstPermissionThatFailed = permThatFailed; this.Demanded = demanded; this.m_granted = grant == null ? "" : grant.ToXml().ToString(); this.m_refused = refused == null ? "" : refused.ToXml().ToString(); this.m_denied = ""; this.m_permitOnly = ""; this.m_assemblyName = assemblyName; this.Method = method; this.m_url = ""; this.m_zone = SecurityZone.NoZone; if (evidence != null) { System.Security.Policy.Url hostEvidence1 = evidence.GetHostEvidence <System.Security.Policy.Url>(); if (hostEvidence1 != null) { this.m_url = hostEvidence1.GetURLString().ToString(); } System.Security.Policy.Zone hostEvidence2 = evidence.GetHostEvidence <System.Security.Policy.Zone>(); if (hostEvidence2 != null) { this.m_zone = hostEvidence2.SecurityZone; } } this.m_debugString = this.ToString(true, false); }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(IsEmpty); } if (target.GetType() != this.GetType()) { return(false); } ResourcePermissionBase targetPermission = (ResourcePermissionBase)target; if (targetPermission.IsUnrestricted()) { return(true); } else if (this.IsUnrestricted()) { return(false); } return(IsContentSubset(this.rootTable, targetPermission.rootTable)); }
/// <include file='doc\DBDataPermission.uex' path='docs/doc[@for="DBDataPermission.Union"]/*' /> override public IPermission Union(IPermission target) { if (null == target) { return(this.Copy()); } if (target.GetType() != this.GetType()) { throw ADP.Argument("target"); } if (IsUnrestricted()) // MDAC 84803 { return(this.Copy()); } DBDataPermission newPermission = (DBDataPermission)target.Copy(); if (!newPermission.IsUnrestricted()) { newPermission._allowBlankPassword |= AllowBlankPassword; if (null != _keyvalues) { foreach (DBConnectionString entry in _keyvalues) { newPermission.AddEntry(entry); } } } return(newPermission); }
// Determine if this permission object is a subset of another. public override bool IsSubsetOf(IPermission target) { if (target == null) { return(state == PermissionState.None && permissions.Count == 0); } else if (target.GetType() != GetType()) { throw new ArgumentException(S._("Arg_PermissionMismatch")); } else if (((ResourcePermissionBase)target).IsUnrestricted()) { return(true); } else if (IsUnrestricted()) { return(false); } foreach (ResourcePermissionBaseEntry entry in permissions) { if (!((ResourcePermissionBase)target).Contains(entry)) { return(false); } } return(true); }
public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } if (target.GetType() != base.GetType()) { throw ADP.PermissionTypeMismatch(); } if (this.IsUnrestricted()) { return(this.Copy()); } DBDataPermission permission = (DBDataPermission)target.Copy(); if (!permission.IsUnrestricted()) { permission._allowBlankPassword |= this.AllowBlankPassword; if (this._keyvalues != null) { foreach (DBConnectionString str in this._keyvalues) { permission.AddPermissionEntry(str); } } } if (!permission.IsEmpty()) { return(permission); } return(null); }
[System.Security.SecuritySafeCritical] // auto-generated public SecurityException(string message, AssemblyName assemblyName, PermissionSet grant, PermissionSet refused, MethodInfo method, SecurityAction action, Object demanded, IPermission permThatFailed, Evidence evidence) : base(message) { PermissionSet.s_fullTrust.Assert(); SetErrorCode(System.__HResults.COR_E_SECURITY); Action = action; if (permThatFailed != null) { m_typeOfPermissionThatFailed = permThatFailed.GetType(); } FirstPermissionThatFailed = permThatFailed; Demanded = demanded; m_granted = (grant == null ? "" : grant.ToXml().ToString()); m_refused = (refused == null ? "" : refused.ToXml().ToString()); m_denied = ""; m_permitOnly = ""; m_assemblyName = assemblyName; Method = method; m_url = ""; m_zone = SecurityZone.NoZone; if (evidence != null) { Url url = evidence.GetHostEvidence <Url>(); if (url != null) { m_url = url.GetURLString().ToString(); } Zone zone = evidence.GetHostEvidence <Zone>(); if (zone != null) { m_zone = zone.SecurityZone; } } m_debugString = this.ToString(true, false); }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } if (target.GetType() != this.GetType()) { throw new ArgumentException(SR.GetString(SR.PermissionTypeMismatch), "target"); } ResourcePermissionBase targetPermission = (ResourcePermissionBase)target; ResourcePermissionBase newPermission = null; if (this.IsUnrestricted() || targetPermission.IsUnrestricted()) { newPermission = CreateInstance(); newPermission.isUnrestricted = true; } else { Hashtable newPermissionRootTable = (Hashtable)UnionOfContents(this.rootTable, targetPermission.rootTable); if (newPermissionRootTable != null) { newPermission = CreateInstance(); newPermission.rootTable = newPermissionRootTable; } } return(newPermission); }
internal static SecurityElement CreatePermissionElement(IPermission perm, string permname) { SecurityElement element = new SecurityElement("IPermission"); XMLUtil.AddClassAttribute(element, perm.GetType(), permname); element.AddAttribute("version", "1"); return element; }
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); }
static internal SecurityElement CreatePermissionElement(IPermission perm) { SecurityElement root = new SecurityElement("IPermission"); XMLUtil.AddClassAttribute(root, perm.GetType()); root.AddAttribute("version", "1"); return(root); }
internal static SecurityElement CreatePermissionElement(IPermission perm, string permname) { SecurityElement element = new SecurityElement("IPermission"); XMLUtil.AddClassAttribute(element, perm.GetType(), permname); element.AddAttribute("version", "1"); return(element); }
//------------------------------------------------------ // // IPermission interface implementation // //------------------------------------------------------ public override bool IsSubsetOf(IPermission target) { if (target == null) return m_resources == HostProtectionResource.None; if(this.GetType() != target.GetType()) throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); return ((uint)this.m_resources & (uint)((HostProtectionPermission)target).m_resources) == (uint)this.m_resources; }
IPermission IPermission.Union(IPermission target) { if (target != null && target.GetType() == this.GetType()) { return((IPermission)((SecurityAuthorizeAttribute)target).MemberwiseClone()); } return(null); }
// IBuiltInPermission is internal but we can test it's values // using reflection. private int GetTokenIndex (IPermission p) { Type t = p.GetType (); int result = (int) t.InvokeMember ("System.Security.Permissions.IBuiltInPermission.GetTokenIndex", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, p, null); return result; }
public override IPermission Union(IPermission target) { if (target == null) return(this.Copy()); if(this.GetType() != target.GetType()) throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); HostProtectionResource newResources = (HostProtectionResource)((uint)this.m_resources | (uint)((HostProtectionPermission)target).m_resources); return new HostProtectionPermission(newResources); }
// IBuiltInPermission is internal but we can test it's values // using reflection. private int GetTokenIndex(IPermission p) { Type t = p.GetType(); int result = (int)t.InvokeMember("System.Security.Permissions.IBuiltInPermission.GetTokenIndex", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, p, null); return(result); }
// Private method to cast (if possible) an IPermission to the type. private SoundPermission VerifyTypeMatch(IPermission target) { if (GetType() != target.GetType()) { throw new ArgumentException(String.Format("target must be of the {0} type", GetType().FullName)); } return((SoundPermission)target); }
public void Union_null() { ConfigurationPermission p1 = new ConfigurationPermission(PermissionState.Unrestricted); IPermission p3 = p1.Union(null); Assert.AreEqual(typeof(ConfigurationPermission), p3.GetType(), "A1"); Assert.IsTrue(((ConfigurationPermission)p3).IsUnrestricted(), "A2"); }
/// <summary> /// Implement the IPermission.IsSubsetOf. This method returns a bool to indicate /// whether or not the current permission is a subset of the supplied permission. To be a subset, every item of state in the current permission must also be in the target permission. /// </summary> /// <param name="target">See <see cref="IPermission"/>.</param> /// <returns></returns> public override bool IsSubsetOf(IPermission target) { // An input of null indicates a permission with no state. // The permission can only be a subset if it's in a similar empty state. bool canEncrypt, canDecrypt, canSign; bool canTargetEncrypt, canTargetDecrypt, canTargetSignature; canEncrypt = (this._permFlag & CryptographicPermissionFlags.Encrypt).Equals(CryptographicPermissionFlags.Encrypt); canDecrypt = (this._permFlag & CryptographicPermissionFlags.Decrypt).Equals(CryptographicPermissionFlags.Decrypt); canSign = (this._permFlag & CryptographicPermissionFlags.Sign).Equals(CryptographicPermissionFlags.Sign); if (target == null) { if (canEncrypt == false && canDecrypt == false && canSign == false) { return(true); } else { return(false); } } if (!target.GetType().Equals(this.GetType())) { throw new ArgumentException(Resource.ResourceManager[Resource.MessageKey.CryptographicPermissionArgumentException]); } // Cast the target to an EncryptionPermission. CryptographicPermission targetPerm = (CryptographicPermission)target; canTargetEncrypt = (targetPerm._permFlag & CryptographicPermissionFlags.Encrypt).Equals(CryptographicPermissionFlags.Encrypt); canTargetDecrypt = (targetPerm._permFlag & CryptographicPermissionFlags.Decrypt).Equals(CryptographicPermissionFlags.Decrypt); canTargetSignature = (targetPerm._permFlag & CryptographicPermissionFlags.Sign).Equals(CryptographicPermissionFlags.Sign); // Every value set (true) in this permission must be in the target. // The following code checks to see if the current permission is a subset // of the target. If the current permission has something that the target // does not have, it cannot be a subset. if (canEncrypt == true && canTargetEncrypt == false) { return(false); } if (canDecrypt == true && canTargetDecrypt == false) { return(false); } if (canSign == true && canTargetSignature == false) { return(false); } return(true); }
// // HELPERS FOR IMPLEMENTING ABSTRACT METHODS // // // Protected helper // /// <summary> /// 验证格式 /// </summary> /// <param name="perm">许可对象</param> /// <returns>bool</returns> internal bool VerifyType(IPermission perm) { if ((perm == null) || (perm.GetType() != this.GetType())) //如果许可对象,那么显然不是同一类型的, { return(false); } else { return(true); } }
public void Intersect() { ConfigurationPermission p1 = new ConfigurationPermission(PermissionState.Unrestricted); ConfigurationPermission p2 = new ConfigurationPermission(PermissionState.None); IPermission p3 = p1.Intersect(p2); Assert.AreEqual(typeof(ConfigurationPermission), p3.GetType(), "A1"); Assert.IsFalse(((ConfigurationPermission)p3).IsUnrestricted(), "A2"); }
public override IPermission Intersect(IPermission target) { if (target == null) return null; if (target.GetType() != typeof(ConfigurationPermission)) throw ExceptionUtil.ParameterInvalid("target"); // Create an None permission if either this or other is None if (_permissionState == PermissionState.None) return new ConfigurationPermission(PermissionState.None); ConfigurationPermission other = (ConfigurationPermission)target; return new ConfigurationPermission(other._permissionState); }
public static PermissionToken GetToken(IPermission perm) { if (perm == null) return null; IBuiltInPermission ibPerm = perm as IBuiltInPermission; if (ibPerm != null) return s_theTokenFactory.BuiltInGetToken( ibPerm.GetTokenIndex(), perm, null ); else return s_theTokenFactory.GetToken(perm.GetType(), perm); }
public override IPermission Union(IPermission target) { if (target == null) return Copy(); if (target.GetType() != typeof(ConfigurationPermission)) throw ExceptionUtil.ParameterInvalid("target"); // Create an Unrestricted permission if either this or other is unrestricted if (_permissionState == PermissionState.Unrestricted) return new ConfigurationPermission(PermissionState.Unrestricted); ConfigurationPermission other = (ConfigurationPermission)target; return new ConfigurationPermission(other._permissionState); }
/// <summary> /// Checks if the specified permission is "implied" by this object. /// <para> /// More specifically, this method returns true if: /// * perm's class is the same as this object's class, and /// * perm's name equals. /// </para> /// </summary> /// <param name="perm">The permission to check against.</param> /// <param name="ignore_case"> /// A <see cref="Boolean"/> indicating a case-sensitive or insensitive /// comparison(<c>true</c> indicates a case-insensitive comparison.) /// </param> /// <returns> /// <c>true</c> if the specified permission is equal to or implied by this /// permission; otherwise, false. /// </returns> public bool Implies(IPermission perm, bool ignore_case) { if (perm == null || perm.GetType() != GetType()) { return false; } if (ignore_case) { return string.Compare(Name, perm.Name, StringComparison.InvariantCultureIgnoreCase) == 0; } return Name == perm.Name; }
public override IPermission Intersect(IPermission target) { if (target == null) { return null; } if (target.GetType() != typeof(ConfigurationPermission)) { throw ExceptionUtil.ParameterInvalid("target"); } if (this._permissionState == PermissionState.None) { return new ConfigurationPermission(PermissionState.None); } ConfigurationPermission permission = (ConfigurationPermission) target; return new ConfigurationPermission(permission._permissionState); }
public override IPermission Intersect(IPermission target) { if (target == null) { return null; } if (target.GetType() != typeof(AspNetHostingPermission)) { throw new ArgumentException(SR.GetString("InvalidArgument", new object[] { (target == null) ? "null" : target.ToString(), "target" })); } AspNetHostingPermission permission = (AspNetHostingPermission) target; if (this.Level <= permission.Level) { return new AspNetHostingPermission(this.Level); } return new AspNetHostingPermission(permission.Level); }
public override IPermission Intersect(IPermission target) { if (target == null) { return null; } if (base.GetType() != target.GetType()) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } HostProtectionResource resources = this.m_resources & ((HostProtectionPermission) target).m_resources; if (resources == HostProtectionResource.None) { return null; } return new HostProtectionPermission(resources); }
public override IPermission Intersect(IPermission target) { NavigationPermission navigationPermission = target as NavigationPermission; if (navigationPermission == null) { throw new ArgumentException(string.Format("Incorrect permission is passed: '{0}' instead of '{1}'", target.GetType(), base.GetType())); } NavigationAccessList navigationAccessList = new NavigationAccessList(); NavigationPermission navigationPermission2 = new NavigationPermission(); foreach (string current in this.AccessInfo.Items) { if (navigationPermission.AccessInfo.Items.Contains(current)) { navigationAccessList.Items.Add(current); } } navigationPermission2.AccessInfo = navigationAccessList; return navigationPermission2; }
private bool VerifyType(IPermission perm) { // if perm is null, then obviously not of the same type return (perm != null) && (perm.GetType() == GetType()); }
static internal SecurityElement CreatePermissionElement( IPermission perm, String permname ) { SecurityElement root = new SecurityElement( "IPermission" ); XMLUtil.AddClassAttribute( root, perm.GetType(), permname ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( perm.GetType().FullName.Equals( permname ), "Incorrect class name passed in! Was: " + permname + " Should be " + perm.GetType().FullName); root.AddAttribute( "version", "1" ); return root; }
public override IPermission Intersect(IPermission target) { if (target == null) return null; if(this.GetType() != target.GetType()) throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); HostProtectionResource newResources = (HostProtectionResource)((uint)this.m_resources & (uint)((HostProtectionPermission)target).m_resources); if(newResources == HostProtectionResource.None) return null; return new HostProtectionPermission(newResources); }
// // HELPERS FOR IMPLEMENTING ABSTRACT METHODS // // // Protected helper // internal bool VerifyType(IPermission perm) { // if perm is null, then obviously not of the same type if ((perm == null) || (perm.GetType() != this.GetType())) { return(false); } else { return(true); } }
public static bool IsTokenProperlyAssigned(IPermission perm, PermissionToken token) { PermissionToken token2 = GetToken(perm); if (token2.m_index != token.m_index) { return false; } if (token.m_type != token2.m_type) { return false; } if ((perm.GetType().Module.Assembly == Assembly.GetExecutingAssembly()) && (token2.m_index >= 0x11)) { return false; } return true; }
} //FromXml() public override bool IsSubsetOf(IPermission target) { if (target == null) return false; if (typeof(myperm) != target.GetType()) return false; return true; } //IsSubsetOf()
[System.Security.SecurityCritical] // auto-generated internal static Exception MakeSecurityException(AssemblyName asmName, Evidence asmEvidence, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) { #if FEATURE_CAS_POLICY // See if we need to throw a HostProtectionException instead HostProtectionPermission hostProtectionPerm = permThatFailed as HostProtectionPermission; if(hostProtectionPerm != null) return new HostProtectionException(GetResString("HostProtection_HostProtection"), HostProtectionPermission.protectedResources, hostProtectionPerm.Resources); // Produce relevant strings String message = ""; MethodInfo method = null; try { if(granted == null && refused == null && demand == null) { message = GetResString("Security_NoAPTCA"); } else { if(demand != null && demand is IPermission) message = String.Format(CultureInfo.InvariantCulture, GetResString("Security_Generic"), demand.GetType().AssemblyQualifiedName ); else if (permThatFailed != null) message = String.Format(CultureInfo.InvariantCulture, GetResString("Security_Generic"), permThatFailed.GetType().AssemblyQualifiedName); else message = GetResString("Security_GenericNoType"); } method = SecurityRuntime.GetMethodInfo(rmh); } catch(Exception e) { // Environment.GetResourceString will throw if we are ReadyForAbort (thread abort). (We shouldn't do a Contract.Assert in this case or it will lock up the thread.) if(e is System.Threading.ThreadAbortException) throw; } /* catch(System.Threading.ThreadAbortException) { // Environment.GetResourceString will throw if we are ReadyForAbort (thread abort). (We shouldn't do a BCLDebug.Assert in this case or it will lock up the thread.) throw; } catch { } */ // make the exception object return new SecurityException(message, asmName, granted, refused, method, action, demand, permThatFailed, asmEvidence); #else return new SecurityException(GetResString("Arg_SecurityException")); #endif }
} //Copy() public override IPermission Intersect(IPermission target) { if (target == null) return null; if (typeof(myperm) != target.GetType()) return null; return new myperm(); } //Intersect()
public static bool IsTokenProperlyAssigned( IPermission perm, PermissionToken token ) { PermissionToken heldToken = GetToken( perm ); if (heldToken.m_index != token.m_index) return false; if (token.m_type != heldToken.m_type) return false; if (perm.GetType().Module.Assembly == Assembly.GetExecutingAssembly() && heldToken.m_index >= BuiltInPermissionIndex.NUM_BUILTIN_NORMAL + BuiltInPermissionIndex.NUM_BUILTIN_UNRESTRICTED) return false; return true; }
[System.Security.SecuritySafeCritical] // auto-generated public SecurityException(string message, Object deny, Object permitOnly, MethodInfo method, Object demanded, IPermission permThatFailed) : base(message) { PermissionSet.s_fullTrust.Assert(); SetErrorCode(System.__HResults.COR_E_SECURITY); Action = SecurityAction.Demand; if(permThatFailed != null) m_typeOfPermissionThatFailed = permThatFailed.GetType(); FirstPermissionThatFailed = permThatFailed; Demanded = demanded; m_granted = ""; m_refused = ""; DenySetInstance = deny; PermitOnlySetInstance = permitOnly; m_assemblyName = null; Method = method; m_zone = SecurityZone.NoZone; m_url = ""; m_debugString = this.ToString(true, false); }
internal static void ThrowInvalidPermission (IPermission target, Type expected) { string msg = Locale.GetText ("Invalid permission type '{0}', expected type '{1}'."); msg = String.Format (msg, target.GetType (), expected); throw new ArgumentException (msg, "target"); }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override bool IsSubsetOf(IPermission target) { if (target == null) { return (IsEmpty); } if (target.GetType() != this.GetType()) return false; ResourcePermissionBase targetPermission = (ResourcePermissionBase)target; if (targetPermission.IsUnrestricted()) return true; else if (this.IsUnrestricted()) return false; return IsContentSubset(this.rootTable, targetPermission.rootTable); }
public static PermissionToken GetToken(IPermission perm) { if (perm == null) { return null; } IBuiltInPermission permission = perm as IBuiltInPermission; if (permission != null) { return s_theTokenFactory.BuiltInGetToken(permission.GetTokenIndex(), perm, null); } return s_theTokenFactory.GetToken(perm.GetType(), perm); }
// // Compares two ConfigurationPermission instances // public override bool IsSubsetOf(IPermission target) { if (target == null) { return _permissionState == PermissionState.None; } if (target.GetType() != typeof(ConfigurationPermission)) { throw ExceptionUtil.ParameterInvalid("target"); } ConfigurationPermission other = (ConfigurationPermission) target; return (_permissionState == PermissionState.None || other._permissionState == PermissionState.Unrestricted); }
} //Intersect() public override IPermission Union(IPermission target) { if (target == null) return new myperm(); if (typeof(myperm) != target.GetType()) return null; return new myperm(); } //Union()
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override IPermission Union(IPermission target) { if (target == null) return this.Copy(); if (target.GetType() != this.GetType()) throw new ArgumentException(SR.GetString(SR.PermissionTypeMismatch), "target"); ResourcePermissionBase targetPermission = (ResourcePermissionBase)target; ResourcePermissionBase newPermission = null; if (this.IsUnrestricted() || targetPermission.IsUnrestricted()) { newPermission = CreateInstance(); newPermission.isUnrestricted = true; } else { Hashtable newPermissionRootTable = (Hashtable)UnionOfContents(this.rootTable, targetPermission.rootTable); if (newPermissionRootTable != null) { newPermission = CreateInstance(); newPermission.rootTable = newPermissionRootTable; } } return newPermission; }
internal PermissionToken GetToken(Type cls, IPermission perm) { Contract.Assert( cls != null, "Must pass in valid type" ); IntPtr typePtr = cls.TypeHandle.Value; object tok = m_handleTable[typePtr]; if (tok == null) { String typeStr = cls.AssemblyQualifiedName; tok = m_tokenTable != null ? m_tokenTable[typeStr] : null; // Assumes asynchronous lookups are safe if (tok == null) { lock (this) { if (m_tokenTable != null) { tok = m_tokenTable[typeStr]; // Make sure it wasn't just added } else m_tokenTable = new Hashtable(m_size, 1.0f, new PermissionTokenKeyComparer()); if (tok == null) { if (perm != null) { tok = new PermissionToken( m_index++, PermissionTokenType.IUnrestricted, typeStr ); } else { if (cls.GetInterface(s_unrestrictedPermissionInferfaceName) != null) tok = new PermissionToken( m_index++, PermissionTokenType.IUnrestricted, typeStr ); else tok = new PermissionToken( m_index++, PermissionTokenType.Normal, typeStr ); } m_tokenTable.Add(typeStr, tok); m_indexTable.Add(m_index - 1, tok); PermissionToken.s_tokenSet.SetItem( ((PermissionToken)tok).m_index, tok ); } if (!m_handleTable.Contains(typePtr)) m_handleTable.Add( typePtr, tok ); } } else { lock (this) { if (!m_handleTable.Contains(typePtr)) m_handleTable.Add( typePtr, tok ); } } } if ((((PermissionToken)tok).m_type & PermissionTokenType.DontKnow) != 0) { if (perm != null) { Contract.Assert( !(perm is IBuiltInPermission), "This should not be called for built-ins" ); ((PermissionToken)tok).m_type = PermissionTokenType.IUnrestricted; #if FEATURE_CAS_POLICY ((PermissionToken)tok).m_strTypeName = perm.GetType().AssemblyQualifiedName; #endif // FEATURE_CAS_POLICY } else { Contract.Assert( cls.GetInterface( "System.Security.Permissions.IBuiltInPermission" ) == null, "This shoudl not be called for built-ins" ); if (cls.GetInterface(s_unrestrictedPermissionInferfaceName) != null) ((PermissionToken)tok).m_type = PermissionTokenType.IUnrestricted; else ((PermissionToken)tok).m_type = PermissionTokenType.Normal; #if FEATURE_CAS_POLICY ((PermissionToken)tok).m_strTypeName = cls.AssemblyQualifiedName; #endif // FEATURE_CAS_POLICY } } return (PermissionToken)tok; }
// note: in 2.0 *all* permissions (including identity permissions) support unrestricted internal static bool IsGranted (Assembly a, IPermission perm) { PermissionSet granted = a.GrantedPermissionSet; if ((granted != null) && !granted.IsUnrestricted ()) { CodeAccessPermission grant = (CodeAccessPermission) granted.GetPermission (perm.GetType ()); if (!perm.IsSubsetOf (grant)) { return false; } } PermissionSet denied = a.DeniedPermissionSet; if ((denied != null) && !denied.IsEmpty ()) { if (denied.IsUnrestricted ()) return false; CodeAccessPermission refuse = (CodeAccessPermission) a.DeniedPermissionSet.GetPermission (perm.GetType ()); if ((refuse != null) && perm.IsSubsetOf (refuse)) return false; } return true; }
[System.Security.SecuritySafeCritical] // auto-generated public SecurityException(string message, AssemblyName assemblyName, PermissionSet grant, PermissionSet refused, MethodInfo method, SecurityAction action, Object demanded, IPermission permThatFailed, Evidence evidence) : base(message) { PermissionSet.s_fullTrust.Assert(); SetErrorCode(System.__HResults.COR_E_SECURITY); Action = action; if(permThatFailed != null) m_typeOfPermissionThatFailed = permThatFailed.GetType(); FirstPermissionThatFailed = permThatFailed; Demanded = demanded; m_granted = (grant == null ? "" : grant.ToXml().ToString()); m_refused = (refused == null ? "" : refused.ToXml().ToString()); m_denied = ""; m_permitOnly = ""; m_assemblyName = assemblyName; Method = method; m_url = ""; m_zone = SecurityZone.NoZone; if(evidence != null) { Url url = evidence.GetHostEvidence<Url>(); if(url != null) m_url = url.GetURLString().ToString(); Zone zone = evidence.GetHostEvidence<Zone>(); if(zone != null) m_zone = zone.SecurityZone; } m_debugString = this.ToString(true, false); }