如何从收到的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/