Tag: impersonation

模拟在Powershell中使用WindowsIdentity抛出FileNotFoundException

我在PowerShell和C#中执行模拟遇到了一些奇怪的错误。 执行以下代码不会显示任何错误。 PSObject result = null; using (PowerShell powershell = PowerShell.Create()) { RunspaceConfiguration config = RunspaceConfiguration.Create(); powershell.Runspace = RunspaceFactory.CreateRunspace(config); powershell.Runspace.Open(); powershell.AddScript(String.Format(CmdletMap[PSVocab.OsBootTime], this.ComputerName)); result = powershell.Invoke().First(); powershell.Runspace.Close(); } return DateTime.Parse(result.ToString()); CmdletMap[PSVocab.OsBootTime]的PS脚本只是: $info = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer ; $info.ConvertToDateTime($info.LastBootUpTime) 上面的C#代码在本地工作正常。 但是,一旦我使用Windows模拟这样的块,就像这样: WindowsIdentity ImpersonatedIdentity = new WindowsIdentity(ImpersonateUserName); WindowsImpersonationContext impersonatedContext = ImpersonatedIdentity.Impersonate(); try { PSObject result = […]

ASP.NET CORE 1.0,模拟

我正在写一个Intranet应用程序。 project.json中的目标框架是dnx451。 这是我的发布命令: dnu publish –runtime dnx-clr-win-x86.1.0.0-rc1-update1 –no-source Database Connection字符串: Server=name;Database=name;Trusted_Connection=True; 我正在尝试模拟数据库访问,但它无法正常工作。 当我启动应用程序时,我的Windows用户被识别,它在右上角显示Hello,Domain \ Username。 一旦我尝试访问数据库,我就会收到错误“登录用户域\ Computername失败”。 如果我在我的用户下运行应用程序池,那么一切正常。 IIS:.NET CLR Versio是v4.0,托管Pipline模式Classic和Identity是ApplicationPoolIdentity。 网站身份validation:启用了ASP.NET模拟和Windows身份validation。 我需要做些什么才能改变模仿终于有效?

是否可以使用c#中的Exchange Web服务分配角色?

是否可以使用c#中的Exchange Web服务分配角色? 像您一样以编程方式自动添加角色ApplicationImpersonation并将角色分配给Office 365 Exchange中的用户?

FilersystemWatcher在模拟用户下运行

我有一个c#winform应用程序,它在本地帐户下运行但需要监视域上的文件夹。 我使用稍微修改过的代码从这里复制文件,并且工作正常。 可以使用类似的代码与FileSystemWatcher设置模拟,以便我可以监控域上的文件夹吗?

如何在没有用户密码的情况下获取Alfresco登录票证,但使用用户主体名称(UPN)模拟用户

我正在编写一个DLL,它具有在不使用用户密码的情况下获取Alfresco登录票证的function,仅使用用户主体名称(UPN)。 我正在调用alfresco REST API服务/ wcservice 。 我在Alfresco使用NTLM。 我正在冒充使用WindowsIdentity构造函数的用户,如http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity所述 。 我检查并且用户被正确模拟(我检查了WindowsIdentity.GetCurrent().Name属性)。 在模仿用户之后,我尝试使用CredentialsCache.DefaultNetworkCredentials制作HttpWebRequest并设置其凭据。 我收到错误: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() 当我使用new NetworkCredential(“username”, “P@ssw0rd”)来设置请求凭据时,我获得了Alfresco登录票证( HttpStatusCode.OK ,200)。 有没有办法可以在没有用户密码的情况下获得Alfresco登录票? 这是我正在使用的代码: private string GetTicket(string UPN) { WindowsIdentity identity = new WindowsIdentity(UPN); WindowsImpersonationContext context = null; try { context = identity.Impersonate(); MakeWebRequest(); } catch (Exception e) { return […]

Parallel.ForEach()更改模拟上下文

今天我们将新创建的ASP.NET应用程序部署到服务器,很快我们意识到存在一个与安全相关的奇怪问题导致应用程序崩溃。 这是一个内部应用程序,我们使用Impersonation来管理用户访问资源的方式。 但是,当用户尝试访问他们完全控制的文件夹时,应用程序会抛出“拒绝访问”exception。 exception实际上是一个AggregateException并且被抛出一个方法,该方法使用Parallel.ForEach枚举列表并在正文内部,它尝试访问该文件夹,但此时模拟上下文被更改并且工作线程运行作为应用程序池的标识,它无权访问该文件夹,因此exception。 为了确认这一点,我查看了Parallel.ForEach主体内部和内部的进程标识: string before = WindowsIdentity.GetCurrent().Name; Debug.WriteLine(“Before Loop: {0}”, before); Parallel.ForEach(myList, currentItem => { string inside = WindowsIdentity.GetCurrent().Name; Debug.WriteLine(“Inside Loop: {0} (Worker Thread {1})”, inside, Thread.CurrentThread.ManagedThreadId); }); 当我运行应用程序时,这是打印出来的: Before Loop: MyDomain\ImpersonatedUser Inside Loop: NT AUTHORITY\SYSTEM (Worker Thread 8) Inside Loop: MyDomain\ImpersonatedUser (Worker Thread 6) Inside Loop: MyDomain\ImpersonatedUser (Worker Thread 7) Inside Loop: […]

服务帐户中的Exchange模拟:无法找到自动发现服务

通过ews发送简单的电子邮件正在按预期工作 – 从我的帐户到我的帐户: ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010); ews.AutodiscoverUrl(“myname@mydomain.com”); EmailMessage email = new EmailMessage(ews); email.ToRecipients.Add(“myname@mydomain.com”); email.Subject = “HelloWorld”; email.Body = new MessageBody(“This is the first email I’ve sent by using the EWS Managed API”); email.Send(); 简单地尝试模拟,它也按预期工作 – 在最后一行,它返回我不允许冒充的错误: ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010); ews.AutodiscoverUrl(“myname@mydomain.com”); ews.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, “testuser@mydomain.com”); EmailMessage email = new EmailMessage(ews); email.ToRecipients.Add(“myname@mydomain.com”); […]

