title: Accessing Sharepoint List in java using NTLM authentication
body: <p>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.</p>
  
  <pre><code>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);
      }
  }
  </code></pre>
  
  <p>*</p>
  
  <pre><code>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));
      }
  }
  </code></pre>