我正在使用JAX-WS从java客户端访问sharepoint列表。我无法破解ntlm身份验证部分。它给了我403禁止的错误。但是我能够在启用基本身份验证时进行身份验证。我的代码如下。之前有人曾经工作过吗?提前谢谢。
public static void main(String[] args) {
try {
String userName = "INDIA\\arindam";
String password = "September@123";
String end = "http://www.sharepoint.com/_vti_bin/lists.asmx";
com.microsoft.schemas.sharepoint.soap.ListsSoap port = null;
com.microsoft.schemas.sharepoint.soap.Lists service = new Lists();
port = service.getListsSoap();
NtlmAuthenticator authenticator = new NtlmAuthenticator(userName, password);
Authenticator.setDefault(authenticator);
String listName = "Shared Documents";
String rowLimit = "150";
String viewName = "";
com.microsoft.schemas.sharepoint.soap.GetListItems.ViewFields viewFields = null;
com.microsoft.schemas.sharepoint.soap.GetListItems.Query query = null;
com.microsoft.schemas.sharepoint.soap.GetListItems.QueryOptions queryOptions = null;
String webID = "";
com.microsoft.schemas.sharepoint.soap.GetListItemsResponse.GetListItemsResult result = port.getListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, webID);
System.out.println(result.toString());
} catch (Exception ex) {
System.err.println(ex);
}
}
*
public class NtlmAuthenticator extends Authenticator {
private final String username;
private final char[] password;
com.microsoft.schemas.sharepoint.soap.ListsSoap port = null;
com.microsoft.schemas.sharepoint.soap.Lists service = new Lists();
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));
}
}
答案 0 :(得分:0)
我使用jax-ws和ntlm工作的时间越长,我仍然会发现更多问题,但我至少设法避免403错误。在创建端口后尝试添加这两行代码:
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);