该帐户无权模拟所请求的用户

我尝试访问资源邮箱时收到此错误。 请任何人帮助我。 我是EWS的新手。 我可以通过OWA(Outlook Web应用程序)访问资源邮箱。 但我不是这个邮箱的所有者,因为它是共享邮箱。 我的代码: ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; ExchangeService newExchangeService = new ExchangeService (ExchangeVersion.Exchange2007_SP1); newExchangeService.Credentials = new NetworkCredential(username, password, domain); newExchangeService.AutodiscoverUrl(email-id, RedirectionUrlValidationCallback); newExchangeService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, email_which_i_want_to_access); Folder visitorsFolder = Folder.Bind(newExchangeService, WellKnownFolderName.Inbox); foreach (Folder childfolder in visitorsFolder.FindFolders(new FolderView(10))) { Console.WriteLine(childfolder.DisplayName); }

使用WindowsImpersonationContext模拟当前用户访问网络驱动器

我需要从Web App访问远程驱动器。 ASP.NET进程无法访问该驱动器,因此我想模拟当前用户的请求。 我看到了一些使用WindowsImpersonationContext的基本示例,并尝试了以下操作。 WindowsImpersonationContext impersonationContext = null; try { impersonationContext = ((WindowsIdentity)User.Identity).Impersonate(); file.SaveAs(filePath); } finally { if (impersonationContext != null) { impersonationContext.Undo(); } } 我仍然获得访问被拒绝的例外。 我已经阅读了一些关于LogonUser的东西,但据我所知,你需要一个用户名和密码才能从中获取凭据。 我不打算以不同的特定用户身份登录,只是当前用户(谁应该有权访问文件存储),所以我认为我实际上并不需要LogonUser API。 有谁知道我错过了什么? 上述代码应该有效吗? 我还要注意包括 不起作用,但包括 在web.config让我进来。我看到一些人问这是为什么,但我没有看到任何解释。 我想知道它是否与我的问题有关。

通过文件共享,用户身份validation通过网络复制文件

我正在构建.net C#控制台程序,以将文件部署到Windows文件共享服务器(正在共享的文件夹)。 路径是:: \\192.168.0.76\htdocs\public 在运行时我收到错误: [09:35:29]: [Step 1/3] Unhandled Exception: System.UnauthorizedAccessException: Access to the path ‘\\192.168.0.76\htdocs\public’ is denied. [09:35:29]: [Step 1/3] at DeployFileShare.Program.CopyDir(String source, String dest, String[] exclude, Boolean overwrite) [09:35:29]: [Step 1/3] at DeployFileShare.Program.Deploy(String num, String source) [09:35:29]: [Step 1/3] at DeployFileShare.Program.Main(String[] args) [09:35:29]: [Step 1/3] Process exited with code -532459699 我想我需要对自己进行身份validation。 我遇到过这个: AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); […]