Java 6的NTLM代理身份验证和HTTPS - 有没有人得到它的工作?(Java 6 NTLM

2019-07-03 15:41发布

我有一个需要访问网络服务的Java应用程序(而不是小程序)。 对于Web服务代理已经与JAX-WS生成,似乎很好地工作。 在一个场景中,它需要通过web代理服务器(其实鱿鱼3.0),它被设置为需要NTLM身份验证交谈。

运行在Sun的JRE 1.6.0_14,一切工作正常访问HTTP的URL,而无需任何修改:内置的NTLM认证踢,这一切工作的无缝。 但是,如果Web服务URL是HTTPS URL,Web服务调用Sun的代码深处失败:

com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.lang.NullPointerException
        at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:121)
        at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:142)
        at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
        at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
        at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
        at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
        at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
        at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
        at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
        at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
        ... our web service call ...
Caused by: java.lang.NullPointerException
        at sun.net.www.protocol.http.NTLMAuthentication.setHeaders(NTLMAuthentication.java:175)
        at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1487)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:164)
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:896)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
        at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:109)
        ... 16 more

展望Sun的bug数据库变成了在这样的类有一些例外,但他们似乎已经固定。 有没有人碰到这样的事? 有没有人有这个工作?

Answer 1:

一些调试后,这似乎是在JRE类库中的缺陷,特别是在sun.net.www.protocol.http.HttpURLConnection

留学HTTP和HTTPS端点的情况下,HTTP请求和响应表明,在成功的HTTP情况下,要求有一个标题Proxy-Connection=keep-alive ,这是缺少失败的HTTPS情况。 阅读更普遍,似乎有一个人是否应该使用“ - 代理连接”或只是“连接”有些混乱,太...

无论如何,值得注意的是,在HTTP的情况下,代码经过HttpURLConnection.writeRequests()它包含下面的代码段

    /*
     * For HTTP/1.1 the default behavior is to keep connections alive.
     * However, we may be talking to a 1.0 server so we should set
     * keep-alive just in case, except if we have encountered an error
     * or if keep alive is disabled via a system property
     */

    // Try keep-alive only on first attempt
    if (!failedOnce && http.getHttpKeepAliveSet()) {
    if (http.usingProxy) {
        requests.setIfNotSet("Proxy-Connection", "keep-alive");
    } else {
        requests.setIfNotSet("Connection", "keep-alive");
    }

创建通过代理进行HTTPS,从而导致squid NTLM身份验证对话期间生气的隧道时,有没有这样的代码。

要解决这个问题,在HttpURLConnection.sendCONNECTRequest()我加

if (http.getHttpKeepAliveSet()) {
    if (http.usingProxy) {
        requests.setIfNotSet("Proxy-Connection", "keep-alive");
    }
}

之前

setPreemptiveProxyAuthentication(requests);
http.writeRequests(requests, null);

我注入我修改HttpURLConnection.class使用“-Xbootclasspath / P”标志进入JRE,而现在它的作品! 不完全是优雅的,但我们是。



Answer 2:

你结婚了到JAX-WS? 我使用Apache Axis2的,它使用Commons的HttpClient和具有NTLM身份验证内置。

例:

//Configure SOAP HTTP client to authenticate to server using NTLM
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

//TODO make report server credentials configurable
auth.setUsername("jdoe");
auth.setPassword("strongpass");
auth.setDomain("WINDOWSDOMAIN");
auth.setHost("host.mydomain.com");
auth.setPort(443);

Options o = new Options();
o.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,auth);
myWebServiceStub._getServiceClient().setOptions(o);


文章来源: Java 6 NTLM proxy authentication and HTTPS - has anyone got it to work?