远程资源的程序化模拟委派(双跳) [英] Programmatic Impersonation Delegation For Remote Resources (Double-Hop)

查看:94
本文介绍了远程资源的程序化模拟委派(双跳)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让运行时模拟工作.

I am having a hard time to get Runtime Impersonation to work.

场景:

  • 在所有服务器中都禁用了匿名访问,并且启用了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委派

有效的方法(Kinda):

如果我使用Web.config

If I turn on impersonation in Web Api 1 using the Web.config

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

  • 所有电话都被冒充. Web Api 1-> Web Api 2和Web Api 1-> oData服务
  • 这不是我们想要的.我们希望只能通过应用程序池帐户访问oData服务.因此,我们不想模拟来自Web Api 1的所有呼出电话.

    程序模拟

    Programmatic Impersonation

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

    We tried to impersonate only calls going from Web Api 1 to Web Api 2 using the following code

    在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();
    };
    

    结果:

    Results:

    • 未模拟从Web Api 1到oData的呼叫(按预期)
    • 从Web Api 1到Web api 2的调用也不会被模拟.这是问题所在.

    问题:

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

    任何指针都会有所帮助.

    Any pointers would be helpful.

    推荐答案

    问题中提到的代码有效!!授权存在一些问题,需要解决.

    The code mentioned in the question works!! There was some problem with delegation, that needed to be fixed.

    谢谢

    这篇关于远程资源的程序化模拟委派(双跳)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