Enum All Roles in a Principal?

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Enum All Roles in a Principal?


    I know how to do ..IsInRole() to test if a user is in a particular
    role.

    How do I enumerate all of the roles currently attached to my principal
    instance? WindowsPrincipal or GenericPrincipal.

    Thanks.

    localhost Guest

  2. Similar Questions and Discussions

    1. Web Service w custom Principal
      We have a class that Implements IPrincipal (System.Security.Principal.IPrincipal). We have a business logic class library assembly that checks the...
    2. Custom Principal
      Hi, I use Custom Principal and it works well on my PC (Localhost). When I deploy it at my hosting service it fails. I print out...
    3. Custom Windows Authentication Principal?
      Ok here's the situation, I have several intranet applications at this company that use windows authentication. Now when people open the...
    4. Setting Principal for HttpWorkerRequest
      re: http://www.dotnet247.com/247reference/msgs/31/159270.aspx (neither my news server, nor microsoft's seems to still carry this thread) I am...
    5. Set Windows Principal
      Hi, My current legacy asp/becoming-asp.net application uses IIS Windows Authentication at present. What I need to do is let a user coming from...
  3. #2

    Default RE: Enum All Roles in a Principal?

    Hi Localhost,


    Thanks for posting in the community!
    Based on my understanding, you're wanting to manually get the role lists of
    a certain IPrinciple object such as WindowsPrincipal or GenreicPrincipal

    Based on my research, the dotnet IPrincipal only provide the IsInRole
    interface to let use validate a certain role via name. It doesn't provide
    the get role lists method. But we can define a custom Principal
    class(which has the interface you want) and replace the original Principal
    object at runtime. This is what many ones have done. Here is a tech article
    on this means:
    #Custom roles for WindowsPrincipals in ASP.NET
    [url]http://weblogs.asp.net/bhickman/archive/2003/02/07/2018.aspx[/url]

    In addition, If you do want to get the roles of a WindowsIdentity, there is
    a means using reflection APIs to invoke the private
    WindowsIdentity._GetRoles method so that you can see what the actual groups
    for the WindowsIdentity are. This
    has saved me lots of trouble in the past. VB.NET code sample here:
    --------------------------------------------
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    Dim wp As WindowsPrincipal = HttpContext.Current.User
    Dim id As WindowsIdentity = wp.Identity
    Dim idType As Type


    idType = GetType(WindowsIdentity)
    Dim result As Object = idType.InvokeMember("_GetRoles", _
    BindingFlags.Static Or BindingFlags.InvokeMethod Or
    BindingFlags.NonPublic, _
    Nothing, id, New Object() {id.Token}, Nothing)

    Dim roles() As String = DirectCast(result, String())

    Dim i As Integer
    For i = 0 To roles.Length - 1

    Response.Write("<br>" + roles(i))
    Next

    End Sub
    ----------------------------------------------
    And since the above means may cause unexpected security issues, we don't
    recommend that it be used. :)


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    [url]http://msdn.microsoft.com/asp.net/whidbey/default.aspx[/url]

    Steven Cheng[MSFT] Guest

  4. #3

    Default Re: Enum All Roles in a Principal?

    You can implement custom IIDentity and IPrincipal and do whatever you want
    with it.

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT06.asp[/url]


    "localhost" <primpilus@cohort.ces> wrote in message
    news:hctu30tujssnib50pruo5937c2itkuia3i@4ax.com...
    >
    > I know how to do ..IsInRole() to test if a user is in a particular
    > role.
    >
    > How do I enumerate all of the roles currently attached to my principal
    > instance? WindowsPrincipal or GenericPrincipal.
    >
    > Thanks.
    >

    Beginner Guest

  5. #4

    Default RE: Enum All Roles in a Principal?

    Hi Localhost,

    Have you had a chance to try out my suggestion or have you got any further
    ideas on this issue? If you need any further assistance ,please feel free
    to post here.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    [url]http://msdn.microsoft.com/asp.net/whidbey/default.aspx[/url]

    Steven Cheng[MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139