Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 验证当前经过身份验证的windows用户是否具有委派权限_C#_Wcf_Windows Authentication_Impersonation - Fatal编程技术网

C# 验证当前经过身份验证的windows用户是否具有委派权限

C# 验证当前经过身份验证的windows用户是否具有委派权限,c#,wcf,windows-authentication,impersonation,C#,Wcf,Windows Authentication,Impersonation,假设我有一个使用windows身份验证的WCF服务,我想模拟它们并调用另一个WCF服务,如下所示: using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate()) { // call another WCF service } 我已经设置了所有配置设置,只要在客户端,它们包括以下行,就可以正常工作: client.ClientCredentials.Windows.AllowedImpersonationLeve

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

using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
    // call another WCF service
}
我已经设置了所有配置设置,只要在客户端,它们包括以下行,就可以正常工作:

client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;
但是,在尝试进行调用之前,如何验证用户令牌是否具有委派权限?i、 e.我不控制的客户机已设置AllowedPersonationLevel

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

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

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

    // call another WCF service
}
请注意,
WindowsIdentity.GetCurrent().ImpersonationLevel
始终等于
TokenImpersonationLevel.Impersonation
,因此不幸的是,这不是一个选项。

怎么办

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

这里的定义可能有些混乱。就windows标识而言,可以是:

  • 模拟-服务可以在本地模拟用户
  • 委派-服务可以远程模拟用户
委派功能非常强大,在Active Directory中受到高度限制:

  • 客户机必须允许委托
  • 执行委派的服务帐户必须在Active Directory中标记为“受信任的委派”
  • 这里有一些方法。需要Active Directory域管理员才能进行更改。我工作过的每个公司环境都有一个不允许授权的政策

    回到你的问题:

    因此,虽然存在
    TokenImpersonationLevel.Delegation
    ,但它被认为是一种安全风险,很少(如果有)使用<代码>令牌模拟级别。模拟是您可能获得的最高级别。

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


    如果您需要在许多服务器之间传递用户的凭据,最好的选择是联合身份安全模型,如Windows身份基础(WIF)。请参阅。

    是的,这是我的想法-但是WindowsIdentity.GetCurrent().ImpersonationLevel始终等于Impersonation