impersonation

How to call LogonUser() to get a non-restricted full token inside a Windows Service with UAC enabled?

耗尽温柔 提交于 2019-11-26 14:43:24
问题 I am running a WindowsService on Windows Server 2012 and it needs to impersonate a domain admin user (who is also added to the local administrators group on the machine). UAC is enabled on the system and Calling LogonUser using the credentials with a LogonType of LOGON32_LOGON_INTERACTIVE, seems to return a restricted token instead of a full token. This is causing the administrative task i'm trying to do to fail. What is the right way to call LogonUser in this situation so that a full token

Run Code as a different user

旧城冷巷雨未停 提交于 2019-11-26 14:33:30
Is there a way to tell my code to run as a different user? I am calling NetUserSetInfo via a PInvoke and I need to call it as a different user. Is there a way to do that? Richard Berg Impersonation requires calling some native APIs (namely, LogonUser) so it's probably not worth posting 3 pages of wrapper code. This page has a complete working sample: http://platinumdogs.wordpress.com/2008/10/30/net-c-impersonation-with-network-credentials/ Note that impersonation has important security considerations. Make sure you follow best practices. Milan Matějka Probably the best and the cleanest code

Impersonating a Windows user

情到浓时终转凉″ 提交于 2019-11-26 11:14:50
问题 I am using the code to impersonate a user account to get access to a file share. public class Impersonator : IDisposable { #region Public methods. // ------------------------------------------------------------------ /// <summary> /// Constructor. Starts the impersonation with the given credentials. /// Please note that the account that instantiates the Impersonator class /// needs to have the \'Act as part of operating system\' privilege set. /// </summary> /// <param name=\"userName\">The

How to get Windows user name when identity impersonate=“true” in asp.net?

◇◆丶佛笑我妖孽 提交于 2019-11-26 11:11:24
I'm creating an intranet asp.net mvc application that everyone in the company should have access to. I need to run the website impersonated for database access etc., but I want to know who each user is. When I look at Page.User.Identity.Name it's blank. Is it possible to get the user's windows account name even though the site is running impersonated? Edit: Here's a little more info. I have a site in IIS 6 running with anonymous access enabled. The site is running under a system account that has access to the database (because all of the employees do not have access to the database). My web

Impersonate using Forms Authentication

纵然是瞬间 提交于 2019-11-26 10:35:01
问题 I have an ASP.NET site that must use Forms Authentication and not Windows Authentication to access a ActiveDirectoryMembershipProvider . The site must use forms because they need a designed input form instead of the browser authentication popup that Windows authentication uses. The site needs to impersonate the user logged in via Active Directory to access user specific files. However, the WindowsIdentity.GetCurrent() is not the same as the HttpContext.Current.User.Identity although my web

Start a .Net Process as a Different User

流过昼夜 提交于 2019-11-26 10:34:47
I want to start a Process with Admin rights. When I run the code below the Process complains saying it needs Admin rights: public class ImpersonationHelper : IDisposable { IntPtr m_tokenHandle = new IntPtr(0); WindowsImpersonationContext m_impersonatedUser; #region Win32 API Declarations const int LOGON32_PROVIDER_DEFAULT = 0; const int LOGON32_LOGON_INTERACTIVE = 2; //This parameter causes LogonUser to create a primary token. [DllImport("advapi32.dll", SetLastError = true)] public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int

Can I turn off impersonation just in a couple instances

此生再无相见时 提交于 2019-11-26 08:23:46
问题 I have an app that has impersonation used throughout. But when a user is logged in as an admin, a few operation require them to write to the server itself. Now if these users do not have rights on the actual server (some don\'t) it will not let them write. What I want to do is turn off impersonation for just a couple commands. Is there a way to do something like this? using(HostingEnvironment.Impersonate.Off()) //I know this isn\'t a command, but you get the idea? Thank you. 回答1: Make sure

How can I fix the Kerberos double-hop issue?

只谈情不闲聊 提交于 2019-11-26 06:36:52
问题 I\'m having some trouble calling a web service from within a web application and I was hoping someone here might be able to help. From what I can tell, this seems to have something to do with the Kerberos double-hop issue. However, if it is, I\'m not sure what to do to actually fix the problem. To make things harder, I don\'t have the proper permissions to make changes to Active Directory accounts, so I need to know what to ask for when requesting changes. In my situation, I need to pass the

Impersonation in ASP.NET MVC

試著忘記壹切 提交于 2019-11-26 05:29:21
问题 I have a MVC web application on an intranet and want to be able to create files on our FTP server to send to outside partners. The code for impersonation uses the WindowsImpersonationContext. System.Security.Principal.WindowsImpersonationContext impersonationContext; impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate(); StreamWriter sw = System.IO.File.CreateText(\"PathOnFTPServer\"); sw.Write(\"data\"); impersonationContext.Undo(); Here\'s what\'s

Run Code as a different user

半世苍凉 提交于 2019-11-26 03:57:02
问题 Is there a way to tell my code to run as a different user? I am calling NetUserSetInfo via a PInvoke and I need to call it as a different user. Is there a way to do that? 回答1: Impersonation requires calling some native APIs (namely, LogonUser) so it's probably not worth posting 3 pages of wrapper code. This page has a complete working sample: http://platinumdogs.wordpress.com/2008/10/30/net-c-impersonation-with-network-credentials/ Note that impersonation has important security considerations