Role bassed security question.

  • Thread starter Ray Cassick \(Home\)
  • Start date
R

Ray Cassick \(Home\)

I am having a bit of a problem doing something that I was expecting to be
very straight forward. I am trying to declare a Role that needs to be
available before a specific class can be instantiated. My class code is set
up like this:

Imports System.Security
Imports System.Security.Permissions
Imports System.Security.Principal

<PrincipalPermission(SecurityAction.Demand, Role:="RUS\GEM_Admin")> _
Public Class GccAdmin
Public Sub New()
End Sub
End Class

I know that the current account I am logged on with is a member of the
GEM_Admin group because when I run this code:

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
Dim wp As WindowsPrincipal = System.Threading.Thread.CurrentPrincipal
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)
If (Not roles(i) Is Nothing) Then
Debug.WriteLine(roles(i).ToString)

Else
Debug.WriteLine("---")

End If

Next

I see this listing:

RUS\Domain Users
Everyone
CASSICKR1\Debugger Users
BUILTIN\Administrators
BUILTIN\Users
NT AUTHORITY\INTERACTIVE
NT AUTHORITY\Authenticated Users
---
LOCAL
RUS\BackOffice Internet Users
RUS\GEM_Admin
RUS\Domain Admins
RUS\GEM_Users

Can someone give me a hint as to why, when I try to create an instance of
the class tagged for a Role of GEM_Admin I get a 'An unhandled exception of
type 'System.Security.SecurityException' occurred in mscorlib.dll' message
when I try to create aninstance of the class as so:

Dim GccAdmin As GCC.GccAdmin
GccAdmin = New GCC.GccAdmin



--
Raymond R Cassick
CEO / CSA
Enterprocity Inc.
www.enterprocity.com
3380 Sheridan Drive, #143
Amherst, NY 14227
V: 716-316-7537
Blog: http://spaces.msn.com/members/rcassick/
 
R

Ray Cassick \(Home\)

Well I figured it out.. Before I make the call to the GccAdmin constructor I
have to make this call:

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top