c# - 如何从收到的 msmq 消息中获取发件人的 WindowsIdentity?

标签 c# security msmq windows-identity

如何从收到的msmq消息中获取发件人的WindowsIdentity?

我使用 msmq 作为传输和安全应用程序 block ,并使用授权规则提供程序进行操作授权。我需要 WindowsPrincipal 而不是 GenericPrincipal,因为规则授予事件目录用户组而不是特定用户。 Message.SenderId 可以转换为 SecurityIdentifier,但我没有找到如何从中获取 WindowsIdentity。

void AuthorizeOperation(Message message)
{
   // get sender windows principal
   WindowsPrincipal principal = ... ???

   // extract operation name from message body
   string operation = ... 

   AuthorizationFactory.GetAuthorizationProvider().Authorize(principal, operation);
}

最佳答案

我找到了解决方法,但不确定它是否是正确的解决方案。 我创建了一个 GenericPrincipal 而不是 WindowsPrincipal,并注入(inject)了从事件目录收到的用户授权组。

var sid = new SecurityIdentifier(message.SenderId, 0);
var user = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain), IdentityType.Sid, sid);
var principal = new GenericPrincipal(
                   new GenericIdentity(user.SamAccountName),
                   user.GetAuthorizationGroups().Select(g => g.SamAccountName).ToArray());
bool authorized = AuthorizationFactory.GetAuthorizationProvider().Authorize(principal, operation);

关于c# - 如何从收到的 msmq 消息中获取发件人的 WindowsIdentity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7959425/

相关文章:

Java AES/CBC/PKCS5Padding 流加密性能与不加密相比

asp.net - 确保登录用户只能看到他们的数据的最佳方法

.net - WCF MSMQ 的观察者模式

c# - 具有负载平衡的高负载服务器,使用 WCF 和 MSMQ

.net - 如何在 nservicebus MSMQ 中达到最大重试次数时发送电子邮件

c# - 如何从 gps 点创建谷歌地图折线?

c# - 从数据库中提取字符串。说不能隐式转换为 'string'

c# - 如何在 OpenCV 和 C# 中进行霍夫变换?

c# - 使用 XNA 执行鼠标、键盘点击

javascript - AES-128-GCM 是否在 Node V6 上验证 IV?