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. Principal Permissions

Principal Permissions

Scheduled Pinned Locked Moved C#
questionc++help
2 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
    Mauricio Ritter
    wrote on last edited by
    #1

    I'm trying to protect one of my classes using PrincipalPermissionAttribute. I'm setting it to only allow the code to execute only if a specific user is trying to run it. Here is the class declaration: [PrincipalPermissionAttribute(SecurityAction.Demand, Authenticated:=True, name:="MYDOMAIN\\Mauricio")] public class foo This code works fine but the problem is that it allows the usage of an GenericPrincipal object and I want it to use a WindowsPrincipal object. Allow it to use a GenericPrincipal will anyone to create a GenericPrincipal with that user name and execute the code. Like this: GenericIdentity oIdent = new GenericIdentity("MYDOMAIN\\Mauricio", "NTLM"); GenericPrincipal oPrinc = new GenericPrincipal(oPrinc, null); foo oFoo = new foo(); My question is: is there anyone to demand that a code only accepts WindowsPrincipals, and don't accept GenericPrincipals ? :wtf: thanks Mauricio Ritter - Brazil Sonorking now: 100.13560 MRitter
    English is not my native language so, if you find any spelling erros in my posts, please let me know.

    H 1 Reply Last reply
    0
    • M Mauricio Ritter

      I'm trying to protect one of my classes using PrincipalPermissionAttribute. I'm setting it to only allow the code to execute only if a specific user is trying to run it. Here is the class declaration: [PrincipalPermissionAttribute(SecurityAction.Demand, Authenticated:=True, name:="MYDOMAIN\\Mauricio")] public class foo This code works fine but the problem is that it allows the usage of an GenericPrincipal object and I want it to use a WindowsPrincipal object. Allow it to use a GenericPrincipal will anyone to create a GenericPrincipal with that user name and execute the code. Like this: GenericIdentity oIdent = new GenericIdentity("MYDOMAIN\\Mauricio", "NTLM"); GenericPrincipal oPrinc = new GenericPrincipal(oPrinc, null); foo oFoo = new foo(); My question is: is there anyone to demand that a code only accepts WindowsPrincipals, and don't accept GenericPrincipals ? :wtf: thanks Mauricio Ritter - Brazil Sonorking now: 100.13560 MRitter
      English is not my native language so, if you find any spelling erros in my posts, please let me know.

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

      The only way you'll be able to do this is to extend the PrincipalPermission and PrincipalPermissionAttribute classes, or create your own. You could do the very same things, except check the Type against WindowsPrincipal that you get back from Thread.CurrentPrincipal. The current implementation doesn't care about the Type, so long as it implements IPrincipal. If you want to know exactly what the current classes mentioned above are doing, you can use ildasm.exe that ships with the .NET Framework SDK if you know IL (and it wouldn't hurt to know anyway), or use a good decompiler like .NET Reflector[^].

      Microsoft MVP, Visual C# My Articles

      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