Home All Groups Group Topic Archive Search About

VB.NET Role-Based Access

Author
30 Mar 2006 11:19 AM
Sauny
Hi all,

Am trying to implement some security on my program.  This program will
be run on a number of machines across the globe.  I have created a
number of user groups which contain the access priveleges of the
windows users but as they are not builtin groups I cannot do as below!

<PrincipalPermissionAttribute(SecurityAction.Demand, _
   Role := "BUILTIN\Backup Operators")> _

What I need to know is how can I change the Role attribute to look at
my user-defined groups instead of the builtin groups? And as i dont
know the Domains that users are working in, How do I add that to the
attribute????  Really need something like below but it doesnt work:

<PrincipalPermissionAttribute(SecurityAction.Demand, _
   Role := "AllowedCreation")> _

Thank you

Dave

Author
30 Mar 2006 11:31 AM
Dominick Baier [DevelopMentor]
That's why in real applications the PrincipalPermission attribute is rarely
used - there are 2 implications

a) attributes are embedded in meta data at compile time - there is no way
to make them somehow dynamic at runtime
b) this leads to 2 problems - you have to hardcode domain/machine names -
and even BUILTIN\ will not work because those names are localized - and the
role check will fail on a non-english Windows

Builtin\Backup Operators (english) == Vordefiniert\Sicherungsoperatoren (german)

Use the attribute only for checking the Authenticated property

For everything else use Thread.CurrentPrincipal.IsInRole (and in 2.0 the
overload of WindowsPrincipal.IsInRole that takes SIDs also makes you locale
independent)

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> Hi all,
>
> Am trying to implement some security on my program.  This program will
> be run on a number of machines across the globe.  I have created a
> number of user groups which contain the access priveleges of the
> windows users but as they are not builtin groups I cannot do as below!
>
> <PrincipalPermissionAttribute(SecurityAction.Demand, _
> Role := "BUILTIN\Backup Operators")> _
> What I need to know is how can I change the Role attribute to look at
> my user-defined groups instead of the builtin groups? And as i dont
> know the Domains that users are working in, How do I add that to the
> attribute????  Really need something like below but it doesnt work:
>
> <PrincipalPermissionAttribute(SecurityAction.Demand, _
> Role := "AllowedCreation")> _
> Thank you
>
> Dave
>
Author
30 Mar 2006 12:03 PM
Sauny
Thank you Dom, I thought as much.
Author
30 Mar 2006 12:08 PM
Sauny
OK, Another related question.

My application is using the windows users as its user list.  Meaning
you can log onto windows as say Alice but when you come to opening my
application you can log on as either Alice or Bob (Another windows user
on the same machine) I've confirmed Bob's password by using LogonUser,
however when I come to use CurrentPrincipal.IsInRole, it is reverting
back to Alices permissions as she is the logged on user in windows.
How do I make the CurrentPrincipal thing look at Bob instead?  I tried
Impersonating Bob with WindowsPrincipal but also to no avail.
Author
30 Mar 2006 12:14 PM
Dominick Baier [DevelopMentor]
that's an odd design ;)

ok - LogonUser returns a token . you can use this token to create a WindowsIdentity.

wrap the WindowsIdentity with a WindowsPrincipal and assign it to Thread.CurrentPrincipal.

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> OK, Another related question.
>
> My application is using the windows users as its user list.  Meaning
> you can log onto windows as say Alice but when you come to opening my
> application you can log on as either Alice or Bob (Another windows
> user
> on the same machine) I've confirmed Bob's password by using LogonUser,
> however when I come to use CurrentPrincipal.IsInRole, it is reverting
> back to Alices permissions as she is the logged on user in windows.
> How do I make the CurrentPrincipal thing look at Bob instead?  I tried
> Impersonating Bob with WindowsPrincipal but also to no avail.
Author
30 Mar 2006 12:19 PM
Sauny
dont ask me about the design, its not mine.... i was quite happy just
using the current user logged in..... made more sense to me but there
you go!

thanks dom