【问题标题】:How to get sender's WindowsIdentity from recieved msmq message?如何从收到的 msmq 消息中获取发件人的 WindowsIdentity?
【发布时间】:2011-12-19 01:17:55
【问题描述】:

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

我使用 msmq 作为传输和带有授权规则提供程序的安全应用程序块来进行操作授权。我需要 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);
}

【问题讨论】:

  • 请注意,SenderId 很容易在消息中被欺骗,因此依赖它是不安全的。

标签: c# security msmq windows-identity


【解决方案1】:

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

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);

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    相关资源
    最近更新 更多