简体   繁体   English

用于IIS集成Windows身份验证(NTLM)的JAX-WS客户端

[英]JAX-WS client for IIS Integrated Windows authentication (NTLM)

Recently, I am working on a project that requires to build a web service client in Java running on JAX-WS engine to talk to a .NET web service secured by Integrated Windows authentication (also known as NTLM protocol) 最近,我正在从事一个项目,该项目需要在JAX-WS引擎上运行的Java中构建Web服务客户端,以与通过集成Windows身份验证(也称为NTLM协议)保护的.NET Web服务进行通信。

I searched on the Internet. 我在互联网上搜索。 It seems a well-known issue, but no one has good solution yet. 这似乎是一个众所周知的问题,但是没有人有好的解决方案。

Anyone has done this before? 有人做过吗?

Any suggestion will be appreciated. 任何建议将不胜感激。

We are using the JAX-WS that is built in to java 6, and running the client on Windows XP and Windows 2003 Server. 我们正在使用Java 6中内置的JAX-WS,并在Windows XP和Windows 2003 Server上运行客户端。 The server is IIS 7 on Windows 2003 Server. 该服务器是Windows 2003 Server上的IIS 7。

I found to my surpise that integrated authentication works out of the box. 我惊讶地发现,集成身份验证可以直接使用。 No configuration supplied. 没有提供配置。 I turned on trace logging at the HTTP layer, and found that NTLM authentication was being used. 我在HTTP层上打开了跟踪日志记录,发现正在使用NTLM身份验证。 Not sure if it would work if only Negotiate authentication was being used and NTLM was turned off. 如果仅使用协商身份验证并且已关闭NTLM,则不确定是否可以使用。

So basically, the answer is: it just works. 因此,基本上,答案是:它确实有效。

To test: 去测试:

package url.auth;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;

