Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsAuthenticationAuthenticationWindows authentication and impersonationWindows authentication and impersonation
Previous
 
Next
New Post
9/17/2007 6:58 AM
 

Hi all,

I am developing a module to access our CRM corporate database (custom). Right now the front end for this database is MS Access but we are trying to get rid of it and make the front-end web-based, so we decided to use the framework provided by DNN to access our data (this data is on a different SQL database, not into the DotNetNuke database, and has its own user permissions, views, SPs, and so on). I have set DNN to use Windows Authentication, but it seems that after the initial automatic logon (provided by admin/Security/WindowsSignin.aspx) the rest of the navigation uses Form Authentication. I want, however, DNN to be able to impersonate the user currently browsing the site. Somewhere in our code, just before running our database queries we need to something like the example shown in: http://support.microsoft.com/kb/306158/en-us

Dim impersonationContext As System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity

currentWindowsIdentity = CType(HttpContext.Current.User.Identity, System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()

'Insert your code that runs under the security context of the authenticating user here.

impersonationContext.Undo()

This throws an exception since at runtime HttpContext.Current.User.Identity is a FormsIdentity object and it cannot be converted into a WindowsIdentity object. Is this WindowsIdentity object supposedly created by WindowsSignin.aspx stored somewhere that can be accessible afterwards? Any way to re-create a WindowsIdentity based on the FormsIdentity (which is in fact created after the windows authentication is done).

Summing up, is there any way to temporarily impersonate to the current user, so that we can execute custom queries to our database (with its own permissions) on behalf of this user and then go back to IWAM_MACHINE account to run the rest of the DNN code?

Thanks to everyone in advance.

 
New Post
9/17/2007 11:30 AM
 

In your web.config there is a section where you can change the Authentication to Windows. Just uncomment that section and comment out the Forms authentication section. I haven't tested it to see if there are other considerations that you need to worry about so I'd give this a test on a development computer first.

 
New Post
9/18/2007 2:45 AM
 

Mike: Thanks for your suggestion but that was the obvious thing that we tried first:

When you disable Forms authentication in web.config and set it to Windows auth (and impersonate=true), the automatic creation of user acounts in DNN does not work anymore, even though the users are authenticated correctly in IIS and in our SQL database, DNN is not aware of them. Besides, we don't want the whole portal to require the users to exist in Active Directory, we just want this module to connect to our database IF the user has the rights to do it, but leave the rest of the portal untouched (using its default settings where possible). More side effects are that we cannot either log-in with admin nor host accounts, we need to set web.config again back to Forms auth, whenever we need to login with those accounts (to make an update to any module, etc.).

Even though it migth the simple solution at first sight, we'd rather be able to do the impersonation at runtime whenever we need to access our database. If we achieve this now, this solution will give us less headaches afterwards.

Any other idea? Thanks again and regards.

 
New Post
11/30/2007 3:23 PM
 

Did anyone ever figure out how to get a module to impersontate the windows account of the authenitcated user at runtime.  We are using AD authentication too, so we can't switch to Windows authentication in the web.config and set impersonation there.

 
New Post
7/8/2010 11:28 AM
 
Solved: I'm updating this old thread with a solution for other "searchers" with the problem. Even with , you can set . If your IIS server has "Integrate Windows authentication" checked, then you can impersonate a user using this code (even though DNN authenticated via forms). Impersonation allows you to access network resources (aka files) as that user. WindowsIdentity winIdent = WindowsIdentity.GetCurrent(); WindowsImpersonationContext winImpersonation = winIdent.Impersonate(); // .. do stuff as windows-authenticated user. winImpersonation.Undo(); Note that if you are accessing another web site using as the user, you must use this code to pass the windows credentials: WebRequest usersRequest = System.Net.HttpWebRequest.Create(someURL); usersRequest.Credentials = CredentialCache.DefaultCredentials; WebResponse theResponse = usersRequest.GetResponse(); An excellant article on authentication (including a table showing user in different and modes) is below. It's also part of a good parent set of articles on ASP.Net security. http://msdn.microsoft.com/en-us/library/aa480475.aspx Good luck, Mark
 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsAuthenticationAuthenticationWindows authentication and impersonationWindows authentication and impersonation


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out