I have a C# application that will use corporate Active Directory for authentication for half the users and a custom authentication method for the other half.
I already managed to authenticate users in AD using DirectoryEntry, DirectorySearcher, etc. and also have my custom authentication working.
However, I want to know if a user has already been logged in his computer using the corporate domain, then that user won’t be shown any Logon form and has to pass to the application.
I know I can use WindowsIdentity.GetCurrent().IsAuthenticated, but that returns “true” for both the locally logged users and the Domain logged users.
I want to know how can I tell apart the first from the latest.
(Note: this is a desktop application)
I also maintain a winforms desktop application that uses active-directory for in office users and supports non-office users as well.
This may be more then your asking for but since I have the same scenario as you I’m going to offer it anyway because it came together in a kind of a nice way, where I really didn’t write too much code and has been working well.
I’m sure others might have done this with a package as opposed to rolling their own – and to be honest I will probably go that route the next time I have this requirement…
Here it is:
Conceptually I took a cue from ASP.NET and broke security into two logical pieces:
Authentication – Who is this user?
Authorization – Can the user do this?
My implementation uses a simple database:
Here’s a snippett from the main form of my application:
And here’s the supporting utility code.
Finally, I administer it with with an ASP.NET scaffold site: