【问题标题】:How to enable Kerberos Authentication in Java Client Consuming .NET WCF service如何在使用 .NET WCF 服务的 Java 客户端中启用 Kerberos 身份验证
【发布时间】:2019-03-11 17:14:19
【问题描述】:

通过使用服务代理请求设置非个人和客户端凭据,我可以使用带有 Kerberos 身份验证的 WCF 服务。

这可以在 Java 中完成吗?

有没有可用的 Java 库?

【问题讨论】:

    标签: java web-services wcf authentication kerberos


    【解决方案1】:

    启用 Kerberos 身份验证是在服务器端配置的,而不是在客户端。

    WSHttpBinding binding = new WSHttpBinding();
            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
    

    我们在客户端设置 Kerberos 凭据,这通常由客户端代理类完成。

    ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
            client.ClientCredentials.Windows.ClientCredential.Domain = "mydomain";
            client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
            client.ClientCredentials.Windows.ClientCredential.Password = "123456";
    

    关于如何在 Java 中创建代理。这里有一些解决方案。 Eclipse项目模板中有一个Web Service Client项目模板,可以生成带有WCF暴露WSDL的客户端代理类,如在C#中添加服务引用。
    http://wiki.eclipse.org/Creating_a_Java_Web_Service_Client
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/accessing-services-using-a-wcf-client?view=netframework-4.7.2
    Java JDK中也有Wsimport.exe工具,如.Net中的SVCUTIL.EXE工具,可以通过命令shell生成代理。
    https://docs.oracle.com/javase/7/docs/technotes/tools/share/wsimport.html
    https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-3.5/aa347733(v=vs.90)
    还有Axis2等第三方库。
    http://axis.apache.org/axis2/java/core/download.cgi
    最后,您甚至可以通过 HttpClient 类构造和发送 get/post 请求来调用服务。
    如果有什么我可以帮助的,请随时与我联系。

    【讨论】:

    • 在Service端不做任何改动,如何从Java客户端设置模拟
    • 得到客户端代理类后,参考以下代码。 ServiceReference1.ServiceClient 客户端 = new ServiceReference1.ServiceClient(); client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ClientCredentials.Windows.ClientCredential.UserName = "测试"; client.ClientCredentials.Windows.ClientCredential.Password = "123456";docs.microsoft.com/en-us/dotnet/framework/wcf/…
    猜你喜欢
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 2022-10-05
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2011-09-26
    • 2010-11-15
    相关资源
    最近更新 更多