JAX-WS Sharepoint 401未经授权的NTLM [英] JAX-WS Sharepoint 401 Unauthorized NTLM

查看:308
本文介绍了JAX-WS Sharepoint 401未经授权的NTLM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过JAX-WS访问Sharepoint列表,如上所述这里

I try to access a Sharepoint list via JAX-WS as described here

然而,当运行下面的代码时,我得到:

However, when running the code below I get:

java.lang.Exception: Exception. See stacktrace.com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized

Sharepoint需要NTLM身份验证。可能是什么问题?非常感谢!

Sharepoint requires NTLM authentication. What may be the problem? Thanks a lot!

public static ListsSoap sharePointListsAuth(String userName, String password) throws Exception {
    ListsSoap port = null;
    if (userName != null && password != null) {
        try {
            Lists service = new Lists();
            port = service.getListsSoap();
            System.out.println("Web Service Auth Username: " + userName);
            ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
            ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
        } catch (Exception e) {
            throw new Exception("Error: " + e.toString());
        }
    } else {
        throw new Exception("Couldn't authenticate: Invalid connection details given.");
    }
    return port;
}


推荐答案

我遇到了同样的问题当使用JAX-WS连接到Exchange Web服务时,这对我有用:

I was facing the same problem when connecting with JAX-WS to Exchange web services, and here's what worked for me:

首先,创建一个验证器:

First, create an authenticator:

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

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

In your application, set up the authenticator as the default:

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

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

请注意,我正在使用方法#2来指定域,如Java文档。

Note that I'm using method #2 for specifying the domain as described in the Java documentation.

这篇关于JAX-WS Sharepoint 401未经授权的NTLM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