0

我有一个用 Java 编写的 Web 应用程序,它使用 Exchange Web 服务对交换服务器进行 JAX-WS Web 服务调用。

当我使用 Java 1.6.0_34 编译和运行应用程序时,它工作正常。

如果我使用 Java 1.7.0_07 编译并运行它,我会收到以下错误:

com.sun.xml.ws.client.ClientTransportException: request requires HTTP authentication: Unauthorized
    at com.sun.xml.ws.transport.http.client.HttpClientTransport.checkResponseCode(HttpClientTransport.java:212)
    at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:149)
    at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:86)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
    at com.sun.xml.ws.client.Stub.process(Stub.java:248)
    at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:135)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:109)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
    at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
    at $Proxy62.getUserAvailability(Unknown Source)
    ...

如果我用 1.6.0_34 编译它并用 1.7.0_07 运行它,也会发生这种情况。

我查找了 Java 6 和 7 之间对 JAX-WS 的更改,但我只发现了一些关于可能的编译错误的注释。

我不确定接下来要看什么,因为显然身份验证代码没有更改,那为什么会失败?

这是我认为应该设置身份验证的方法:

/**
 *  Set up Authentication
 *
 */
protected void setupAuthenticator(){
    if(authenticator == null){
        authenticator = new Authenticator(){
            protected PasswordAuthentication getPasswordAuthentication(){
                String superusername = ExchangeServerPortFactory.this.adDomain
                                + "\\" 
                                + ExchangeServerPortFactory.this.username;
                String superPassword = ExchangeServerPortFactory.this.password;
                return new PasswordAuthentication(superusername
                                         ,superPassword.toCharArray());
            }
        };
        Authenticator.setDefault(authenticator);
    }
}

我尝试更改"\\"为,"\\\\"因为我在某个论坛上发现了一条消息,该消息解决了类似的问题,但这对我没有任何好处。

4

2 回答 2

0

好的,这就是我到目前为止所得到的,您正在调用交换服务,但是您现在使用的是基本身份验证方法,您需要的是 NTML 身份验证,我不知道为什么这适用于 j6 而不是 j7 ,但我认为客户端正在根据服务的 wsdl 解析您的请求,该服务可能定义它是一个交换服务,并且可能 j7 具有用于 NTML 身份验证的特定身份验证器,但同样,这是一个很长的镜头,我假设许多事。

( Marcel Levy的所有学分)

首先,创建一个身份验证器:

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class NtlmAuthenticator extends Authenticator {

  private final String username;
  private final char[] password;

  public NtlmAuthenticator(final String username, final String password) {
    super();
    this.username = new String(username);
    this.password = password.toCharArray(); 
  }

  @Override
  public PasswordAuthentication getPasswordAuthentication() {
    return (new PasswordAuthentication (username, password));
  }
}

在您的应用程序中,将身份验证器设置为默认值:

String username = "DOMAIN\\USERNAME";
String password = "PASSWORD"

NtlmAuthenticator authenticator = new NtlmAuthenticator(username, password);
Authenticator.setDefault(authenticator);

你可能试过这个,如果是这样,请忽略这个答案。

于 2012-12-10T15:20:47.447 回答
0

它似乎在 1.7.0u10 或更高版本中工作。

我只能猜测这是因为该版本中已修复的错误 8003948

于 2013-07-24T14:35:23.140 回答