WCF 授权策略:模拟问题

发布于 2024-09-30 13:54:54 字数 915 浏览 3 评论 0原文

我有以下情况(概要):

授权Web服务
该服务被调用并验证(通过执行给定的业务逻辑)用户是否有效。

定制业务网络服务
这是为业务应用程序创建的一些 Web 服务,它在内部调用“授权 Web 服务”以验证调用业务 Web 服务的帐户。

我通过在“自定义业务 Web 服务”中使用 WCF 服务授权来实现此逻辑。基本上我配置了

<serviceAuthorization principalPermissionMode="Custom">
    <authorizationPolicies>
        <add policyType="MyCompany.Authorization.WCF.AuthorizationPolicy, MyCompany.AuthorizationDll"/>
    </authorizationPolicies>
</serviceAuthorization>

AuthorizationPolicy 在内部调用“Authorization Webservice”。

问题
问题是我需要模拟“自定义业务 Web 服务”的调用者。客户端标识是正确的,但 WindowsIdentity 是应用程序池用户的标识。
请注意,如果我在 AuthorizationPolicy 的 Evaluate(... ) 方法。

(显然,我使用 Windows 身份验证凭据使用传输级安全性)

任何人都可以提示我如何在输入 IAuthorizationPolicy.Evaluate(...) 方法之前模拟调用者?

I have the following situation (outline):

Authorization Webservice
This service gets called and verifies (by executing the given business logic) whether a user is valid or not.

Custom Business Webservice
This is some webservice created for a business app, that internally calls the "Authorization Webservice" in order to verify the account which called the business webservice.

I realized this logic by making use of WCF service authorization in my "Custom Business Webservice". Basically I configured

<serviceAuthorization principalPermissionMode="Custom">
    <authorizationPolicies>
        <add policyType="MyCompany.Authorization.WCF.AuthorizationPolicy, MyCompany.AuthorizationDll"/>
    </authorizationPolicies>
</serviceAuthorization>

The AuthorizationPolicy internally invokes the "Authorization Webservice".

The Problem
The problem is that I need to impersonate the caller of my "Custom Business Webservice". The client identity is the correct one, however the WindowsIdentity is that of the application pool user.
Note, impersonation works within the service itself if I use [OperationBehavior(Impersonation = ImpersonationOption.Required)] but it does not within the AuthorizationPolicy's Evaluate(...) method.

(I use Transport level security using windows authentication credentials, obviously)

Anyone has any hints on how I can impersonate the caller prior to entering the IAuthorizationPolicy.Evaluate(...) method??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2024-10-07 13:54:54

回答我自己的问题总是感觉有点奇怪,但为了与其他人分享我得到的东西,我将在这里发布“解决方案”。

我会尽量简明扼要:

  1. 在 IAuthorizationPolicy.Evaluate(...) 中进行模拟是不可能的。 (S4U2Self 可能有效,没有测试,因为我没有该选项)

正如我已经提到的,通过放置 [OperationBehavior(Impersonation = ImpersonationOption.Required)].因此,调用我的自定义 Web 服务来检索主体作为我的服务操作中的第一个语句始终有效。然而我不喜欢这种方法。
作为替代方案,我尝试在 WCF 服务操作的调用链中找到模拟最终起作用的最新可能点。这是我找到 OperationInvoker 的地方。

下图说明了在调用到达实际操作之前完成的调度顺序(取自 此处):
alt text

参数检查为时过早,模拟尚未起作用,但幸运的是它在操作调用器中起作用。因此,通过编写自定义操作调用程序并将所有内容包装到自定义操作行为属性中,我能够优雅地解决问题。

有关我写的博客文章的更多信息< /a>.

It always again feels a bit strange, answering to my own questions, but for the sake of sharing what I got with others I'm going to post the "solution" here.

I'll try to make it short:

  1. Impersonating in the IAuthorizationPolicy.Evaluate(...) is not possible. (S4U2Self may work, didn't test that since I didn't have that option)

As I already mentioned, impersonating the caller within the webservice operation worked by placing the [OperationBehavior(Impersonation = ImpersonationOption.Required)]. So calling my custom webservice for retrieving the principal as the first statement in my service operation would always work. I didn't like that approach however.
As an alternative I tried to find the latest possible point in the call chain of a WCF service operation where the impersonation finally worked. This is where I found the OperationInvoker.

The following diagram illustrates the sequence of dispatchings that are done before the call arrives at the actual operation (taken from here):
alt text

Parameter Inspection was too early, impersonation didn't yet work, but it luckily worked in the Operation Invoker. So by writing a custom operation invoker and wrapping everything into a custom operation behavior attribute I was able to elegantly solve the problem.

More info on an according blog post I wrote.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文