public class DownloadUrl {
    public static void main(String[] args) {

        try {
            URL url = new URL("http://myserver/url/that/requires/authentication");
            URLConnection conn = url.openConnection();
            InputStream is = conn.getInputStream();
            Map<String, List<String>> headers = conn.getHeaderFields();
            for(String header : headers.keySet()) {
                System.out.println(header + ": " + headers.get(header));
            }
            System.out.println("");
            System.out.println(IOUtils.toString(is));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Java HTTP Client Options This section talks about the known implementations of NTLM support with a Java HTTP client so that you can select the implementation that best serves your needs. Java HTTP客户端选项本节讨论Java HTTP客户端对NTLM支持的已知实现,以便您可以选择最能满足您的需求的实现。

The available implementations are: 可用的实现有:

Sun JRE 1.4.2 or higher (free) - Full support of NTLM protocol (LM/NTLM/NTLM V2) on the Windows platform only. Sun JRE 1.4.2或更高版本(免费)-仅在Windows平台上完全支持NTLM协议(LM / NTLM / NTLM V2)。 Supports all NTLM configuration levels (I would imagine, I have not tried). 支持所有NTLM配置级别(我想,我还没有尝试过)。 Sun JRE 6 or 5 (only 1.5_08 or higher) (free) - Full support of NTLM protocol (LM/NTLM/NTLM V2) on all platforms. Sun JRE 6或5(仅1.5_08或更高版本)(免费)-在所有平台上完全支持NTLM协议(LM / NTLM / NTLM V2)。 Supports all NTLM configuration levels (I would imagine, I have not tried). 支持所有NTLM配置级别(我想,我还没有尝试过)。 However, on a Windows machine, it assumes you wish to authenticate using the currently logged on user. 但是,在Windows计算机上,它假定您希望使用当前登录的用户进行身份验证。 You can work around this only after the authentication fails. 只有在身份验证失败后,您才能解决此问题。 Jakarta (Apache) HTTP Client (free, Apache license) - Support for LM/NTLM (not NTLM V2) protocol on all Java platforms. Jakarta(Apache)HTTP客户端(免费,Apache许可证)-在所有Java平台上支持LM / NTLM(不是NTLM V2)协议。 Requires JRE 1.2 or higher. 需要JRE 1.2或更高版本。 Not plug-compatible with the Java UrlConnection classes. 与Java UrlConnection类不兼容。 No support for OEM encoding (as required by certain proxy servers). 不支持OEM编码(某些代理服务器要求)。 NTLM support was added quite a while ago and they don't appear to be interested in extending it. NTLM支持是在很早以前添加的,他们似乎对扩展它不感兴趣。 Supports NTLM configuration levels 0-3 only. 仅支持NTLM配置级别0-3。 Innovation HTTP Client w/Luigi Dragone NTLM support (free, LGPL) - Status of this is not clear; 带有Luuigi Dragone NTLM支持的创新HTTP客户端(免费,LGPL)-此状态尚不清楚; I had difficulty getting it to work reliably, and the software has not been released since 2002. It is not plug-compatible with the Java URLConnection classes. 我很难使它可靠地工作,并且该软件自2002年以来尚未发布。它与Java URLConnection类不兼容。 Probably supports only NTLM configuration levels 0-3 only. 可能仅支持NTLM配置级别0-3。 JCIFS (free, LGPL)- Plug-compatible support for LM/NTLM (not NTLM V2) on all Java platforms. JCIFS(免费,LGPL)-在所有Java平台上对LM / NTLM(不是NTLM V2)的插件兼容支持。 Not clear if OEM encoding is implemented. 不清楚是否实现了OEM编码。 Supports NTLM configurations levels 0-3 only. 仅支持NTLM配置级别0-3。 Oakland Software Java HTTP Client (not free) - Full plug-compatible support of LM/NTLM/NTLMv2 on all Java platforms JRE release 1.2 or higher. Oakland Software Java HTTP客户端(非免费)-在所有Java平台JRE 1.2或更高版本上,对LM / NTLM / NTLMv2完全兼容插件。 Supports both Unicode and OEM encoding. 支持Unicode和OEM编码。 Supports all NTLM configuration levels. 支持所有NTLM配置级别。 If your Java implementation is 1.4.2 or greater and you are running Java on Windows, use the built in JRE support and you are done. 如果您的Java实现是1.4.2或更高版本,并且您正在Windows上运行Java,则使用内置的JRE支持即可。 Use the java.net.Authenticator class optionally in conjunction with setting some networking properties 可以结合使用java.net.Authenticator类和设置一些网络属性

If you can change the Windows machine to an NTLM configuration level less that 4 (to not require NTLM V2), and make sure the Network security: Minimum session security for NTLM SSP based (including secure RPC) servers is not set to require NTLM V2, then use either the Jakarta HTTP Client (if you don't care about plug compatibility) or the JCIFS HTTP client if you do. 如果您可以将Windows计算机更改为小于4的NTLM配置级别(不需要NTLM V2),并确保未将网络安全性:基于NTLM SSP(包括安全RPC)服务器的最低会话安全性设置为要求NTLM V2 ,然后使用Jakarta HTTP客户端(如果您不关心插件兼容性)或JCIFS HTTP客户端(如果您这样做)。 Also, if you are accessing your HTTP server through a proxy that supports only OEM encoding for NTLM, then you cannot use the Jakarta HTTP client (is this also true of JCIFS?). 另外,如果要通过仅支持NTLM OEM编码的代理访问HTTP服务器,则不能使用Jakarta HTTP客户端(JCIFS也是如此吗?)。

Note however, there is a potential compatibility related downside to the JCIFS HTTP client 但是请注意,JCIFS HTTP客户端存在与兼容性相关的潜在缺点

from http://jcifs.samba.org/ , it show jcifs-1.3.1 released / NTLM HTTP Filter Fixed . 来自http://jcifs.samba.org/ ,显示了jcifs-1.3.1已发布/ NTLM HTTP过滤器已修复。 does that mean can use http filter with ntlmV2 without problem? 这是否意味着可以在ntlmV2中使用http过滤器而不会出现问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM