HighTechTalks DotNet Forums  

Windows authendicate

Dotnet Security microsoft.public.dotnet.security


Discuss Windows authendicate in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Johnny E. Jensen
 
Posts: n/a

Default Windows authendicate - 03-09-2007 , 01:34 PM






Hey

I'am writing a Windows application using C#. I would like to do this:

Application Start:
Is User Authendicated (windows)
does user exists in Administrators or in MyAppGroup ( MyAppGroup = the
AD group for users running the application)

If IsUser Authendicated = False or not in the above groups -> display login
form

I found some code:
System.Security.Principal.WindowsIdentity ident =
System.Security.Principal.WindowsIdentity.GetCurre nt();

System.Security.Principal.WindowsPrincipal prin = new
WindowsPrincipal(ident);

System.Threading.Thread.CurrentPrincipal = prin;

IdentityReferenceCollection col = ident.Groups;

IdentityReference ir = col[1];

In the ident object i'll get the IsAuthendicated property and also i see the
Groups property

The two last lines was just to have a look on a group. I cant get the group
name (like Administrator) how to do that?

Kind regards
Johnny E. Jensen











Reply With Quote
  #2  
Old   
 
Posts: n/a

Default Re: Windows authendicate - 03-17-2007 , 10:19 AM






Try this,

WindowsIdentity ident = WindowsIdentity.GetCurrent();
WindowsPrincipal prin = new WindowsPrincipal(ident);

// User authenticated?
if (ident.IsAuthenticated)
{
// User is administrator or in MyAppGroup?
if (!prin.IsInRole("Administrator") && !prin.IsInRole("MyAppGroup"))
{
// Show login form
}
}
else
{
// Show login form
}

--
Carsten Thomsen
Senior .NET Solutions Architect / Developer / Author
MCAD/MCSD/MCSE/MCTS
"Johnny E. Jensen" <jej (AT) winner-crm (DOT) dk> wrote

Quote:
Hey

I'am writing a Windows application using C#. I would like to do this:

Application Start:
Is User Authendicated (windows)
does user exists in Administrators or in MyAppGroup ( MyAppGroup = the
AD group for users running the application)

If IsUser Authendicated = False or not in the above groups -> display
login form

I found some code:
System.Security.Principal.WindowsIdentity ident =
System.Security.Principal.WindowsIdentity.GetCurre nt();

System.Security.Principal.WindowsPrincipal prin = new
WindowsPrincipal(ident);

System.Threading.Thread.CurrentPrincipal = prin;

IdentityReferenceCollection col = ident.Groups;

IdentityReference ir = col[1];

In the ident object i'll get the IsAuthendicated property and also i see
the Groups property

The two last lines was just to have a look on a group. I cant get the
group name (like Administrator) how to do that?

Kind regards
Johnny E. Jensen













Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.