Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Granting/Demanding a custom permission

Granting/Demanding a custom permission

Scheduled Pinned Locked Moved C#
questiondata-structuressecurityhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike Hodnick
    wrote on last edited by
    #1

    I've created a very, very simple custom CodeAccessPermission class. It basically does nothing more than override the necessary base class methods and implement IUnrestrictedPermission. In another class, I want to perform an imperative security check to ensure the caller has been granted my custom permission: public static void ReadData() { CustomPermission MyPermission = new CustomPermission(PermissionState.Unrestricted); MyPermission.Demand(); //perform method stuff... } The problem is, I haven't done anything to specifically grant my application this permission, and when I call Demand no SecurityException is thrown. But, I want a SecurityException to be thrown since I have not explicitly granted any code that permission. Why does this happen? - Mike ------------------------- "No human being would stack books like that." - Dr. Venkman

    H 1 Reply Last reply
    0
    • M Mike Hodnick

      I've created a very, very simple custom CodeAccessPermission class. It basically does nothing more than override the necessary base class methods and implement IUnrestrictedPermission. In another class, I want to perform an imperative security check to ensure the caller has been granted my custom permission: public static void ReadData() { CustomPermission MyPermission = new CustomPermission(PermissionState.Unrestricted); MyPermission.Demand(); //perform method stuff... } The problem is, I haven't done anything to specifically grant my application this permission, and when I call Demand no SecurityException is thrown. But, I want a SecurityException to be thrown since I have not explicitly granted any code that permission. Why does this happen? - Mike ------------------------- "No human being would stack books like that." - Dr. Venkman

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You've hopefully already read this, but be sure you're familiar with the content described in Creating Your Own Code Access Permissions[^] in the .NET Framework SDK. Also be sure that your permission class is installed into the GAC and granted FullTrust permissions, as is documented (and for reasons that should be obvious). If your application is granted FullTrust permissions, than it really doesn't matter what permissions you demand - they will all succeed. Also, make sure that any callers higher in the stack haven't asserted that permissions (if they have it, they can grant it for children).

      Microsoft MVP, Visual C# My Articles

      M 1 Reply Last reply
      0
      • H Heath Stewart

        You've hopefully already read this, but be sure you're familiar with the content described in Creating Your Own Code Access Permissions[^] in the .NET Framework SDK. Also be sure that your permission class is installed into the GAC and granted FullTrust permissions, as is documented (and for reasons that should be obvious). If your application is granted FullTrust permissions, than it really doesn't matter what permissions you demand - they will all succeed. Also, make sure that any callers higher in the stack haven't asserted that permissions (if they have it, they can grant it for children).

        Microsoft MVP, Visual C# My Articles

        M Offline
        M Offline
        Mike Hodnick
        wrote on last edited by
        #3

        I overlooked the subtle fact that all code on the local computer gets Full Trust by default. That's all. - Mike ------------------------- "No human being would stack books like that." - Dr. Venkman

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups