Apache Axis2 1.5.1 和 NTLM 身份验证

发布于 2024-09-04 13:36:18 字数 1476 浏览 6 评论 0原文

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

有人能解决此问题吗?

I've browsed all of the discussions here on StackOverflow regarding NTLM and Java, and I can't seem to find the answer. I'll try and be much more specific.

Here's some code that returns a client stub that (I hope) is configured for NTLM authentication:

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;
}

This returns a valid SerivceStub object. When I try to invoke a call on the stub, I see the following in my log:

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

Does anyone have a solution to this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过潦 2024-09-11 13:36:18

试试这个:http://robaustin.wikidot.com/axis
这对我有用。您需要在 getService() 之前调用 setupCertsAndCredential()

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;    
}    

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;    
}    
肩上的翅膀 2024-09-11 13:36:18

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); 

HttpClient doesnt support NTLM v2 hence I use JCIFS library to return NTLM v1,2,3 message type as described in this website

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

I just used the JCIFS_NTLMScheme.java file from the above website to register the auth scheme and it worked !!!!

Sample client:

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); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文