473,569 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Role bassed security question.

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/
Nov 21 '05 #1
1 1084
Well I figured it out.. Before I make the call to the GccAdmin constructor I
have to make this call:

AppDomain.Curre ntDomain.SetPri ncipalPolicy(Pr incipalPolicy.W indowsPrincipal )

"Ray Cassick (Home)" <rc************ @enterprocity.c om> wrote in message
news:er******** *****@TK2MSFTNG P15.phx.gbl...
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/

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2336
by: craig | last post by:
I am working on my first .NET development project that involves custom role-based security per the project requirements. This lead to a general design issue this week that really caused us some concern. I have described the situation below because we are very curious to see what other, more experienced, developers might suggest. The specific...
0
1366
by: ChrisB | last post by:
Hello: I am a member of a team creating a .NET application, and we seem to have run into an issue when trying to implement role based security. Our application makes use of a fairly common (table based) security model in which privileges are assigned to roles, which are then assigned users. So, for example, the user "JSmith" may be...
9
5272
by: Thom Little | last post by:
I seem to (once again) be missing something pretty basic. I am running under Windows XP Professional Service Pack 1 with all Hotfixes installed and Visual Studio .NET 2003 in Debug mode. The following reports "You have the >Administrator< role." using System.Security.Principal ; using System.Security.Permissions ;
4
2916
by: hazz | last post by:
If I successfully run a VS.NET app which includes the following; ************************** APP 1 **************************** m_iIdnt = new System.Security.Principal.GenericIdentity(t.UserName,"MyAuthentication"); //user and My authentication type added to Identity string roles = {"Chief Cook and Bottle Washer", "Master Gardener"};
3
2012
by: Mike Logan | last post by:
Questions about Role Based Security in ASP.Net: I have a few questions about role based security in an ASP.Net application. Below are some points about our system: - We have a hierarchical roles system stored in a database. - We are also using Windows for authentication. - Page - Role relationships are also held in a database. - We have...
3
1207
by: Ray Cassick \(Home\) | last post by:
I have some code that looks like this for one of my classes: 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
8
4888
by: Mark White | last post by:
Hey everyone I'm having a great deal of problems finding this information through google and yahoo, so I turn to you on this. I have a Windows app running on XP. I am able to caputre the user's Name property in the WindowsPrincipal's IIdentity interface. Where can I find the role that the user is assigned for the current login? I only...
7
2991
by: nugget | last post by:
Role-based security for an ASP/ASP.NET mixed environment Hello: My co-worker and I have been charged with designing role-based security for our intranet. The technologies we have to work with are ASP and ASP.NET. This security design must support *both* technologies. Currently, we have a successful collection of both ASP and ASP.NET...
3
2000
by: RedHair | last post by:
I use the Form Authentication and Role base security to secure one ASP.NET 3.5 appication. Below are security settings in web.config <location path="testAdmin.aspx"> <system.web> <authorization> <allow roles="Admin"/> <deny users="*"/> </authorization>
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.