用户触发事件,因此该线程位于该用户的上下文中。我遍历所有已连接的用户,并希望向他们发送该事件,但是我想使用经典的授权来确定他们是否应该接收该事件。问题是线程主体等在触发事件的用户上下文中。
我正在研究模拟线程,然后进行授权。我在上面找到了这篇文章
http://msdn.microsoft.com/zh-CN/library/ff647248.aspx#ImpersonationDelegation5
using System.Security.Principal;
…
WindowsIdentity wi = new WindowsIdentity(userName@fullyqualifieddomainName);
WindowsImpersonationContext ctx = null;
try
{
ctx = wi.Impersonate();
// Thread is now impersonating you can call the backend operations here...
catch
{
// Prevent exceptions propagating.
}
finally
{
// Ensure impersonation is reverted
ctx.Undo();
}
在ctx = wi.Impersonate();
线程仍在调用用户的上下文中之后,我在做什么错?
更新我想以其他用户身份运行此代码
provider = AuthorizationFactory.GetAuthorizationProvider();
provider.Authorize(Thread.CurrentPrincipal, Rule)
我做了一个小博客,介绍了所需的步骤http://andersmalmgren.com/2014/06/12/client-server-event-aggregation-with-role-authorization/
provider.Authorize(principal, context)
已System.Security.Principal.IPrincipal
作为其第一个放慢参数(请参阅MSDN)。为什么不创建一个System.Security.Principal.WindowsPrincipal
-instance(它将一个System.Security.Principal.WindowsIdentity
已经存在的-instance用作ctor参数)并将其用作参数?
否则:您是否知道CurrentPrincipal
某个线程有一个setter?请参阅其他问题/答案
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句