ThrowSecurityException() приватный статический Метод

private static ThrowSecurityException ( Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed ) : void
asm System.Reflection.Assembly
granted PermissionSet
refused PermissionSet
rmh System.RuntimeMethodHandle
action SecurityAction
demand Object
permThatFailed IPermission
Результат void
 private static void ThrowSecurityException(object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, object demand, IPermission permThatFailed)
 {
     if (assemblyOrString != null && !(assemblyOrString is RuntimeAssembly))
     {
         throw SecurityException.MakeSecurityException(new AssemblyName((string)assemblyOrString), (Evidence)null, granted, refused, rmh, action, demand, permThatFailed);
     }
     CodeAccessSecurityEngine.ThrowSecurityException((RuntimeAssembly)assemblyOrString, granted, refused, rmh, action, demand, permThatFailed);
 }
Пример #2
0
        internal static bool CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, object assemblyOrString, SecurityAction action, bool throwException)
        {
            IPermission permThatFailed = null;

            if (grants != null)
            {
                grants.CheckDecoded(demands);
            }
            if (refused != null)
            {
                refused.CheckDecoded(demands);
            }
            bool flag = SecurityManager._SetThreadSecurity(false);

            try
            {
                if (!demands.CheckDemand(grants, out permThatFailed))
                {
                    if (!throwException)
                    {
                        return(false);
                    }
                    CodeAccessSecurityEngine.ThrowSecurityException(assemblyOrString, grants, refused, rmh, action, demands, permThatFailed);
                }
                if (!demands.CheckDeny(refused, out permThatFailed))
                {
                    if (!throwException)
                    {
                        return(false);
                    }
                    CodeAccessSecurityEngine.ThrowSecurityException(assemblyOrString, grants, refused, rmh, action, demands, permThatFailed);
                }
            }
            catch (SecurityException)
            {
                throw;
            }
            catch (Exception)
            {
                if (!throwException)
                {
                    return(false);
                }
                CodeAccessSecurityEngine.ThrowSecurityException(assemblyOrString, grants, refused, rmh, action, demands, permThatFailed);
            }
            finally
            {
                if (flag)
                {
                    SecurityManager._SetThreadSecurity(true);
                }
            }
            return(true);
        }
Пример #3
0
        private static void ThrowSecurityException(object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, object demand, IPermission permThatFailed)
        {
            if (assemblyOrString == null || assemblyOrString is RuntimeAssembly)
            {
                CodeAccessSecurityEngine.ThrowSecurityException((RuntimeAssembly)assemblyOrString, granted, refused, rmh, action, demand, permThatFailed);
                return;
            }
            AssemblyName asmName = new AssemblyName((string)assemblyOrString);

            throw SecurityException.MakeSecurityException(asmName, null, granted, refused, rmh, action, demand, permThatFailed);
        }
Пример #4
0
        internal static bool CheckHelper(PermissionSet grantedSet, PermissionSet refusedSet, CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh, object assemblyOrString, SecurityAction action, bool throwException)
        {
            if (permToken == null)
            {
                permToken = PermissionToken.GetToken(demand);
            }
            if (grantedSet != null)
            {
                grantedSet.CheckDecoded(permToken.m_index);
            }
            if (refusedSet != null)
            {
                refusedSet.CheckDecoded(permToken.m_index);
            }
            bool flag = SecurityManager._SetThreadSecurity(false);

            try
            {
                if (grantedSet == null)
                {
                    if (!throwException)
                    {
                        return(false);
                    }
                    CodeAccessSecurityEngine.ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
                }
                else if (!grantedSet.IsUnrestricted())
                {
                    CodeAccessPermission grant = (CodeAccessPermission)grantedSet.GetPermission(permToken);
                    if (!demand.CheckDemand(grant))
                    {
                        if (!throwException)
                        {
                            return(false);
                        }
                        CodeAccessSecurityEngine.ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
                    }
                }
                if (refusedSet != null)
                {
                    CodeAccessPermission codeAccessPermission = (CodeAccessPermission)refusedSet.GetPermission(permToken);
                    if (codeAccessPermission != null && !codeAccessPermission.CheckDeny(demand))
                    {
                        if (!throwException)
                        {
                            return(false);
                        }
                        CodeAccessSecurityEngine.ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
                    }
                    if (refusedSet.IsUnrestricted())
                    {
                        if (!throwException)
                        {
                            return(false);
                        }
                        CodeAccessSecurityEngine.ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
                    }
                }
            }
            catch (SecurityException)
            {
                throw;
            }
            catch (Exception)
            {
                if (!throwException)
                {
                    return(false);
                }
                CodeAccessSecurityEngine.ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
            }
            finally
            {
                if (flag)
                {
                    SecurityManager._SetThreadSecurity(true);
                }
            }
            return(true);
        }