IsGranted() private method

private IsGranted ( IPermission perm ) : bool
perm IPermission
return bool
Esempio n. 1
0
 internal static IPermission CheckPermissionSet(Assembly a, PermissionSet ps, bool noncas)
 {
     if (ps.IsEmpty())
     {
         return(null);
     }
     foreach (object obj in ps)
     {
         IPermission permission = (IPermission)obj;
         if (!noncas && permission is CodeAccessPermission)
         {
             if (!SecurityManager.IsGranted(a, permission))
             {
                 return(permission);
             }
         }
         else
         {
             try
             {
                 permission.Demand();
             }
             catch (SecurityException)
             {
                 return(permission);
             }
         }
     }
     return(null);
 }
Esempio n. 2
0
        public virtual void Assert()
#endif
        {
            int count = this.Count;

            // we (current frame) must have the permission to assert it to others
            // otherwise we don't assert (but we don't throw an exception)
            foreach (IPermission p in list)
            {
                // note: we ignore non-CAS permissions
                if (p is IStackWalk)
                {
                    if (!SecurityManager.IsGranted(p))
                    {
                        return;
                    }
                }
                else
                {
                    count--;
                }
            }

            // note: we must ignore the stack modifiers for the non-CAS permissions
            if (SecurityManager.SecurityEnabled && (count > 0))
            {
                throw new NotSupportedException("Currently only declarative Assert are supported.");
            }
        }
Esempio n. 3
0
 /// <summary>Determines whether a permission is granted to the caller.</summary>
 /// <returns>true if the permissions granted to the caller include the permission <paramref name="perm" />; otherwise, false.</returns>
 /// <param name="perm">The permission to test against the grant of the caller. </param>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
 /// </PermissionSet>
 public static bool IsGranted(IPermission perm)
 {
     return(perm == null || !SecurityManager.SecurityEnabled || SecurityManager.IsGranted(Assembly.GetCallingAssembly(), perm));
 }
Esempio n. 4
0
 private static bool LinkDemandUnmanaged(Assembly a)
 {
     return(SecurityManager.IsGranted(a, SecurityManager.UnmanagedCode));
 }