使用 NTLM 身份验证在 java 中访问 Sharepoint 列表
我正在使用 JAX-WS 从 java 客户端访问共享点列表。我无法破解 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));
}
}
I am using JAX-WS for accessing sharepoint list from java client. I am not able to crack the ntlm authentication part. It's giving me 403 forbidden error.But I am able to authenticate when there is basic authentication enabled. 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));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 jax-ws 和 ntlm 的时间越长,我仍然发现更多的问题,但我至少设法避免了 403 错误。创建端口后尝试添加这两行代码:
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. Try adding these two lines of code after you create your port: