远程资源的程序化模拟委派(双跳)

时间:2014-12-31 20:07:54

标签: web-services c#-4.0 kerberos impersonation kerberos-delegation

我很难让Runtime Impersonation工作。

情境:

  • 在所有服务器中禁用匿名访问,并启用Windows身份验证
  • 客户端致电Web Api 1
  • Web Api 1可以调用Web Api 2或oData服务
  • 需要使用客户端凭据模拟从Web Api 1到Web Api 2的呼叫
  • 不得模拟从Web Api 1到oData Service的呼叫
  • Web Api 1使用Web Request调用该服务
  • 我们已正确配置Kerberos委派

Client to Service Design

什么有用(有点):

如果我使用Web.config打开Web Api 1中的模拟

<authentication mode="Windows"/>
<identity impersonate="true"/>
  • 所有电话都被模仿。 Web Api 1 - &gt; Web Api 2和Web Api 1 - &gt; oData服务

这不是我们想要的。我们希望只能通过应用程序池帐户访问oData服务。因此,我们不想模拟来自Web Api 1的所有拨出电话。

程序化模拟

我们尝试使用以下代码模拟从Web Api 1到Web Api 2的调用

在Web.config中禁用模拟

<authentication mode="Windows"/>
<identity impersonate="false"/>

模拟从Web Api 1到Web Api 2的调用。

// Impersonate the currently authenticated User
using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate()) {
    var request = (HttpWebRequest)HttpWebRequest.Create(uri);
    ...
    ...
    request.Credentials = CredentialCache.DefaultCredentials;

    response = (HttpWebResponse)request.GetResponse();
};

结果:

  • 从Web Api 1到oData的呼叫未被模拟(正如预期的那样)
  • 从Web Api 1到Web api 2的呼叫也没有被模仿。这就是问题所在。

问题:

  • 这是否应该在Web服务中实现运行时模拟?
  • 我们做错了什么?

任何指针都会有所帮助。

1 个答案:

答案 0 :(得分:0)

问题中提到的代码有效!!授权存在一些问题,需要修复。

由于

相关问题