【问题标题】:Verify that the currently authenticated windows user has delegation rights验证当前已通过身份验证的 windows 用户是否具有委托权限
【发布时间】:2013-03-01 01:51:23
【问题描述】:

鉴于我有一个使用 Windows 身份验证的 WCF 服务,并且我想模拟它们并调用另一个 WCF 服务,如下所示:

using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
    // call another WCF service
}

我已经设置了所有的配置设置,它工作正常,只要在客户端,它们包括以下行:

client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;

但是,在尝试调用用户令牌是否具有委托权限之前,我该如何验证?即我无法控制的客户端设置了 AllowedPersonationLevel?

如果他们没有设置它,就会抛出各种奇怪的异常(比如无法加载程序集 X 等)。

理想情况下,我希望能够做到以下几点:

using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
    if (UserDoesntHaveDelegationRights())
        throw new SecurityException("No delegation rights");

    // call another WCF service
}

请注意,WindowsIdentity.GetCurrent().ImpersonationLevel 始终等于 TokenImpersonationLevel.Impersonation,因此很遗憾,这不是一个选项。

【问题讨论】:

    标签: c# wcf windows-authentication impersonation


    【解决方案1】:

    这里的定义可能有些混乱。就impersonation levels而言,一个windows身份可以是:

    • 模拟 - 服务可以在本地模拟用户
    • 委托 - 服务可以远程模拟用户

    委派的能力如此强大,以至于它在 Active Directory 中受到高度限制:

    1. 客户端必须允许委派
    2. 执行委派的服务帐户必须在 Active Directory 中标记为“受委派”。

    这是enable an account for delegation的方法。它需要 Active Directory 域管理员进行更改。我曾经工作过的每个公司环境都有一个不允许委派的政策。

    回到你的问题:

    所以虽然TokenImpersonationLevel.Delegation 存在,但它被认为是一种安全风险,并且很少(如果有的话)使用。 TokenImpersonationLevel.Impersonation 是您可能获得的最高级别。

    TokenImpersonationLevel.Impersonation 很有用。您仍然可以以模拟用户身份连接到数据库或进行远程服务调用。但是远程服务(不在同一个盒子上)不能再次模拟用户。基本的经验法则是“模拟使两台机器跳”。如果用户的凭据必须“跳”得更远,它将失败。

    如果您需要在多台服务器之间传递用户凭据,最好的选择是联合安全模型,例如 Windows Identity Foundation (WIF)。见Identity Management in Active Directory

    【讨论】:

      【解决方案2】:

      怎么样

      if (WindowsIdentity.GetCurrent().ImpersonationLevel != TokenImpersonationLevel.Delegation) ...
      

      【讨论】:

      • 是的,我就是这么想的——但是 WindowsIdentity.GetCurrent().ImpersonationLevel 总是等于 Impersonation
      猜你喜欢
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      相关资源
      最近更新 更多