【问题标题】:Find a WCF service caller's Active Directory domain username查找 WCF 服务调用者的 Active Directory 域用户名
【发布时间】:2011-06-19 04:33:57
【问题描述】:

考虑使用WsHttpBinding 的 WCF 服务,仅允许域用户调用该服务。

如何找到调用者的 Active Directory 用户名?

【问题讨论】:

    标签: c# wcf wcf-security


    【解决方案1】:

    获取System.ServiceModel.ServiceSecurityContext.Current.WindowsIdentity.Name 属性的值。

    只要安全模式与绑定的None 不同,您使用哪种绑定都没有关系。

    如果安全模式是None,那么System.ServiceModel.ServiceSecurityContext.Current 将是null

    【讨论】:

    • “你使用哪种绑定都没有关系”——我认为这是不正确的。对我来说,Name 属性仅填充了Windows 身份验证模式。
    【解决方案2】:

    您可以通过调用获取用户的身份:

    ServiceSecurityContext.Current.WindowsIdentity.Name
    

    OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
    

    【讨论】:

      【解决方案3】:

      您必须将某种用户信息添加到您用于联系服务的消息结构中。

      例如

      public class UserInformation
      {
        public string User { get; set; }
        public string Password { get; set; }
      }
      
      [DataContract]
      public class Request
      {
        [DataMember]
        public UserInformation User { get; set; }
        [DataMember]
        public MyRequest RequestBody { get; set; }
      }
      

      通过这种方式,您可以在客户端查询活动目录、填充 UserInformation 对象并将用户详细信息作为消息结构的一部分发送。

      【讨论】:

        猜你喜欢
        • 2023-03-24
        • 1970-01-01
        • 2011-05-14
        • 1970-01-01
        • 1970-01-01
        • 2020-07-02
        • 1970-01-01
        • 1970-01-01
        • 2010-09-28
        相关资源
        最近更新 更多