473,472 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Checking if User is in Role

mc
I would like to check if a user is currently a member of a Local Group on the server. I am able to
do the test for the current user and all is ok, however I would like to be able to take a list of
users from a table in the database and check if the user is in the specified group. is it possible
to take a username (as a string) and create an instance of IPricipal for that user? or achive by any
other method?

Regards
MC
Apr 26 '07 #1
6 1789

"mc" <mc@community.nospamwrote in message
news:46********@mail.hmgcc.gov.uk...
>I would like to check if a user is currently a member of a Local Group on
the server. I am able to do the test for the current user and all is ok,
however I would like to be able to take a list of users from a table in the
database and check if the user is in the specified group. is it possible to
take a username (as a string) and create an instance of IPricipal for that
user? or achive by any other method?
The following code returned true if UserName is a member of a Power Users
group.
DirectoryEntry entryRoot = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer",
Environment.MachineName +"\\" + SuperUserName, SuperUserPassword,
System.DirectoryServices.AuthenticationTypes.Reado nlyServer);
DirectoryEntry userEntry = entryRoot.Children.Find(UserName, "user");
DirectoryEntry objGroup = entryRoot.Children.Find("Power Users", "group");
bool isMember = (bool)objGroup.Invoke("IsMember", new object[] {
userEntry.Path.ToString() });

SuperUserName is a local user
Apr 26 '07 #2
Hi MC,

As Alexey has suggested, if you do not have the full credentials of a user
account, y ou may try using ADSI to query the user groups. Or if the server
is in a windows 2003 domain, you can also have a look at the S4U based
kerberos authentication which allow the server to construct a windows token
based on the user principal name(rather than full username/password
credentials):

#Exploring S4U Kerberos Extensions in Windows Server 2003
http://msdn.microsoft.com/msdnmag/is...ecurityBriefs/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 27 '07 #3
mc
When I try and use the S4U solution I get some error about no active logon session and the ADSI
approach didn't seem very obvious either, I have no time to investigate this properly as it's only a
"Nice to Have" requirement. I might reconsider getting this working at a later date. (if time permits)

Thanks for you assistance.
MC
Steven Cheng[MSFT] wrote:
Hi MC,

As Alexey has suggested, if you do not have the full credentials of a user
account, y ou may try using ADSI to query the user groups. Or if the server
is in a windows 2003 domain, you can also have a look at the S4U based
kerberos authentication which allow the server to construct a windows token
based on the user principal name(rather than full username/password
credentials):

#Exploring S4U Kerberos Extensions in Windows Server 2003
http://msdn.microsoft.com/msdnmag/is...ecurityBriefs/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Apr 30 '07 #4
On Apr 30, 10:52 am, mc <m...@community.nospamwrote:
When I try and use the S4U solution I get some error about no active logon session and the ADSI
approach didn't seem very obvious either, I have no time to investigate this properly as it's only a
"Nice to Have" requirement. I might reconsider getting this working at a later date. (if time permits)
Do you mean that the code above is not working?

Apr 30 '07 #5
mc
Alexey Smirnov wrote:
On Apr 30, 10:52 am, mc <m...@community.nospamwrote:
>>When I try and use the S4U solution I get some error about no active logon session and the ADSI
approach didn't seem very obvious either, I have no time to investigate this properly as it's only a
"Nice to Have" requirement. I might reconsider getting this working at a later date. (if time permits)


Do you mean that the code above is not working?
It is not possible to store the Super User Password in the Code, therefore I don't think I would be
able to use the approach you offered.

Regards
MC
May 2 '07 #6
On May 2, 10:37 am, mc <m...@community.nospamwrote:
Alexey Smirnov wrote:
On Apr 30, 10:52 am, mc <m...@community.nospamwrote:
>When I try and use the S4U solution I get some error about no active logon session and the ADSI
approach didn't seem very obvious either, I have no time to investigate this properly as it's only a
"Nice to Have" requirement. I might reconsider getting this working at a later date. (if time permits)
Do you mean that the code above is not working?

It is not possible to store the Super User Password in the Code, therefore I don't think I would be
able to use the approach you offered.

Regards

MC
It can be configured in the web.config

Another way I know is a good old COM+ that you can run with a fixed
identity.

May 2 '07 #7

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

Similar topics

1
by: DC_DBA | last post by:
I want to 'grant sysdba to a user' for an application. (At least that is what I believe so far after having had this problem dumped on me 2 days ago.) The support we get from the application vendor...
0
by: leecho | last post by:
Hi, I confuse. I had a role named lsc_role with certain object privs. if i run this query : select role from dba_role; ROLE ----------------------- JAVADEBUGPRIV EJBCLIENT JAVA_ADMIN
1
by: Tom Dauria | last post by:
I have a SQL database with an Access front end. In the database I have a read only and a read write role. When a read only user opens the database I want all the fields on the form to be locked...
2
by: Edward Estrada | last post by:
I would like to determine if a particular user has sysadmin server role. Is there a way to do this via the connection string? Currently our code checks if a login is valid using SQLDriverConnect,...
2
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some...
8
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...
3
by: shapper | last post by:
Hello, How to I check if a user is authenticated and if it is what is its role? I am using Asp.Net 2.0 and forms authentication. Thanks, Miguel
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
4
by: John Devlon | last post by:
Hi, I've created a small application with some user-authentication and roles. I would like to show/hide some navigation parts based on the users role. Could someone please tell me what the...
2
by: Anthony Smith | last post by:
I have a user object that is set when a user logs in. There are also permissions that I get about the user from a web service. Currently I take the results from those web services and store them as...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.