在服务器上问题时联系ADFS端点

时间:2012-02-28 20:01:43

标签: wcf iis wcf-security adfs

我有一项服务设置为从ADFS检索安全令牌并使用该令牌与其他服务进行通信。当我从本地开发机器上联系我的ADFS windowsmixed端点命中ADFS服务时,我能够成功检索到令牌。但是,当我在运行ADFS的同一台计算机上安装我的服务时,我收到以下错误:

 Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint.

我可以使用以下只获取令牌的代码重现错误。当我在我的开发机器上命中远程服务器时,此代码再次起作用,但是当它直接在服务器上时它会失败。我在两者上使用相同的用户凭据。我在IIS Web服务中使用应用程序池凭据和使用下面代码的简单测试客户端获得相同的错误。

    private static SecurityToken GetToken()
    {
        string stsEndpoint = "https://adfsserver.com/adfs/services/trust/13/windowsmixed";
         string appliesTo = "http://domain.com/application/myapplication";

        var factory = new WSTrustChannelFactory(
            new WindowsWSTrustBinding(SecurityMode.TransportWithMessageCredential),
            stsEndpoint);
        factory.TrustVersion = TrustVersion.WSTrust13;

        var rst = new RequestSecurityToken
        {
            RequestType = RequestTypes.Issue,
            AppliesTo = new EndpointAddress(appliesTo),
            KeyType = KeyTypes.Symmetric
        };

        var channel = factory.CreateChannel();
        return channel.Issue(rst);
    }

我打开了Windows事件日志中的ADFS 2.0调试跟踪。当直接在服务器上访问windowsmixed端点时,我没有收到任何让我相信它实际上没有到达端点的条目。

我确实在安全日志中收到了与我正在运行的服务相关的一些审核失败:     请求了对象的句柄。

Subject:
    Security ID:        DOMAIN\ODI$ODIController
    Account Name:       ODI$ODIController
    Account Domain:     DOMAIN
    Logon ID:       0x1a574b5

Object:
    Object Server:      SC Manager
    Object Type:        SERVICE OBJECT
    Object Name:        WinHttpAutoProxySvc
    Handle ID:      0x0

Process Information:
    Process ID:     0x1f8
    Process Name:       C:\Windows\System32\services.exe

Access Request Information:
    Transaction ID:     {00000000-0000-0000-0000-000000000000}
    Accesses:       Query status of service
                Start the service
                Query information from service

    Access Reasons:     -
    Access Mask:        0x94
    Privileges Used for Access Check:   -

我可以使用存储的凭据访问usernamemixed端点并接收正确的令牌,因此它似乎可以验证用户甚至能够与ADFS端点进行通信。

如果我在上面的代码中设置了特定凭据,则可以进行连接。这再次让我相信在同一台机器上没有为我的Windows用户传递正确的凭据。

 factory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential("UserID", "password1", "dev.domain");

感谢您提供任何帮助。

布赖恩

1 个答案:

答案 0 :(得分:1)

我有类似的问题。我能够使用此处的示例使其工作:http://blogs.southworks.net/mwoloski/2009/07/17/getting-a-token-from-adfs-ex-geneva-server-using-wcf/

您的代码和工作示例之间的区别在于您修改邮件安全性以使用绑定中的当前安全凭证而不是客户端上的安全凭证。如果您使用的是WIF 4.0,则需要修改代码以使用WSTrustChannelFactory而不是WSTrustClient。其他代码虽然没有太大变化。

我的工厂代码如下:

var binding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential); binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; binding.Security.Message.EstablishSecurityContext = false;

var factory = new WSTrustChannelFactory( binding, new EndpointAddress(new Uri(sts), EndpointIdentity.CreateUpnIdentity(adfsUpn)));