[英]Accessing Sharepoint List in java using NTLM authentication
I am using JAX-WS for accessing sharepoint list from java client. 我正在使用JAX-WS从Java客户端访问共享点列表。 I am not able to crack the ntlm authentication part.
我无法破解ntlm身份验证部分。 It's giving me 403 forbidden error.But I am able to authenticate when there is basic authentication enabled.
这是403禁止的错误。但是启用基本身份验证后,我便可以进行身份验证。 My code is as below.
我的代码如下。 Has anyone worked before on that?
以前有人做过吗? Thanks in advance.
提前致谢。
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));
}
}
I'm still finding more problems the longer I work with jax-ws and ntlm, but I've at least managed to avoid 403 errors. 使用jax-ws和ntlm的时间越长,我仍然会发现更多问题,但是我至少设法避免了403错误。 Try adding these two lines of code after you create your port:
创建端口后,尝试添加以下两行代码:
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.