【问题标题】:Accessing Sharepoint List in java using NTLM authentication使用 NTLM 身份验证在 ja​​va 中访问 Sharepoint 列表
【发布时间】:2011-11-18 16:36:39
【问题描述】:

我正在使用 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));
    }
}

【问题讨论】:

    标签: java jax-ws ntlm


    【解决方案1】:

    使用 jax-ws 和 ntlm 的时间越长,我仍然会发现更多问题,但我至少设法避免了 403 错误。创建端口后尝试添加这两行代码:

    ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
    ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 2014-12-10
      • 1970-01-01
      相关资源
      最近更新 更多