我已经浏览了 StackOverflow 上关于 NTLM 和 Java 的所有讨论,但我似乎找不到答案。我会尝试更具体。
这是一些返回客户端存根的代码(我希望)为 NTLM 身份验证配置:
ServiceStub getService() {
try {
ServiceStub stub = new ServiceStub(
"http://myserver/some/path/to/webservices.asmx"); // this service is hosted on IIS
List<String> ntlmPreferences = new ArrayList<String>(1);
ntlmPreferences.add(HttpTransportProperties.Authenticator.NTLM);
HttpTransportProperties.Authenticator ntlmAuthenticator = new HttpTransportProperties.Authenticator();
ntlmAuthenticator.setAuthSchemes(ntlmPreferences);
ntlmAuthenticator.setUsername("me");
ntlmAuthenticator.setHost("localhost");
ntlmAuthenticator.setDomain("mydomain");
Options options = stub._getServiceClient().getOptions();
options.setProperty(HTTPConstants.AUTHENTICATE, ntlmAuthenticator);
options.setProperty(HTTPConstants.CHUNKED, "false");
return stub;
} catch (AxisFault e) {
e.printStackTrace();
}
return null;
}
这将返回一个有效的 SerivceStub 对象。当我尝试在存根上调用调用时,我在日志中看到以下内容:
Jun 9, 2010 12:12:22 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: NTLM authentication scheme selected
Jun 9, 2010 12:12:22 PM org.apache.commons.httpclient.HttpMethodDirector authenticate
SEVERE: Credentials cannot be used for NTLM authentication: org.apache.commons.httpclient.UsernamePasswordCredentials
有没有人有这个问题的解决方案?