2

我已经浏览了 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

有没有人有这个问题的解决方案?

4

2 回答 2

3

Try this: http://robaustin.wikidot.com/axis It works for me. You need to call setupCertsAndCredential() before getService()

private void setupCredential() {
  final NTCredentials nt = new NTCredentials("user", "pass", "", "domain");
  final CredentialsProvider myCredentialsProvider = new CredentialsProvider() {
   public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException {
    return nt;
   }
  };
  DefaultHttpParams.getDefaultParams().setParameter("http.authentication.credential-provider", myCredentialsProvider);
 }

ServiceStub getService() {  

  try {   
    ServiceStub stub = new ServiceStub(   
        "http://myserver/some/path/to/webservices.asmx"); // this service is hosted on IIS   

    return stub;    
  } catch (AxisFault e) {    
      e.printStackTrace();    
  }    
      return null;    
}    
于 2010-08-31T18:39:23.033 回答
0

HttpClient 不支持 NTLM v2,因此我使用 JCIFS 库返回 NTLM v1、2、3 消息类型,如本网站所述

http://devsac.blogspot.com/2010/10/supoprt-for-ntlmv2-with-apache.html

我刚刚使用上述网站上的 JCIFS_NTLMScheme.java 文件来注册身份验证方案,它成功了!!!!

示例客户端:

List authSchema = new ArrayList();
AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, org.tempuri.JCIFS_NTLMScheme.class);
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername("");
auth.setPassword("");
auth.setDomain("");
auth.setHost("");
auth.setPort();
List authPrefs = new ArrayList(1);
authPrefs.add(AuthPolicy.NTLM);
auth.setAuthSchemes(authPrefs);
stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); 
于 2013-03-15T17:22:01.780 回答