【发布时间】:2014-08-02 12:46:41
【问题描述】:
用户触发了一个事件,因此线程在该用户的上下文中。 我遍历所有连接的用户并希望向他们发送此事件,但我想使用经典授权来确定他们是否应该接收该事件。问题是线程主体等在触发事件的用户的上下文中。
我正在研究模拟线程,然后进行授权。我在上面找到了这篇文章
http://msdn.microsoft.com/en-us/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/
【问题讨论】:
-
是否出现异常?该代码没有捕获任何内容,所以我很好奇!你在 wcf 上下文中吗(因为你提到的文档是这样认为的) - 如果是这样,你会添加一个适当的标签吗?
-
我在 HTTP 上下文 (WebApi) 中,没有错误,但 Thread.CurrentPrincipal.Identity.Name 返回原始调用者而不是被篡改的调用者
-
您是否在 AD 中为应用程序设置了委派?您是否在主机上设置了 SPN?您是否通过 FQDN 连接到服务器?给冥界三头魔犬献了个处女(实习开发者还可以)?
-
其实……好好想想吧。你知道委托和模仿的区别吗?
-
@Anders 你的
WindowsImpersonationContext为空吗?在您尝试模仿之前和之后,System.Security.Principal.WindowsIdentity.GetCurrent().Name说了什么?
标签: c# impersonation windows-identity identity-delegation