与排队的用户在不同的进程中运行后台作业

在我们的应用程序中,我们有要在后台运行的Web API排队作业。我们使用HangFire进行作业的后台处理。Web API使用Windows身份验证。Hangfire服务器配置为作为Windows服务运行。

我正在尝试以将队列排队的同一用户的身份执行后台作业。

我尝试传递WindowsIdentity.GetCurrent()(由hangfire序列化并传递),引发的异常是“用于模拟的无效令牌-不能重复”

[HttpGet, Route("enq")]
public IHttpActionResult EnQueue(string country)
{     
    var curUser = System.Security.Principal.WindowsIdentity.GetCurrent();           
    var id = Hangfire.BackgroundJob.Enqueue(() => Services.Common.TestClass.Test(curUser , country));
    return Ok(id);
}

遇到了一种调用WIN32 API方法登录用户的方法但是由于将密码作为输入,因此不确定如何使用它。

以排队的同一用户身份执行后台作业的任何方法?

可能的解决方案:

  1. 使用Win32 API调用。缺点是,此方法需要用户密码。在下面的SO问题中有更多详细信息。

Windows模拟和复制令牌

  1. 使用Kerberos扩展“用户登录服务”

https://blogs.msdn.microsoft.com/winsdk/2015/08/28/logon-as-a-user-without-a-password/

var upn = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName;
WindowsIdentity s4u = new WindowsIdentity(upn);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章