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
<PrincipalPermi ssion(SecurityA ction.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.Curre ntDomain.SetPri ncipalPolicy(Pr incipalPolicy.W indowsPrincipal )
Dim wp As WindowsPrincipa l = System.Threadin g.Thread.Curren tPrincipal
Dim id As WindowsIdentity = wp.Identity
Dim idType As Type
idType = GetType(Windows Identity)
Dim result As Object = idType.InvokeMe mber("_GetRoles ", _
BindingFlags.St atic Or BindingFlags.In vokeMethod Or
BindingFlags.No nPublic, _
Nothing, id, New Object() {id.Token}, Nothing)
Dim roles() As String = DirectCast(resu lt, String())
Dim i As Integer
For i = 0 To (roles.Length - 1)
If (Not roles(i) Is Nothing) Then
Debug.WriteLine (roles(i).ToStr ing)
Else
Debug.WriteLine ("---")
End If
Next
I see this listing:
RUS\Domain Users
Everyone
CASSICKR1\Debug ger Users
BUILTIN\Adminis trators
BUILTIN\Users
NT AUTHORITY\INTER ACTIVE
NT AUTHORITY\Authe nticated 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.Securit y.SecurityExcep tion' 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/