Home All Groups Group Topic Archive Search About

How do I check for domain group membership?

Author
29 Sep 2005 6:35 PM
Byron
I have a WinForm app that will run on XP boxes in a Win2003 AD domain named
"GTI.int".  I have several Universal security groups named "ILF_x", one of
which is "ILF_Installer" and I have made myself a member of that group for
development.  There are arrays of security group names associated with menu
items along with other things that should be enabled or disabled based on
security group membership, though my example code only uses the one group
"ILF_Installer" for testing.  I need a method that will iterate the array of
acceptable security group names and return true if the current user is a
member of at least one group, or false otherwise.

I have tried the below listed code without success to test for my membership
in the "ILF_Installer" group.

As always, any help would be greatly appreciated.

--------------------- SNIP
--------------------------------------------------------------
AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal prin = (WindowsPrincipal)Thread.CurrentPrincipal;

Console.WriteLine("Principle:" + prin.Identity.Name);

// The preceding line correctly displays GTI\MyUserName

if ( prin.IsInRole("ILF_Installer") )
   Console.WriteLine("ILF_Installer");

// The preceding block does NOT display "ILF_Installer" as desired.
-------------------------------- SNIP
------------------------------------------

Author
29 Sep 2005 7:23 PM
Dominick Baier [DevelopMentor]
Hello Byron,

you have to use the fully qualified group name - which is DOMAIN\GroupName

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

Show quoteHide quote
> I have a WinForm app that will run on XP boxes in a Win2003 AD domain
> named "GTI.int".  I have several Universal security groups named
> "ILF_x", one of which is "ILF_Installer" and I have made myself a
> member of that group for development.  There are arrays of security
> group names associated with menu items along with other things that
> should be enabled or disabled based on security group membership,
> though my example code only uses the one group "ILF_Installer" for
> testing.  I need a method that will iterate the array of acceptable
> security group names and return true if the current user is a member
> of at least one group, or false otherwise.
>
> I have tried the below listed code without success to test for my
> membership in the "ILF_Installer" group.
>
> As always, any help would be greatly appreciated.
>
> --------------------- SNIP
> --------------------------------------------------------------
> AppDomain myDomain = Thread.GetDomain();
> myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
> WindowsPrincipal prin = (WindowsPrincipal)Thread.CurrentPrincipal;
>
> Console.WriteLine("Principle:" + prin.Identity.Name);
>
> // The preceding line correctly displays GTI\MyUserName
>
> if ( prin.IsInRole("ILF_Installer") )
> Console.WriteLine("ILF_Installer");
> // The preceding block does NOT display "ILF_Installer" as desired.
> -------------------------------- SNIP
> ------------------------------------------
>
Are all your drivers up to date? click for free checkup

Author
29 Sep 2005 8:47 PM
Byron
Thanks for the reply, but even when it is changed to:

if ( prin.IsInRole(@"GTI\ILF_Installer") )
   Console.WriteLine("ILF_Installer");

it still fails the check even though I know I'm a member of that domain
universal security group.  Since my name comes back as "GTI\UserName" I'm
sure I'm logged into the right domain.

Can you think of anything else that could be causing an issue?

Show quoteHide quote
"Dominick Baier [DevelopMentor]" wrote:

> Hello Byron,
>
> you have to use the fully qualified group name - which is DOMAIN\GroupName
>
> ---------------------------------------
> Dominick Baier - DevelopMentor
> http://www.leastprivilege.com
>
> > I have a WinForm app that will run on XP boxes in a Win2003 AD domain
> > named "GTI.int".  I have several Universal security groups named
> > "ILF_x", one of which is "ILF_Installer" and I have made myself a
> > member of that group for development.  There are arrays of security
> > group names associated with menu items along with other things that
> > should be enabled or disabled based on security group membership,
> > though my example code only uses the one group "ILF_Installer" for
> > testing.  I need a method that will iterate the array of acceptable
> > security group names and return true if the current user is a member
> > of at least one group, or false otherwise.
> >
> > I have tried the below listed code without success to test for my
> > membership in the "ILF_Installer" group.
> >
> > As always, any help would be greatly appreciated.
> >
> > --------------------- SNIP
> > --------------------------------------------------------------
> > AppDomain myDomain = Thread.GetDomain();
> > myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
> > WindowsPrincipal prin = (WindowsPrincipal)Thread.CurrentPrincipal;
> >
> > Console.WriteLine("Principle:" + prin.Identity.Name);
> >
> > // The preceding line correctly displays GTI\MyUserName
> >
> > if ( prin.IsInRole("ILF_Installer") )
> > Console.WriteLine("ILF_Installer");
> > // The preceding block does NOT display "ILF_Installer" as desired.
> > -------------------------------- SNIP
> > ------------------------------------------
> >
>
>
>
Author
29 Sep 2005 9:03 PM
carion1
The following works.

