【问题标题】:Why do I get a WindowsIdentity when using message security?为什么我在使用消息安全性时会获得 WindowsIdentity?
【发布时间】:2013-01-30 14:06:10
【问题描述】:

从无安全性切换到证书时,我在IAuthorizationPolicy.Evaluate (evaluationContext.Properties.TryGetValue("Identities", out obj) 中获得了一个 WindowsIdentity?这是设计的吗:

从这里:

<binding name="NetTcpBinding_IMyAppClientServiceRegular" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="01:00:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <reliableSession ordered="true" inactivityTimeout="infinite" enabled="false"/>
          <security mode="None">
            <transport clientCredentialType="None"/>
          </security>
        </binding>

对此:

<binding name="netTcpCertificate" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="01:00:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="1000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="200" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <reliableSession ordered="true" inactivityTimeout="infinite" enabled="false"/>
          <security>
            <message clientCredentialType="Certificate"/>
          </security>
        </binding>

有什么方法可以避免在 IAuthorizationPolicy.Evaluate 中获取 WindowsIdentity?我只希望在使用此绑定时设置 WindowsIdentity:

<binding name="NetTcpBinding_IMyAppClientServiceWindows" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="01:00:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <reliableSession ordered="true" inactivityTimeout="infinite" enabled="false"/>
          <security mode="Message">
            <message clientCredentialType="Windows"/>
          </security>

【问题讨论】:

    标签: c# .net wcf security windows-identity


    【解决方案1】:

    我注意到您没有在 netTcpCertificate 配置中设置 &lt;security&gt; 中的模式,而不是您可能想要的:&lt;security mode="Message"&gt;。通过不设置mode 属性,WCF 将使用Transportdefault value 而不是Message,这可能是您想要的证书凭据。当模式设置为传输时,WCF 可能正在传递 Windows 标识,但我没有尝试验证它。

    更新: 根据下面的 cmets,您应该确保 client 配置文件 endpoint>indentity>dns> 值与 server 证书名称 CN= 值匹配。根据您输入的内容,此值需要为 MyAppServer。

    【讨论】:

    • 您好,当将其设置为 mode=Message 时,不会触发 IAuthorizationPolicy.Evaluate(=未登录)。然而,服务方法被执行,但返回时将抛出以下异常:“传出消息的身份检查失败。远程端点的预期 DNS 身份是 'localhost',但远程端点提供了 DNS 声明 'MyAppServer'”。我认为它正在使用消息,因为
    • 您看到的错误是由于证书未使用 localhost 作为域名(DNS 身份)。不过,将mode 属性留空可能是正确的。查看 this good walkthrough 以了解带有证书的消息安全性。首先尝试让该示例在 wsHttpBinding 中成功运行。接下来,将示例绑定示例更改为使用 netHttpBinding 并使其正常工作。最后,使用示例检查您的配置。
    • 什么属性应该为空?我已经按照这个例子做了我所需要的:codeproject.com/Articles/36683/… 它使用对等信任而不是链,它也是 TCP 而不是 wsHTTP。
    • 对不起,我遗漏了这个元素。我指的是配置中的Security 元素。我已经编辑了答案。
    猜你喜欢
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 2010-09-28
    • 2015-09-30
    • 2013-02-05
    相关资源
    最近更新 更多