public static void Main(string [] args)
{
Show quoteHide quote
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); WindowsPrincipal p = (WindowsPrincipal) Thread.CurrentPrincipal; WindowsIdentity i = (WindowsIdentity) p.Identity; if(p.IsInRole(@"Galactic\IT"))  doit();}--Derek Davisddavi***@gmail.com"Byron" <By***@discussions.microsoft.com> wrote in messagenews:9C75F012-5E70-4D48-8EBE-0489D39BF***@microsoft.com...> Thanks for the reply, but even when it is changed to:>> if ( prin.IsInRole(@"GTI\ILF_Installer") )>   Console.WriteLine("ILF_Installer");>> it still fails the check even though I know I'm a member of that domain> universal security group.  Since my name comes back as "GTI\UserName" I'm> sure I'm logged into the right domain.>> Can you think of anything else that could be causing an issue?>> "Dominick Baier [DevelopMentor]" wrote:>>> Hello Byron,>>>> you have to use the fully qualified group name - which isDOMAIN\GroupName>>>> --------------------------------------->> Dominick Baier - DevelopMentor>> http://www.leastprivilege.com>>>> > I have a WinForm app that will run on XP boxes in a Win2003 AD domain>> > named "GTI.int".  I have several Universal security groups named>> > "ILF_x", one of which is "ILF_Installer" and I have made myself a>> > member of that group for development.  There are arrays of security>> > group names associated with menu items along with other things that>> > should be enabled or disabled based on security group membership,>> > though my example code only uses the one group "ILF_Installer" for>> > testing.  I need a method that will iterate the array of acceptable>> > security group names and return true if the current user is a member>> > of at least one group, or false otherwise.>> >>> > I have tried the below listed code without success to test for my>> > membership in the "ILF_Installer" group.>> >>> > As always, any help would be greatly appreciated.>> >>> > --------------------- SNIP>> > -------------------------------------------------------------->> > AppDomain myDomain = Thread.GetDomain();>> > myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);>> > WindowsPrincipal prin = (WindowsPrincipal)Thread.CurrentPrincipal;>> >>> > Console.WriteLine("Principle:" + prin.Identity.Name);>> >>> > // The preceding line correctly displays GTI\MyUserName>> >>> > if ( prin.IsInRole("ILF_Installer") )>> > Console.WriteLine("ILF_Installer");>> > // The preceding block does NOT display "ILF_Installer" as desired.>> > -------------------------------- SNIP>> > ------------------------------------------>> >>>>>>>
Author
29 Sep 2005 9:09 PM
carion1
Not sure what happened with the other post...

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal p = (WindowsPrincipal) Thread.CurrentPrincipal;
WindowsIdentity i = (WindowsIdentity) p.Identity;
if(p.IsInRole(@"Galactic\IT"))
doit();

--

Derek Davis
ddavi***@gmail.com

Show quoteHide quote
"carion1" <ddavi***@gmail.com> wrote in message
news:%23trvlnTxFHA.3860@TK2MSFTNGP09.phx.gbl...
> The following works.
>
> public static void Main(string [] args)
> {
> AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
> WindowsPrincipal p = (WindowsPrincipal) Thread.CurrentPrincipal;
> WindowsIdentity i = (WindowsIdentity) p.Identity;
> if(p.IsInRole(@"Galactic\IT"))  doit();}--Derek
> Davisddavi***@gmail.com"Byron" <By***@discussions.microsoft.com> wrote in
> messagenews:9C75F012-5E70-4D48-8EBE-0489D39BF***@microsoft.com...> Thanks
> for the reply, but even when it is changed to:>> if (
> prin.IsInRole(@"GTI\ILF_Installer") )>
> Console.WriteLine("ILF_Installer");>> it still fails the check even though
> I know I'm a member of that domain> universal security group.  Since my
> name comes back as "GTI\UserName" I'm> sure I'm logged into the right
> domain.>> Can you think of anything else that could be causing an issue?>>
> "Dominick Baier [DevelopMentor]" wrote:>>> Hello Byron,>>>> you have to
> use the fully qualified group name - which
> isDOMAIN\GroupName>>>> --------------------------------------->> Dominick
> Baier - DevelopMentor>> http://www.leastprivilege.com>>>> > I have a
> WinForm app that will run on XP boxes in a Win2003 AD domain>> > named
> "GTI.int".  I have several Universal security groups named>> > "ILF_x",
> one of which is "ILF_Installer" and I have made myself a>> > member of
> that group for development.  There are arrays of security>> > group names
> associated with menu items along with other things that>> > should be
> enabled or disabled based on security group membership,>> > though my
> example code only uses the one group "ILF_Installer" for>> > testing.  I
> need a method that will iterate the array of acceptable>> > security group
> names and return true if the current user is a member>> > of at least one
> group, or false otherwise.>> >>> > I have tried the below listed code
> without success to test for my>> > membership in the "ILF_Installer"
> group.>> >>> > As always, any help would be greatly appreciated.>> >>>
>  > --------------------- SNIP>>
>  > -------------------------------------------------------------->> >
> AppDomain myDomain = Thread.GetDomain();>> >
> myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);>> >
> WindowsPrincipal prin = (WindowsPrincipal)Thread.CurrentPrincipal;>> >>> >
> Console.WriteLine("Principle:" + prin.Identity.Name);>> >>> > // The
> preceding line correctly displays GTI\MyUserName>> >>> > if (
> prin.IsInRole("ILF_Installer") )>> > Console.WriteLine("ILF_Installer");>>
>  > // The preceding block does NOT display "ILF_Installer" as desired.>>
>  > -------------------------------- SNIP>>
>  > ------------------------------------------>> >>>>>>>
>
Author
30 Sep 2005 4:56 AM
Dominick Baier [DevelopMentor]
Hello Byron,


use

whoami /groups

from the command line to check the exact spelling of the group names...

(whoami is included in w2k3 -> otherwise resource kit)

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

Show quoteHide quote
> Thanks for the reply, but even when it is changed to:
>
> if ( prin.IsInRole(@"GTI\ILF_Installer") )
> Console.WriteLine("ILF_Installer");
> it still fails the check even though I know I'm a member of that
> domain universal security group.  Since my name comes back as
> "GTI\UserName" I'm sure I'm logged into the right domain.
>
> Can you think of anything else that could be causing an issue?
>
> "Dominick Baier [DevelopMentor]" wrote:
>
>> Hello Byron,
>>
>> you have to use the fully qualified group name - which is
>> DOMAIN\GroupName
>>
>> ---------------------------------------
>> Dominick Baier - DevelopMentor
>> http://www.leastprivilege.com
>>> I have a WinForm app that will run on XP boxes in a Win2003 AD
>>> domain named "GTI.int".  I have several Universal security groups
>>> named "ILF_x", one of which is "ILF_Installer" and I have made
>>> myself a member of that group for development.  There are arrays of
>>> security group names associated with menu items along with other
>>> things that should be enabled or disabled based on security group
>>> membership, though my example code only uses the one group
>>> "ILF_Installer" for testing.  I need a method that will iterate the
>>> array of acceptable security group names and return true if the
>>> current user is a member of at least one group, or false otherwise.
>>>
>>> I have tried the below listed code without success to test for my
>>> membership in the "ILF_Installer" group.
>>>
>>> As always, any help would be greatly appreciated.
>>>
>>> --------------------- SNIP
>>> --------------------------------------------------------------
>>> AppDomain myDomain = Thread.GetDomain();
>>> myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
>>> WindowsPrincipal prin = (WindowsPrincipal)Thread.CurrentPrincipal;
>>>
>>> Console.WriteLine("Principle:" + prin.Identity.Name);
>>>
>>> // The preceding line correctly displays GTI\MyUserName
>>>
>>> if ( prin.IsInRole("ILF_Installer") )
>>> Console.WriteLine("ILF_Installer");
>>> // The preceding block does NOT display "ILF_Installer" as desired.
>>> -------------------------------- SNIP
>>> ------------------------------------------

Bookmark and Share

Post Thread options